at 23.11-beta 1.4 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; 17in 18stdenv.mkDerivation { 19 name = "${fileName}.img"; 20 __structuredAttrs = true; 21 22 nativeBuildInputs = [ squashfsTools ]; 23 24 buildCommand = 25 '' 26 closureInfo=${closureInfo { rootPaths = storeContents; }} 27 28 # Also include a manifest of the closures in a format suitable 29 # for nix-store --load-db. 30 cp $closureInfo/registration nix-path-registration 31 32 '' + lib.optionalString stdenv.buildPlatform.is32bit '' 33 # 64 cores on i686 does not work 34 # fails with FATAL ERROR: mangle2:: xz compress failed with error code 5 35 if ((NIX_BUILD_CORES > 48)); then 36 NIX_BUILD_CORES=48 37 fi 38 '' + '' 39 40 # Generate the squashfs image. 41 mksquashfs nix-path-registration $(cat $closureInfo/store-paths) $out ${pseudoFilesArgs} \ 42 -no-hardlinks ${lib.optionalString noStrip "-no-strip"} -keep-as-directory -all-root -b 1048576 -comp ${comp} \ 43 -processors $NIX_BUILD_CORES 44 ''; 45}