NixOS - Add Podman Containers UI to Cockpit


With Cockpit Podman Containers you can manage Podman containers in your browser. I thought it would be a nice addition to my NixOS server configuration. I won’t use it to create or update containers, I will do that via the NixOS configuration. But it is useful to quickly see the status of containers and to view the logs and use the console.

Make sure you already have Cockpit running because the Podman Containers UI is an addition to it.

Configuration

Cockpit podman is unfortunately not available as a package. So I added a custom package declaratively.

First create a new directory, for example:

sudo mkdir -p  /etc/nixos/packages/cockpit

Create default.nix:

cd /etc/nixos/packages/cockpit
sudo nano default.nix

And add the following:

{ pkgs, ... }:

{
  # virtual-machines = pkgs.callPackage ./virtual-machines.nix { };
  podman-containers = pkgs.callPackage ./podman-containers.nix { };
}

You can add virtual-machines.nix in the same way, but we will ignore that for now. Save the changes to default.nix.

Create podman-containers.nix:

sudo nano podman-containers.nix

And add the following:

{ lib, stdenv, fetchzip, gettext }:

stdenv.mkDerivation rec {
  pname = "cockpit-podman";
  version = "81";

  src = fetchzip {
    url = "https://github.com/cockpit-project/${pname}/releases/download/${version}/${pname}-${version}.tar.xz";
    sha256 = "sha256-7ibC1tUyVmabJ9yLFZQJGC/bBplqWjsBxORKyioQ8bE=";
  };

  nativeBuildInputs = [
    gettext
  ];

  makeFlags = [ "DESTDIR=$(out)" "PREFIX=" ];

  postPatch = ''
    substituteInPlace Makefile \
      --replace /usr/share $out/share
    touch pkg/lib/cockpit-po-plugin.js
    touch dist/manifest.json
  '';

  dontBuild = true;

  meta = with lib; {
    description = "Cockpit UI for podman containers";
    license = licenses.lgpl21;
    homepage = "https://github.com/cockpit-project/cockpit-podman";
    platforms = platforms.linux;
    maintainers = with maintainers; [ ];
  };
}

The above is inspired by this script but modified a bit to get it working again.

Adjust the version if necessary.

If it is not easy to determine the shaS256 of the tar.gz file, then switch to the new NixOS configuration with the wrong value, the new sha256 will then be mentioned

Save the changes to podman-containers.nix.

Now open configuration.nix:

sudo nano /etc/nixos/configuration.nix

Adjust the configuration like this:

{ config, pkgs, lib, ... }:

let
  cockpit-apps = pkgs.callPackage packages/cockpit/default.nix { inherit pkgs; };
in
{
  imports =
  [ # Include the results of the hardware scan.
    ./hardware-configuration.nix
  ];

  environment.systemPackages = with pkgs; [
     cockpit
     cockpit-apps.podman-containers
     # cockpit-apps.podman-machines
  ];

# Add the rest of the configuration here

}

For a newer version of Cockpit you can use the package from the unstable channel as described here.

Save the changes to configuration.nix.

Now you can switch to the new configuration:

sudo nix-collect-garbage # optional: clean up
sudo nixos-rebuild switch

You can view my complete configuration.nix here.


Read other notes

Comments

    No comments found for this note.

    Join the discussion for this note on this ticket. Comments appear on this page instantly.

    Tags


    Notes mentioning this note

    • NixOS - Cockpit Setup
      Cockpit is a modern web-based graphical interface for servers. You can use it to administer servers and it has a...

    Notes Graph