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