mirror of
https://github.com/NixOS/nixpkgs.git
synced 2026-12-06 04:40:10 +00:00
nixos/oci-containers: add tmpFs option (#572731)
This commit is contained in:
@@ -705,6 +705,8 @@ The above example can be migrated via the following structured code block:
|
||||
|
||||
- The `newuidmap` and `newgidmap` security wrappers are now installed with `cap_setuid`/`cap_setgid` file capabilities instead of the setuid-root bit, matching shadow's `--with-fcaps` install mode and other major distributions. Rootless containers (podman, docker-rootless, unprivileged user namespaces) are unaffected. The only behavioural change is that mapping host uid 0 via `/etc/subuid` (which NixOS never configures by default) additionally requires `cap_setfcap`; users who explicitly grant uid 0 in a subuid range can restore the previous behaviour with `security.wrappers.newuidmap.capabilities = lib.mkForce "cap_setuid,cap_setfcap+ep";`.
|
||||
|
||||
- Added `virtualisation.oci-containers.containers.<name>.tmpFs` to configure `tmpfs` mounts on OCI containers. Refer to the [Docker engine documentation](https://docs.docker.com/engine/storage/tmpfs/) for the full list of mount options.
|
||||
|
||||
- The `authelia` module now uses systemd's `LoadCredential` to load all files defined in `secrets`. As such, these files no longer need to be readable by the authelia user and group: they can for example be set to be only readable by the root user.
|
||||
|
||||
- `zoneminder` has been updated to 1.38.x release. See [upstream release note](https://github.com/ZoneMinder/zoneminder/releases/tag/1.38.0). While database migration should happen automatically, it's recommended that you make a backup of the database before upgrading your system.
|
||||
|
||||
@@ -219,6 +219,26 @@ let
|
||||
];
|
||||
};
|
||||
|
||||
tmpFs = mkOption {
|
||||
type = types.attrsOf (types.listOf types.str);
|
||||
default = { };
|
||||
description = ''
|
||||
Attribute set of container paths to mount into a tmpfs.
|
||||
|
||||
Mount options for tmpfs may be passed in as a list for each path.
|
||||
For the full list of options, refer to the
|
||||
[Docker engine documentation](https://docs.docker.com/engine/storage/tmpfs/).
|
||||
'';
|
||||
example = {
|
||||
"/data" = [
|
||||
"noexec"
|
||||
"size=1024"
|
||||
"mode=1777"
|
||||
];
|
||||
"/defaultData" = [ ];
|
||||
};
|
||||
};
|
||||
|
||||
workdir = mkOption {
|
||||
type = with types; nullOr str;
|
||||
default = null;
|
||||
@@ -459,47 +479,52 @@ let
|
||||
else
|
||||
throw "Unhandled backend: ${cfg.backend}";
|
||||
|
||||
script = concatStringsSep " \\\n " (
|
||||
[
|
||||
"exec ${cfg.backend} "
|
||||
]
|
||||
++ map escapeShellArg container.preRunExtraOptions
|
||||
++ [
|
||||
"run"
|
||||
"--name=${escapedName}"
|
||||
"--log-driver=${container.log-driver}"
|
||||
]
|
||||
++ optional (container.entrypoint != null) "--entrypoint=${escapeShellArg container.entrypoint}"
|
||||
++ optional (container.hostname != null) "--hostname=${escapeShellArg container.hostname}"
|
||||
++ lib.optionals (cfg.backend == "podman") [
|
||||
"--cidfile=/run/${escapedName}/ctr-id"
|
||||
"--cgroups=enabled"
|
||||
"--sdnotify=${container.podman.sdnotify}"
|
||||
"-d"
|
||||
"--replace"
|
||||
]
|
||||
++ (mapAttrsToList (k: v: "-e ${escapeShellArg k}=${escapeShellArg v}") container.environment)
|
||||
++ map (f: "--env-file ${escapeShellArg f}") container.environmentFiles
|
||||
++ map (p: "-p ${escapeShellArg p}") container.ports
|
||||
++ optional (container.user != null) "-u ${escapeShellArg container.user}"
|
||||
++ map (v: "-v ${escapeShellArg v}") container.volumes
|
||||
++ (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
|
||||
)
|
||||
++ mapAttrsToList (k: _: "--cap-drop=${escapeShellArg k}") (
|
||||
filterAttrs (_: v: v == false) container.capabilities
|
||||
)
|
||||
++ map (d: "--device=${escapeShellArg d}") container.devices
|
||||
++ map (n: "--network=${escapeShellArg n}") (lib.lists.unique container.networks)
|
||||
++ [ "--pull ${escapeShellArg container.pull}" ]
|
||||
++ map escapeShellArg container.extraOptions
|
||||
++ [ container.image ]
|
||||
++ map escapeShellArg container.cmd
|
||||
);
|
||||
script =
|
||||
let
|
||||
concatOptions = options: optionalString (options != [ ]) ":${concatStringsSep "," options}";
|
||||
in
|
||||
concatStringsSep " \\\n " (
|
||||
[
|
||||
"exec ${cfg.backend} "
|
||||
]
|
||||
++ map escapeShellArg container.preRunExtraOptions
|
||||
++ [
|
||||
"run"
|
||||
"--name=${escapedName}"
|
||||
"--log-driver=${container.log-driver}"
|
||||
]
|
||||
++ optional (container.entrypoint != null) "--entrypoint=${escapeShellArg container.entrypoint}"
|
||||
++ optional (container.hostname != null) "--hostname=${escapeShellArg container.hostname}"
|
||||
++ lib.optionals (cfg.backend == "podman") [
|
||||
"--cidfile=/run/${escapedName}/ctr-id"
|
||||
"--cgroups=enabled"
|
||||
"--sdnotify=${container.podman.sdnotify}"
|
||||
"-d"
|
||||
"--replace"
|
||||
]
|
||||
++ (mapAttrsToList (k: v: "-e ${escapeShellArg k}=${escapeShellArg v}") container.environment)
|
||||
++ map (f: "--env-file ${escapeShellArg f}") container.environmentFiles
|
||||
++ map (p: "-p ${escapeShellArg p}") container.ports
|
||||
++ optional (container.user != null) "-u ${escapeShellArg container.user}"
|
||||
++ map (v: "-v ${escapeShellArg v}") container.volumes
|
||||
++ (mapAttrsToList (k: v: "--tmpfs ${escapeShellArg k}${concatOptions v}") container.tmpFs)
|
||||
++ (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
|
||||
)
|
||||
++ mapAttrsToList (k: _: "--cap-drop=${escapeShellArg k}") (
|
||||
filterAttrs (_: v: v == false) container.capabilities
|
||||
)
|
||||
++ map (d: "--device=${escapeShellArg d}") container.devices
|
||||
++ map (n: "--network=${escapeShellArg n}") (lib.lists.unique container.networks)
|
||||
++ [ "--pull ${escapeShellArg container.pull}" ]
|
||||
++ map escapeShellArg container.extraOptions
|
||||
++ [ container.image ]
|
||||
++ map escapeShellArg container.cmd
|
||||
);
|
||||
|
||||
preStop =
|
||||
if cfg.backend == "podman" then
|
||||
|
||||
@@ -37,6 +37,11 @@ let
|
||||
devices = [
|
||||
"/dev/random:/dev/random"
|
||||
];
|
||||
tmpFs."/custom-tmp" = [
|
||||
"noexec"
|
||||
"size=1024"
|
||||
"mode=1777"
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
@@ -63,6 +68,9 @@ let
|
||||
assert output['HostConfig']['Devices'] == [{'PathOnHost': '/dev/random', 'PathInContainer': '/dev/random', 'CgroupPermissions': '${
|
||||
if backend == "docker" then "rwm" else ""
|
||||
}'}]
|
||||
assert output['HostConfig']['Tmpfs'] == {'/custom-tmp': 'noexec,size=1024,mode=1777${
|
||||
lib.optionalString (backend == "podman") ",rprivate,nosuid,nodev,tmpcopyup"
|
||||
}'}
|
||||
''
|
||||
+ lib.strings.optionalString (backend == "podman") ''
|
||||
assert output['Config']['Labels']['PODMAN_SYSTEMD_UNIT'] == '${serviceName}.service'
|
||||
|
||||
Reference in New Issue
Block a user