nixos/oci-containers: add autoRemoveOnStop option (#387051)

This commit is contained in:
Pol Dellaiera
2025-03-10 20:32:42 +01:00
committed by GitHub
@@ -381,6 +381,14 @@ let
'';
};
autoRemoveOnStop = mkOption {
type = types.bool;
default = true;
description = ''
Automatically remove the container when it is stopped or killed
'';
};
networks = mkOption {
type = with types; listOf str;
default = [ ];
@@ -468,7 +476,6 @@ let
++ map escapeShellArg container.preRunExtraOptions
++ [
"run"
"--rm"
"--name=${escapedName}"
"--log-driver=${container.log-driver}"
]
@@ -489,6 +496,7 @@ let
++ (mapAttrsToList (k: v: "-l ${escapeShellArg k}=${escapeShellArg v}") container.labels)
++ optional (container.workdir != null) "-w ${escapeShellArg container.workdir}"
++ optional (container.privileged) "--privileged"
++ optional (container.autoRemoveOnStop) "--rm"
++ mapAttrsToList (k: _: "--cap-add=${escapeShellArg k}") (
filterAttrs (_: v: v == true) container.capabilities
)