From 6eb17cb3bf9b9d8e948b7a8cc09d6d51d6f4c373 Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 25 Nov 2026 13:43:44 +0000 Subject: layers/nix.nix: keep the rw-store's copies of the host's store's paths fc-rw-store-unshadow dropped every path in the rw-store that a lower layer had, as complete there, including the host's store. But the host's store isn't fixed like the images: its garbage collection can remove a path any time, and then a path the guest's nix had added and still has registered (its own copy dropped at boot, in favour of the host's) is gone. nix-store --verify then can't fix the database (the missing paths have valid referrers), nix-load-db fails, and with it the nix daemon. Now only paths that an image has get dropped, and of the host's store's, only whiteouts, which would hide its path; real copies stay (tested in a scratch tree, with a whiteout made in a user namespace). --- layers/nix.nix | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/layers/nix.nix b/layers/nix.nix index 02c37ac..f4dc07f 100644 --- a/layers/nix.nix +++ b/layers/nix.nix @@ -61,9 +61,13 @@ in # 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. + # later image, too. Any path that an image 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. Not so for the host's + # store, which can lose a path any time (its garbage collection), while + # the guest's nix still has it registered (then nix-store --verify + # fails): drop only whiteouts, which would hide the host's path, and + # keep real copies. boot.initrd.systemd.services.fc-rw-store-unshadow = { requiredBy = [ "sysroot-nix-store.mount" ]; before = [ "sysroot-nix-store.mount" ]; @@ -74,12 +78,17 @@ in mkdir -p -m 0755 /sysroot/nix/.rw-store/store /sysroot/nix/.rw-store/work cd /sysroot/nix/.rw-store/store for p in *; do - for d in ${toString (map (d: "/sysroot" + d) lowerdir)}; do + for d in ${toString (map (d: "/sysroot" + d) (lib.remove "/nix/.host-store" lowerdir))}; do if test -e "$d/$p"; then rm -rf "$p" - break + continue 2 fi done + # Whiteouts (character devices, which no store path is) hide the + # host's path, or nothing. + if test -c "$p"; then + rm -f "$p" + fi done ''; }; -- cgit v1.3.1