diff options
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 |
