Skip to content

How to add Cockpit UI for Podman containers to NixOS

Introduction

Cockpit is a cutting-edge web-based graphical interface for server management. It allows you to administer servers effortlessly and includes a built-in terminal.

Personally, I utilize the NixOS package to monitor system logs, network settings, services, system resources, and CPU load and all without needing to touch the command line.

With the Cockpit UI for Podman containers, you can manage Podman containers directly in your browser. I thought it would be a useful addition to my NixOS server configuration. Although I won’t use it to create or update containers—I’ll handle that through the NixOS configuration—it’s convenient for quickly checking container statuses, viewing logs, and accessing the console.

Cockpit Podman UI

How To

Unfortunately, Cockpit Podman is not available as a package. To resolve this, I added a custom package declaratively.

  1. First create the packages/cockpit directory

    Run the following command:

    # Open your terminal application
    sudo mkdir -p /etc/nixos/packages/cockpit
  2. Create /etc/nixos/packages/cockpit/default.nix

    /etc/nixos/packages/cockpit/default.nix
    # To edit use your text editor application, for example Nano
    { 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.

  3. Create /etc/nixos/packages/cockpit/podman-containers.nix

    /etc/nixos/packages/cockpit/podman-containers.nix
    # To edit use your text editor application, for example Nano
    { 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 I modified it slightly to get it working again.

    Adjust the version if necessary.

  4. Add the cockpit-apps to configuration.nix

    /etc/nixos/configuration.nix
    # To edit use your text editor application, for example Nano
    { 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.virtual-machines
    ];
    # Add the rest of the configuration here
    }
  5. Switch NixOS configuration

    Now you can switch to the new NixOS configuration. Run the following command:

    # Open your terminal application
    sudo nix-collect-garbage # Optional: clean up
    sudo nixos-rebuild switch
  6. Check the results

    Now you can browse to Cockpit and the Podman container UI by opening a web browser and going to: http://localhost:9090. Replace localhost with the relevant IP address or FQDN if needed, and adjust the port if you changed it earlier.

Comments

    No comments found for this note.

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

    Copyright 2021- Fiction Becomes Fact