@@ -126,6 +126,9 @@ function closure() {
126126}
127127
128128system_closure="$tmpdir/system.closure"
129+# Use a FIFO for piping nix-store --export into nix-store --import, saving disk
130+# I/O and space. nix-store --import is run by nixos-prepare-root.
131+mkfifo $system_closure
129132
130133if [ -z "$closure" ]; then
131134 expr="(import <nixpkgs/nixos> {}).system"
@@ -135,7 +138,9 @@ else
135138 system_root=$closure
136139 # Create a temporary file ending in .closure (so nixos-prepare-root knows to --import it) to transport the store closure
137140 # to the filesytem we're preparing. Also delete it on exit!
138− nix-store --export $(nix-store -qR $closure) > $system_closure
141+ # Run in background to avoid blocking while trying to write to the FIFO
142+ # $system_closure refers to
143+ nix-store --export $(nix-store -qR $closure) > $system_closure &
139144fi
140145
141146channel_root="$(nix-env -p /nix/var/nix/profiles/per-user/root/channels -q nixos --no-name --out-path 2>/dev/null || echo -n "")"