diff --git a/pkgs/squashfs-recursive/default.nix b/pkgs/squashfs-recursive/default.nix index 5d1bcc2..d1a66a0 100644 --- a/pkgs/squashfs-recursive/default.nix +++ b/pkgs/squashfs-recursive/default.nix @@ -2,20 +2,28 @@ let map-squash = ./map-squash.nix; - mkSquashfsManifest = { name, storeContents, reverse ? false }: - runCommand "${name}-squashfs-manifest" { + mkSquashfsManifest = { name, storeContents }: + runCommand "${name}-squashfs-manifests" { buildInputs = [ nix jq ]; requiredSystemFeatures = [ "recursive-nix" ]; exportReferencesGraph = [ "root" storeContents ]; NIX_PATH = "nixpkgs=${path}"; + outputs = [ "out" "manifest" ]; } '' cat root | grep /nix/store | sort | uniq | jq -R . | jq -s . > paths.json - nix-build ${map-squash} --arg pathsJson ./paths.json --arg reverse ${if reverse then "true" else "false"} + nix-build ${map-squash} --arg pathsJson ./paths.json touch $out for f in $(cat result); do find "$f" -type f >> $out done + + touch $manifest + for f in $(cat "$out"); do + prefix=$(echo "$f" | head -c20) + suffix=$(echo "$f" | tail -c+21) + echo "$prefix $suffix" >> $manifest + done ''; in mkSquashfsManifest diff --git a/pkgs/squashfs-recursive/map-squash.nix b/pkgs/squashfs-recursive/map-squash.nix index 5125145..88d9577 100644 --- a/pkgs/squashfs-recursive/map-squash.nix +++ b/pkgs/squashfs-recursive/map-squash.nix @@ -1,4 +1,4 @@ -{ reverse ? false, pathsJson, pkgs ? import {} }: +{ pathsJson, pkgs ? import {} }: let namePart = strPath: let @@ -12,7 +12,9 @@ let buildInputs = [ pkgs.squashfsTools pkgs.utillinux ]; } '' mkdir $out - revout=$(echo "$(basename ${strPath})" | rev) + dirname=$(echo "$(basename ${strPath})" | head -c8) + filename=$(echo "$(basename ${strPath})" | tail -c+9) + mksquashfs \ "${builtins.storePath strPath}" \ ./result \ @@ -20,11 +22,8 @@ let -keep-as-directory \ -all-root - if ${if reverse then "true" else "false"}; then - tac result > result.rev - mv result.rev result - fi - mv result "$out/$revout" + mkdir -p "$out/$dirname" + mv result "$out/$dirname/$filename" ''; in pkgs.writeText "squashes" (pkgs.lib.concatMapStringsSep "\n" mksquash paths) diff --git a/quickly.nix b/quickly.nix index 2182baa..fa4033c 100644 --- a/quickly.nix +++ b/quickly.nix @@ -46,8 +46,12 @@ in mkdir -p /mnt-root/nix/.squash mkdir -p /mnt-root/nix/store - for f in $(rev /nix-store-isos); do - dest=$(basename "$f" | rev) + # the manifest splits the /nix/store/.... path with a " " to + # prevent Nix from determining it depends on things. + for f in $(cat /nix-store-isos | sed 's/ //'); do + prefix=$(basename "$(dirname "$f")") + suffix=$(basename "$f") + dest="$prefix$suffix" echo "$dest" mkdir "/mnt-root/nix/.squash/$dest" mount -t squashfs -o loop "$f" "/mnt-root/nix/.squash/$dest" @@ -80,6 +84,12 @@ in inherit config pkgs; initrds = { initrd = "${config.system.build.initialRamdisk}/initrd"; + + # squashfsStore is just a manifest file, and makeCpioRecursive + # will bring in all its dependencies automatically. + # the nix-store initrd is the actual files, and the manifest + # is intentionally only just the manifest file, located + # at /nix-store-isos nix-store = "${( netbootpkgs.makeCpioRecursive { name = "better-initrd"; @@ -92,9 +102,7 @@ in contents = [ { - object = pkgs.runCommand "nix-store-isos-reversed" {} '' - ${pkgs.utillinux}/bin/rev ${config.system.build.squashfsStore} > $out - ''; + object = config.system.build.squashfsStore.manifest; symlink = "/nix-store-isos"; } ];