1{ stdenv, squashfsTools, closureInfo
2
3, # The root directory of the squashfs filesystem is filled with the
4 # closures of the Nix store paths listed here.
5 storeContents ? []
6, # Compression parameters.
7 # For zstd compression you can use "zstd -Xcompression-level 6".
8 comp ? "xz -Xdict-size 100%"
9}:
10
11stdenv.mkDerivation {
12 name = "squashfs.img";
13
14 nativeBuildInputs = [ squashfsTools ];
15
16 buildCommand =
17 ''
18 closureInfo=${closureInfo { rootPaths = storeContents; }}
19
20 # Also include a manifest of the closures in a format suitable
21 # for nix-store --load-db.
22 cp $closureInfo/registration nix-path-registration
23
24 # Generate the squashfs image.
25 mksquashfs nix-path-registration $(cat $closureInfo/store-paths) $out \
26 -no-hardlinks -keep-as-directory -all-root -b 1048576 -comp ${comp}
27 '';
28}