squashes / cpios: properly break the Nix storepaths by breaking them up in to chunks

This commit is contained in:
Graham Christensen
2020-06-08 09:17:32 -04:00
parent ee99e276cf
commit 4e8c7a08b8
3 changed files with 30 additions and 15 deletions

View File

@@ -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

View File

@@ -1,4 +1,4 @@
{ reverse ? false, pathsJson, pkgs ? import <nixpkgs> {} }:
{ pathsJson, pkgs ? import <nixpkgs> {} }:
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)