diff options
| author | tv <tv@krebsco.de> | 2026-11-20 04:17:07 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-20 04:17:07 +0000 |
| commit | 24f2fb6eb968acef443e510af6819dba35339282 (patch) | |
| tree | ea9fa884b069905ae7f205c589987fde7d6814e1 /pkgs | |
| parent | 2d3fabb736e681d1b3f5f91e2d7897ea35aa4c58 (diff) | |
drop rw-store paths that a lower layer has, before mounting the store
nix in the guest deletes a path in the store that isn't in its
database before it adds it, like any of the host's store's paths, which
aren't registered. On the overlay, that leaves a whiteout in the
rw-store, or an opaque directory with what nix adds again, if it gets
that far. With a persistent rw-store, that hides the path from every
later boot, from images that have it, too: a hermes layer's setup
failed with exit 255, as python3's binary wrapper couldn't exec the
python the rw-store hid.
A path that a lower layer has is complete there, and the same as
anything of that name in the rw-store. So drop such paths from the
rw-store in the initrd, before sysroot-nix-store.mount; what's left is
what only the guest added.
Diffstat (limited to 'pkgs')
| -rw-r--r-- | pkgs/run-firecracker-vm/default.nix | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/pkgs/run-firecracker-vm/default.nix b/pkgs/run-firecracker-vm/default.nix index 2705d1f..0cd8e79 100644 --- a/pkgs/run-firecracker-vm/default.nix +++ b/pkgs/run-firecracker-vm/default.nix @@ -44,7 +44,10 @@ let # The system of the first n layers (the base system being layer 0), # with n + 1 images. - evalSystem = n: import (pkgs.path + "/nixos") { + evalSystem = n: let + # The overlay's lower layers: the images, then the host's store. + lowerdirs = lib.genList (k: "/nix/.image/${toString k}") (n + 1) ++ [ "/nix/.host-store" ]; + in import (pkgs.path + "/nixos") { inherit (pkgs.stdenv.hostPlatform) system; configuration = { config, modulesPath, ... }: { imports = [ @@ -114,10 +117,36 @@ let serviceConfig.ExecStart = "${pkgs.coreutils}/bin/mkdir -p -m 0755 /nix/.rw-store/var"; }; fileSystems."/nix/store".overlay = { - lowerdir = lib.genList (k: "/nix/.image/${toString k}") (n + 1) ++ [ "/nix/.host-store" ]; + lowerdir = lowerdirs; upperdir = "/nix/.rw-store/store"; workdir = "/nix/.rw-store/work"; }; + # nix in the guest deletes a path in the store that isn't in its + # database before it adds it, like the host's store's paths. On the + # overlay, deleting a lower layer's path leaves a whiteout in the rw-store, + # or an opaque directory, which is what nix adds again, if it gets that + # far. With a persistent rw-store, that hides the path from any + # later image, too. Any path that a lower layer has is complete + # there, and the same as anything of that name in the rw-store, so + # drop such paths from the rw-store before mounting the overlay. + boot.initrd.systemd.services.fc-rw-store-unshadow = { + requiredBy = [ "sysroot-nix-store.mount" ]; + before = [ "sysroot-nix-store.mount" ]; + unitConfig.DefaultDependencies = false; + unitConfig.RequiresMountsFor = map (d: "/sysroot" + d) ([ "/nix/.rw-store" ] ++ lowerdirs); + serviceConfig.Type = "oneshot"; + script = '' + cd /sysroot/nix/.rw-store/store 2>/dev/null || exit 0 + for p in *; do + for d in ${toString (map (d: "/sysroot" + d) lowerdirs)}; do + if test -e "$d/$p"; then + rm -rf "$p" + break + fi + done + done + ''; + }; # nix, with the host's nixpkgs for nix-shell -p and the like, at # /nixpkgs (see below). Root goes through the daemon too, so the |
