Merge: nixos/oci-containers: stricter dependencies for rootless containers with sdnotify=healthy (#394039)

Changed files
+25 -3
nixos
modules
virtualisation
tests
+24 -3
nixos/modules/virtualisation/oci-containers.nix
···
};
effectiveUser = container.podman.user or "root";
+
inherit (config.users.users.${effectiveUser}) uid;
dependOnLingerService =
cfg.backend == "podman" && effectiveUser != "root" && config.users.users.${effectiveUser}.linger;
in
···
wantedBy = [ ] ++ optional (container.autoStart) "multi-user.target";
wants =
lib.optional (container.imageFile == null && container.imageStream == null) "network-online.target"
-
++ lib.optional dependOnLingerService "linger-users.service";
+
++ lib.optionals dependOnLingerService [ "linger-users.service" ];
after =
lib.optionals (cfg.backend == "docker") [
"docker.service"
···
"network-online.target"
]
++ dependsOn
-
++ lib.optional dependOnLingerService "linger-users.service";
-
requires = dependsOn;
+
++ lib.optionals dependOnLingerService [ "linger-users.service" ]
+
++ lib.optionals (effectiveUser != "root" && container.podman.sdnotify == "healthy") [
+
"user@${toString uid}.service"
+
];
+
requires =
+
dependsOn
+
++ lib.optionals (effectiveUser != "root" && container.podman.sdnotify == "healthy") [
+
"user@${toString uid}.service"
+
];
environment = lib.mkMerge [
proxy_env
(mkIf (cfg.backend == "podman" && container.podman.user != "root") {
···
else
"${cfg.backend} rm -f ${name} || true";
+
unitConfig = mkIf (effectiveUser != "root") {
+
RequiresMountsFor = "/run/user/${toString uid}/containers";
+
};
+
serviceConfig =
{
### There is no generalized way of supporting `reload` for docker
···
{
assertion = cfg.backend == "docker" -> podman == null;
message = "virtualisation.oci-containers.containers.${name}: Cannot set `podman` option if backend is `docker`.";
+
}
+
{
+
assertion =
+
cfg.backend == "podman" && podman.sdnotify == "healthy" && podman.user != "root"
+
-> config.users.users.${podman.user}.uid != null;
+
message = ''
+
Rootless container ${name} (with podman and sdnotify=healthy)
+
requires that its running user ${podman.user} has a statically specified uid.
+
'';
}
];
in
+1
nixos/tests/oci-containers.nix
···
home = "/var/lib/redis";
linger = type == "healthy";
createHome = true;
+
uid = 2342;
subUidRanges = [
{
count = 65536;