nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 runCommand,
3 lib,
4 type ? "zstd",
5 zstd,
6}:
7
8firmware:
9
10let
11 compressor =
12 {
13 xz = {
14 ext = "xz";
15 nativeBuildInputs = [ ];
16 cmd = file: target: ''xz -9c -T1 -C crc32 --lzma2=dict=2MiB "${file}" > "${target}"'';
17 };
18 zstd = {
19 ext = "zst";
20 nativeBuildInputs = [ zstd ];
21 cmd = file: target: ''zstd -T1 -19 --long --check -f "${file}" -o "${target}"'';
22 };
23 }
24 .${type} or (throw "Unsupported compressor type for firmware.");
25
26 args = {
27 outputChecks.out.allowedRequisites = [ "out" ];
28 __structuredAttrs = true;
29 inherit (compressor) nativeBuildInputs;
30 }
31 // lib.optionalAttrs (firmware ? meta) { inherit (firmware) meta; };
32in
33
34runCommand "${firmware.name}-${type}" args ''
35 mkdir -p $out/lib
36 (cd ${firmware} && find lib/firmware -type d -print0) |
37 (cd $out && xargs -0 mkdir -v --)
38 (cd ${firmware} && find lib/firmware -type f -print0) |
39 (cd $out && xargs -0rtP "$NIX_BUILD_CORES" -n1 \
40 sh -c '${compressor.cmd "${firmware}/$1" "$1.${compressor.ext}"}' --)
41 (cd ${firmware} && find lib/firmware -type l) | while read link; do
42 target="$(readlink "${firmware}/$link")"
43 if [ -f "${firmware}/$link" ]; then
44 ln -vs -- "''${target/^${firmware}/$out}.${compressor.ext}" "$out/$link.${compressor.ext}"
45 else
46 ln -vs -- "''${target/^${firmware}/$out}" "$out/$link"
47 fi
48 done
49
50 echo "Checking for broken symlinks:"
51 find -L $out -type l -print -execdir false -- '{}' '+'
52''