at 24.11-pre 1.5 kB view raw
1{ lib, stdenv, squashfsTools, closureInfo 2 3, fileName ? "squashfs" 4, # The root directory of the squashfs filesystem is filled with the 5 # closures of the Nix store paths listed here. 6 storeContents ? [] 7 # Pseudo files to be added to squashfs image 8, pseudoFiles ? [] 9, noStrip ? false 10, # Compression parameters. 11 # For zstd compression you can use "zstd -Xcompression-level 6". 12 comp ? "xz -Xdict-size 100%" 13}: 14 15let 16 pseudoFilesArgs = lib.concatMapStrings (f: ''-p "${f}" '') pseudoFiles; 17 compFlag = if comp == null then "-no-compression" else "-comp ${comp}"; 18in 19stdenv.mkDerivation { 20 name = "${fileName}.img"; 21 __structuredAttrs = true; 22 23 nativeBuildInputs = [ squashfsTools ]; 24 25 buildCommand = 26 '' 27 closureInfo=${closureInfo { rootPaths = storeContents; }} 28 29 # Also include a manifest of the closures in a format suitable 30 # for nix-store --load-db. 31 cp $closureInfo/registration nix-path-registration 32 33 '' + lib.optionalString stdenv.buildPlatform.is32bit '' 34 # 64 cores on i686 does not work 35 # fails with FATAL ERROR: mangle2:: xz compress failed with error code 5 36 if ((NIX_BUILD_CORES > 48)); then 37 NIX_BUILD_CORES=48 38 fi 39 '' + '' 40 41 # Generate the squashfs image. 42 mksquashfs nix-path-registration $(cat $closureInfo/store-paths) $out ${pseudoFilesArgs} \ 43 -no-hardlinks ${lib.optionalString noStrip "-no-strip"} -keep-as-directory -all-root -b 1048576 ${compFlag} \ 44 -processors $NIX_BUILD_CORES 45 ''; 46}