Containerization
Platforms: NixOS only.
Container modules under othrys.services.containerization.*. Located in modules/services/containerization/.
Available Modules
| Module | Option | Description |
|---|---|---|
| Podman | othrys.services.containerization.podman | Container runtime with Docker compatibility |
| Docker | othrys.services.containerization.docker | Docker runtime (conflicts with Podman dockerCompat) |
| k3s | othrys.services.containerization.k3s | Lightweight single-node/cluster Kubernetes |
Podman
Options
options.othrys.services.containerization.podman = {
enable = lib.mkEnableOption "Podman container runtime";
dockerCompat = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Create docker alias pointing to podman for drop-in replacement.";
};
enableDns = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Enable DNS for default network (required for podman-compose).";
};
distrobox = {
enable = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Enable Distrobox for running containers as if they were native apps.";
};
};
compose = {
enable = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Install podman-compose for docker-compose compatibility.";
};
};
autoPrune = {
enable = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Periodically prune unused Podman resources.";
};
dates = lib.mkOption {
type = lib.types.str;
default = "weekly";
description = "systemd calendar expression for the prune timer.";
};
flags = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = ["--all"];
description = "Flags passed to `podman system prune`. `--all` removes every image without a running container; hosts that pre-pull pinned images should override this.";
};
};
extraPackages = lib.mkOption {
type = lib.types.listOf lib.types.package;
default = [];
description = "Additional packages to install alongside Podman.";
example = lib.literalExpression "with pkgs; [ skopeo buildah ]";
};
};
Features
- Docker CLI compatibility via
dockerCompat - DNS enabled for container networking (required for compose)
- Auto-prune of unused images on
autoPrune.dates, weekly by default, for the root store and for the primary user’s rootless store - podman-compose for docker-compose compatibility
- Optional Distrobox for running containers as native apps
- Shell aliases:
docker-compose→podman-compose - Persistence for container storage and config
The primary user runs podman rootless and is not added to group podman.
That group owns the rootful podman.socket nixpkgs installs, so membership is
access to the root daemon’s API, which is root. A host that wants a user on
the rootful socket adds the group in users.users.<name>.extraGroups itself.
Docker
The Docker runtime (othrys.services.containerization.docker), rootless by
default. With rootless.enable the only daemon is the user’s, started in the
user’s session, and no rootful daemon or root socket runs; the user’s store is
pruned by a user timer on autoPrune.dates. With rootless.enable = false
the rootful daemon runs, the primary user joins group docker, and upstream’s
prune unit prunes the root store. That group owns the root daemon’s socket, so
membership is root.
The rootful daemon writes its own iptables rules ahead of the router’s chain,
so on a host with othrys.services.router a published container port is
reachable from the WAN whatever the router allows. The module refuses that
pairing unless daemon.settings.iptables = false is set, after which ports
are published through the router’s portForwards. Rootless Docker reaches the
network through its own namespace and touches no host rules.
GPU containers
GPU access for containers comes from the NVIDIA module, which serves Docker and
Podman alike. othrys.hardware.nvidia.containerToolkit.enable writes a CDI
specification for the card at boot, as Hardware
describes. Podman reads it with --device nvidia.com/gpu=all. Docker, rootful
or rootless, reads it with --gpus all or the same --device flag. The option
was othrys.services.containerization.docker.nvidia.enable before, and that
name still works with a warning.
k3s
Lightweight Kubernetes (othrys.services.containerization.k3s) for a single-node
control plane or a joined cluster. See modules/services/containerization/k3s.nix
for the full option set (role, node labels and taints, manifests).
The cluster token is a file from the secrets provider, tokenFile, and never
a string in the configuration. An agent, or a server that joins another through
serverAddr, must set it; a single server that initialises its own cluster
needs none. openFirewall is off by default. On, it opens the kubelet and the
flannel tunnel on every node, the API on a server, and embedded etcd only on a
server that initialises or joins a cluster. k3s bundles its own Traefik on 80
and 443, so a server beside othrys.services.traefik must list "traefik" in
disable. /etc/rancher, which holds the admin kubeconfig, is persisted
private to root.
hardenedFlags is on by default and starts a server with
--write-kubeconfig-mode=0600 and --secrets-encryption, ahead of
extraFlags. k3s requires every server of a cluster to agree on secrets
encryption, so all of them take the same value. A cluster created without
encryption sets hardenedFlags = false and turns encryption on with
k3s secrets-encrypt, as the k3s documentation describes. An agent takes
neither flag. Forwarding is switched on through net.ipv4.conf.all.forwarding
as a default, the key othrys.services.router writes, so a host with both
emits it once.