makeSquashfsManifest: recursively create squashfs

This commit is contained in:
Graham Christensen 2020-05-25 21:46:51 -04:00
parent 6ecf5bfa0f
commit 138e51b3b3
No known key found for this signature in database
GPG Key ID: FE918C3A98C1030F
3 changed files with 52 additions and 0 deletions

View File

@ -1,4 +1,5 @@
{ callPackage }: { callPackage }:
{ {
makeCpioRecursive = callPackage ./cpio-recursive {}; makeCpioRecursive = callPackage ./cpio-recursive {};
makeSquashfsManifest = callPackage ./squashfs-recursive {};
} }

View File

@ -0,0 +1,21 @@
{ runCommand, nixUnstable, jq, path }:
let
map-squash = ./map-squash.nix;
mkSquashfsManifest = { name, storeContents, reverse ? false }:
runCommand "${name}-squashfs-manifest" {
buildInputs = [ nixUnstable jq ];
requiredSystemFeatures = [ "recursive-nix" ];
exportReferencesGraph = [ "root" storeContents ];
NIX_PATH = "nixpkgs=${path}";
} ''
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"}
touch $out
for f in $(cat result); do
find "$f" -type f >> $out
done
'';
in
mkSquashfsManifest

View File

@ -0,0 +1,30 @@
{ reverse ? false, pathsJson, pkgs ? import <nixpkgs> {} }:
let
namePart = strPath:
let
nameParts = builtins.tail (builtins.tail (builtins.split "[-]" strPath));
namePartsWithDashes = (builtins.map (x: if x == [] then "-" else x) nameParts);
in
builtins.foldl' (collect: part: "${collect}${part}") "" namePartsWithDashes;
paths = builtins.fromJSON (builtins.readFile pathsJson);
mksquash = strPath: pkgs.runCommand "${namePart strPath}-squash" {
buildInputs = [ pkgs.squashfsTools pkgs.utillinux ];
} ''
mkdir $out
revout=$(echo "$(basename ${strPath})" | rev)
mksquashfs \
"${builtins.storePath strPath}" \
./result \
-comp gzip -Xcompression-level 9 \
-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"
'';
in
pkgs.writeText "squashes" (pkgs.lib.concatMapStringsSep "\n" mksquash paths)