2025-03-17 19:39:28 +01:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
utils,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
2020-04-20 09:37:53 +01:00
|
|
|
let
|
|
|
|
cfg = config.virtualisation.podman;
|
2021-05-27 16:19:01 +02:00
|
|
|
json = pkgs.formats.json { };
|
2020-04-20 09:37:53 +01:00
|
|
|
|
|
|
|
inherit (lib) mkOption types;
|
|
|
|
|
|
|
|
# Provides a fake "docker" binary mapping to podman
|
2024-12-23 23:32:25 +11:00
|
|
|
dockerCompat =
|
|
|
|
pkgs.runCommand "${cfg.package.pname}-docker-compat-${cfg.package.version}"
|
2022-08-18 09:53:45 +10:00
|
|
|
{
|
|
|
|
outputs = [
|
|
|
|
"out"
|
|
|
|
"man"
|
|
|
|
];
|
2024-12-23 23:32:25 +11:00
|
|
|
inherit (cfg.package) meta;
|
2024-09-10 10:53:46 +00:00
|
|
|
preferLocalBuild = true;
|
2022-08-18 09:53:45 +10:00
|
|
|
}
|
|
|
|
''
|
2020-05-01 18:24:09 +10:00
|
|
|
mkdir -p $out/bin
|
2024-12-23 23:32:25 +11:00
|
|
|
ln -s ${cfg.package}/bin/podman $out/bin/docker
|
2025-04-01 20:10:43 +02:00
|
|
|
|
2020-04-20 09:37:53 +01:00
|
|
|
mkdir -p $man/share/man/man1
|
2024-12-23 23:32:25 +11:00
|
|
|
for f in ${cfg.package.man}/share/man/man1/*; do
|
2020-04-20 09:37:53 +01:00
|
|
|
basename=$(basename $f | sed s/podman/docker/g)
|
|
|
|
ln -s $f $man/share/man/man1/$basename
|
|
|
|
done
|
|
|
|
'';
|
|
|
|
|
|
|
|
in
|
|
|
|
{
|
2020-05-14 16:28:32 +10:00
|
|
|
imports = [
|
2022-08-18 13:58:03 +10:00
|
|
|
(lib.mkRemovedOptionModule [
|
|
|
|
"virtualisation"
|
|
|
|
"podman"
|
|
|
|
"defaultNetwork"
|
|
|
|
"dnsname"
|
|
|
|
] "Use virtualisation.podman.defaultNetwork.settings.dns_enabled instead.")
|
|
|
|
(lib.mkRemovedOptionModule [
|
|
|
|
"virtualisation"
|
|
|
|
"podman"
|
|
|
|
"defaultNetwork"
|
|
|
|
"extraPlugins"
|
|
|
|
] "Netavark isn't compatible with CNI plugins.")
|
2021-12-09 12:10:44 +10:00
|
|
|
./network-socket.nix
|
2020-05-14 16:28:32 +10:00
|
|
|
];
|
|
|
|
|
2020-04-20 12:35:36 +01:00
|
|
|
meta = {
|
|
|
|
maintainers = lib.teams.podman.members;
|
|
|
|
};
|
2020-04-20 09:37:53 +01:00
|
|
|
|
|
|
|
options.virtualisation.podman = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
This option enables Podman, a daemonless container engine for
|
|
|
|
developing, managing, and running OCI Containers on your Linux System.
|
|
|
|
|
|
|
|
It is a drop-in replacement for the {command}`docker` command.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-05-25 10:26:28 +02:00
|
|
|
dockerSocket.enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Make the Podman socket available in place of the Docker socket, so
|
|
|
|
Docker tools can find the Podman socket.
|
|
|
|
|
|
|
|
Podman implements the Docker API.
|
|
|
|
|
|
|
|
Users must be in the `podman` group in order to connect. As
|
|
|
|
with Docker, members of this group can gain root access.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-04-20 09:37:53 +01:00
|
|
|
dockerCompat = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Create an alias mapping {command}`docker` to {command}`podman`.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-01-06 06:01:09 -05:00
|
|
|
enableNvidia = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
2024-07-28 13:12:27 +02:00
|
|
|
**Deprecated**, please use hardware.nvidia-container-toolkit.enable instead.
|
2024-01-28 13:00:32 +01:00
|
|
|
|
2024-05-20 22:17:31 +02:00
|
|
|
Enable use of Nvidia GPUs from within podman containers.
|
2021-01-06 06:01:09 -05:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-04-28 21:27:18 +01:00
|
|
|
extraPackages = mkOption {
|
|
|
|
type = with types; listOf package;
|
|
|
|
default = [ ];
|
2021-10-03 18:06:03 +02:00
|
|
|
example = lib.literalExpression ''
|
2020-04-28 21:27:18 +01:00
|
|
|
[
|
|
|
|
pkgs.gvisor
|
|
|
|
]
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Extra packages to be installed in the Podman wrapper.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2022-12-24 11:58:27 +01:00
|
|
|
autoPrune = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to periodically prune Podman resources. If enabled, a
|
|
|
|
systemd timer will run `podman system prune -f`
|
|
|
|
as specified by the `dates` option.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
flags = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [ ];
|
|
|
|
example = [ "--all" ];
|
|
|
|
description = ''
|
|
|
|
Any additional flags passed to {command}`podman system prune`.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
dates = mkOption {
|
|
|
|
default = "weekly";
|
|
|
|
type = types.str;
|
|
|
|
description = ''
|
|
|
|
Specification (in the format described by
|
|
|
|
{manpage}`systemd.time(7)`) of the time at
|
|
|
|
which the prune will occur.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-12-23 23:32:25 +11:00
|
|
|
package =
|
|
|
|
(lib.mkPackageOption pkgs "podman" {
|
|
|
|
extraDescription = ''
|
|
|
|
This package will automatically include extra packages and runtimes.
|
2020-04-20 12:31:07 +01:00
|
|
|
'';
|
2024-12-23 23:32:25 +11:00
|
|
|
})
|
|
|
|
// {
|
|
|
|
apply =
|
|
|
|
pkg:
|
|
|
|
pkg.override {
|
|
|
|
extraPackages =
|
|
|
|
cfg.extraPackages
|
|
|
|
++ [
|
|
|
|
"/run/wrappers" # setuid shadow
|
|
|
|
config.systemd.package # To allow systemd-based container healthchecks
|
|
|
|
]
|
|
|
|
++ lib.optional (config.boot.supportedFilesystems.zfs or false) config.boot.zfs.package;
|
|
|
|
extraRuntimes =
|
|
|
|
[ pkgs.runc ]
|
|
|
|
++ lib.optionals
|
|
|
|
(
|
|
|
|
config.virtualisation.containers.containersConf.settings.network.default_rootless_network_cmd or ""
|
|
|
|
== "slirp4netns"
|
|
|
|
)
|
|
|
|
(
|
|
|
|
with pkgs;
|
|
|
|
[
|
|
|
|
slirp4netns
|
|
|
|
]
|
|
|
|
);
|
2025-04-01 20:10:43 +02:00
|
|
|
};
|
2024-12-23 23:32:25 +11:00
|
|
|
};
|
2020-04-20 12:31:07 +01:00
|
|
|
|
2022-08-18 13:58:03 +10:00
|
|
|
defaultNetwork.settings = lib.mkOption {
|
|
|
|
type = json.type;
|
|
|
|
default = { };
|
2023-03-27 00:04:15 +02:00
|
|
|
example = lib.literalExpression "{ dns_enabled = true; }";
|
2021-05-27 16:19:01 +02:00
|
|
|
description = ''
|
2022-08-18 13:58:03 +10:00
|
|
|
Settings for podman's default network.
|
2021-05-27 16:19:01 +02:00
|
|
|
'';
|
|
|
|
};
|
2020-04-20 12:31:07 +01:00
|
|
|
|
2020-04-20 09:37:53 +01:00
|
|
|
};
|
|
|
|
|
2024-01-15 18:34:06 +01:00
|
|
|
config =
|
|
|
|
let
|
|
|
|
networkConfig = (
|
|
|
|
{
|
|
|
|
dns_enabled = false;
|
|
|
|
driver = "bridge";
|
|
|
|
id = "0000000000000000000000000000000000000000000000000000000000000000";
|
|
|
|
internal = false;
|
|
|
|
ipam_options = {
|
|
|
|
driver = "host-local";
|
|
|
|
};
|
|
|
|
ipv6_enabled = false;
|
|
|
|
name = "podman";
|
|
|
|
network_interface = "podman0";
|
|
|
|
subnets = [
|
|
|
|
{
|
|
|
|
gateway = "10.88.0.1";
|
|
|
|
subnet = "10.88.0.0/16";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
// cfg.defaultNetwork.settings
|
|
|
|
);
|
|
|
|
inherit (networkConfig) dns_enabled network_interface;
|
|
|
|
in
|
|
|
|
lib.mkIf cfg.enable {
|
2024-01-28 13:00:32 +01:00
|
|
|
warnings = lib.optionals cfg.enableNvidia [
|
|
|
|
''
|
2024-07-31 09:56:09 +02:00
|
|
|
You have set virtualisation.podman.enableNvidia. This option is deprecated, please set hardware.nvidia-container-toolkit.enable instead.
|
2024-01-28 13:00:32 +01:00
|
|
|
''
|
|
|
|
];
|
|
|
|
|
2021-01-06 06:01:09 -05:00
|
|
|
environment.systemPackages = [ cfg.package ] ++ lib.optional cfg.dockerCompat dockerCompat;
|
|
|
|
|
2022-08-18 13:58:03 +10:00
|
|
|
# https://github.com/containers/podman/blob/097cc6eb6dd8e598c0e8676d21267b4edb11e144/docs/tutorials/basic_networking.md#default-network
|
|
|
|
environment.etc."containers/networks/podman.json" = lib.mkIf (cfg.defaultNetwork.settings != { }) {
|
2024-01-15 18:34:06 +01:00
|
|
|
source = json.generate "podman.json" networkConfig;
|
2022-08-18 13:58:03 +10:00
|
|
|
};
|
2021-01-06 06:01:09 -05:00
|
|
|
|
2024-01-15 18:34:06 +01:00
|
|
|
# containers cannot reach aardvark-dns otherwise
|
|
|
|
networking.firewall.interfaces.${network_interface}.allowedUDPPorts = lib.mkIf dns_enabled [ 53 ];
|
|
|
|
|
2021-01-06 06:01:09 -05:00
|
|
|
virtualisation.containers = {
|
|
|
|
enable = true; # Enable common /etc/containers configuration
|
2022-08-18 13:58:03 +10:00
|
|
|
containersConf.settings = {
|
|
|
|
network.network_backend = "netavark";
|
2021-04-03 10:09:40 -04:00
|
|
|
};
|
2021-01-06 06:01:09 -05:00
|
|
|
};
|
2020-04-20 09:37:53 +01:00
|
|
|
|
2021-01-29 01:22:46 +10:00
|
|
|
systemd.packages = [ cfg.package ];
|
|
|
|
|
2022-12-24 11:58:27 +01:00
|
|
|
systemd.services.podman-prune = {
|
|
|
|
description = "Prune podman resources";
|
|
|
|
|
|
|
|
restartIfChanged = false;
|
|
|
|
unitConfig.X-StopOnRemoval = false;
|
|
|
|
|
2025-03-17 19:39:28 +01:00
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
ExecStart = utils.escapeSystemdExecArgs (
|
|
|
|
[
|
|
|
|
(lib.getExe cfg.package)
|
|
|
|
"system"
|
|
|
|
"prune"
|
|
|
|
"-f"
|
|
|
|
]
|
|
|
|
++ cfg.autoPrune.flags
|
|
|
|
);
|
|
|
|
};
|
2022-12-24 11:58:27 +01:00
|
|
|
|
|
|
|
startAt = lib.optional cfg.autoPrune.enable cfg.autoPrune.dates;
|
|
|
|
after = [ "podman.service" ];
|
|
|
|
requires = [ "podman.service" ];
|
|
|
|
};
|
|
|
|
|
2024-02-21 16:29:11 +01:00
|
|
|
systemd.services.podman.environment = config.networking.proxy.envVars;
|
2021-01-29 01:22:46 +10:00
|
|
|
systemd.sockets.podman.wantedBy = [ "sockets.target" ];
|
2021-05-25 10:22:29 +02:00
|
|
|
systemd.sockets.podman.socketConfig.SocketGroup = "podman";
|
2024-05-02 16:04:37 +02:00
|
|
|
# Podman does not support multiple sockets, as of podman 5.0.2, so we use
|
|
|
|
# a symlink. Unfortunately this does not let us use an alternate group,
|
|
|
|
# such as `docker`.
|
|
|
|
systemd.sockets.podman.socketConfig.Symlinks = lib.mkIf cfg.dockerSocket.enable [
|
|
|
|
"/run/docker.sock"
|
|
|
|
];
|
2021-05-25 10:22:29 +02:00
|
|
|
|
2024-02-21 16:29:11 +01:00
|
|
|
systemd.user.services.podman.environment = config.networking.proxy.envVars;
|
2022-06-08 07:23:01 +10:00
|
|
|
systemd.user.sockets.podman.wantedBy = [ "sockets.target" ];
|
|
|
|
|
2023-05-20 02:48:09 +02:00
|
|
|
systemd.timers.podman-prune.timerConfig = lib.mkIf cfg.autoPrune.enable {
|
|
|
|
Persistent = true;
|
|
|
|
RandomizedDelaySec = 1800;
|
|
|
|
};
|
|
|
|
|
2021-05-25 10:22:29 +02:00
|
|
|
systemd.tmpfiles.packages = [
|
|
|
|
# The /run/podman rule interferes with our podman group, so we remove
|
|
|
|
# it and let the systemd socket logic take care of it.
|
2024-09-10 10:53:46 +00:00
|
|
|
(pkgs.runCommand "podman-tmpfiles-nixos"
|
|
|
|
{
|
|
|
|
package = cfg.package;
|
|
|
|
preferLocalBuild = true;
|
|
|
|
}
|
|
|
|
''
|
2021-05-25 10:22:29 +02:00
|
|
|
mkdir -p $out/lib/tmpfiles.d/
|
|
|
|
grep -v 'D! /run/podman 0700 root root' \
|
|
|
|
<$package/lib/tmpfiles.d/podman.conf \
|
|
|
|
>$out/lib/tmpfiles.d/podman.conf
|
2022-08-18 09:53:45 +10:00
|
|
|
''
|
|
|
|
)
|
|
|
|
];
|
2021-05-25 10:22:29 +02:00
|
|
|
|
2022-08-18 09:53:45 +10:00
|
|
|
users.groups.podman = { };
|
2021-01-29 01:22:46 +10:00
|
|
|
|
2021-01-06 06:01:09 -05:00
|
|
|
assertions = [
|
|
|
|
{
|
|
|
|
assertion = cfg.dockerCompat -> !config.virtualisation.docker.enable;
|
|
|
|
message = "Option dockerCompat conflicts with docker";
|
|
|
|
}
|
2021-05-25 10:26:28 +02:00
|
|
|
{
|
|
|
|
assertion = cfg.dockerSocket.enable -> !config.virtualisation.docker.enable;
|
|
|
|
message = ''
|
|
|
|
The options virtualisation.podman.dockerSocket.enable and virtualisation.docker.enable conflict, because only one can serve the socket.
|
|
|
|
'';
|
|
|
|
}
|
2021-01-06 06:01:09 -05:00
|
|
|
];
|
2023-01-25 13:21:36 +01:00
|
|
|
};
|
2020-04-20 09:37:53 +01:00
|
|
|
}
|