From 24f2fb6eb968acef443e510af6819dba35339282 Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 20 Nov 2026 04:17:07 +0000 Subject: 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. --- pkgs/run-firecracker-vm/default.nix | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'pkgs/run-firecracker-vm/default.nix') 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 -- cgit v1.3.1