fix bug
diff-pr / dix (pull_request) Successful in 6m49s
lint / lint (pull_request) Canceled after 0s
flake-check / flake-check (pull_request) Canceled after 2m14s

This commit is contained in:
Autumn Liu
2026-09-11 15:50:58 -05:00
parent 6cda214d97
commit 49137f9c16
2 changed files with 13 additions and 7 deletions
+8 -7
View File
@@ -222,11 +222,13 @@ rec {
: Bind mounts, keyed by mount point. : Bind mounts, keyed by mount point.
`resources.devices` `resources.devices`
: Host device nodes to expose, as paths. Bound into the container's `/dev` : Host device nodes to expose, as paths, added to the unit's
and added to the unit's `DeviceAllow=` - the bind alone leaves the cgroup `DeviceAllow=`. nspawn populates a handful of privileged devices
denying `open()`. Nodes keep their host ownership, so a consumer inside (`/dev/kvm`, `/dev/net/tun`, ...) into the container's own `/dev` once
needs `isolation.privateUsers = "identity"` for the owning gid to mean the cgroup allows it, and silently skips ones the host doesn't have -
anything. no `resources.fs` bind mount needed. Nodes keep their host ownership,
so a consumer inside needs `isolation.privateUsers = "identity"` for
the owning gid to mean anything.
`isolation.nixDaemon` `isolation.nixDaemon`
: Whether the Nix daemon and CLI are available inside the container. : Whether the Nix daemon and CLI are available inside the container.
@@ -293,7 +295,6 @@ rec {
+ lib.optionalString useIdmap ":idmap" + lib.optionalString useIdmap ":idmap"
) allBindMounts; ) allBindMounts;
bindMountHostPaths = map (bm: bm.hostPath) (lib.attrValues allBindMounts); bindMountHostPaths = map (bm: bm.hostPath) (lib.attrValues allBindMounts);
deviceFlags = map (d: "--bind=${d}") devices;
inherit (deriveIdentity ifPrefix.nspawn name) inherit (deriveIdentity ifPrefix.nspawn name)
iface iface
mac mac
@@ -380,7 +381,7 @@ rec {
nixosContainer = { nixosContainer = {
inherit autoStart privateUsers; inherit autoStart privateUsers;
bindMounts = { }; bindMounts = { };
extraFlags = bindMountExtraFlags ++ deviceFlags; extraFlags = bindMountExtraFlags;
privateNetwork = true; privateNetwork = true;
extraVeths = linkVeths; extraVeths = linkVeths;
config = config =
+5
View File
@@ -333,6 +333,11 @@ with subtest("(functional): published ports follow the container's lifetime"):
with subtest("(functional): declared devices are usable in-container"): with subtest("(functional): declared devices are usable in-container"):
for name, devices in DEVICES.items(): for name, devices in DEVICES.items():
for dev in devices: for dev in devices:
if server.execute(f"test -e {dev}")[0] != 0:
# host lacks the device (e.g. /dev/kvm without nested
# virtualization, as in this test's own VM) - nspawn skips
# populating it in-container, so there's nothing to check.
continue
# opened, not stat'd: without DeviceAllow= the node is still visible # opened, not stat'd: without DeviceAllow= the node is still visible
server.succeed(ct_cmd(name, f"exec 3<> {dev}")) server.succeed(ct_cmd(name, f"exec 3<> {dev}"))