1 { lib, stdenv, squashfsTools, closureInfo
3 , fileName ? "squashfs"
4 , # The root directory of the squashfs filesystem is filled with the
5 # closures of the Nix store paths listed here.
7 # Pseudo files to be added to squashfs image
10 , # Compression parameters.
11 # For zstd compression you can use "zstd -Xcompression-level 6".
12 comp ? "xz -Xdict-size 100%"
13 , # create hydra build product. will put image in directory instead
14 # of directly in the store
15 hydraBuildProduct ? false
19 pseudoFilesArgs = lib.concatMapStrings (f: ''-p "${f}" '') pseudoFiles;
20 compFlag = if comp == null then "-no-compression" else "-comp ${comp}";
23 name = "${fileName}${lib.optionalString (!hydraBuildProduct) ".img"}";
24 __structuredAttrs = true;
26 nativeBuildInputs = [ squashfsTools ];
30 closureInfo=${closureInfo { rootPaths = storeContents; }}
32 # Also include a manifest of the closures in a format suitable
33 # for nix-store --load-db.
34 cp $closureInfo/registration nix-path-registration
37 '' + lib.optionalString hydraBuildProduct ''
40 imgPath="$out/${fileName}.squashfs"
41 '' + lib.optionalString stdenv.buildPlatform.is32bit ''
43 # 64 cores on i686 does not work
44 # fails with FATAL ERROR: mangle2:: xz compress failed with error code 5
45 if ((NIX_BUILD_CORES > 48)); then
50 # Generate the squashfs image.
51 mksquashfs nix-path-registration $(cat $closureInfo/store-paths) $imgPath ${pseudoFilesArgs} \
52 -no-hardlinks ${lib.optionalString noStrip "-no-strip"} -keep-as-directory -all-root -b 1048576 ${compFlag} \
53 -processors $NIX_BUILD_CORES
54 '' + lib.optionalString hydraBuildProduct ''
56 mkdir -p $out/nix-support
57 echo "file squashfs-image $out/${fileName}.squashfs" >> $out/nix-support/hydra-build-products