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 allowedRequisites = [ ];
28 inherit (compressor) nativeBuildInputs;
29 }
30 // lib.optionalAttrs (firmware ? meta) { inherit (firmware) meta; };
31in
32
33runCommand "${firmware.name}-${type}" args ''
34 mkdir -p $out/lib
35 (cd ${firmware} && find lib/firmware -type d -print0) |
36 (cd $out && xargs -0 mkdir -v --)
37 (cd ${firmware} && find lib/firmware -type f -print0) |
38 (cd $out && xargs -0rtP "$NIX_BUILD_CORES" -n1 \
39 sh -c '${compressor.cmd "${firmware}/$1" "$1.${compressor.ext}"}' --)
40 (cd ${firmware} && find lib/firmware -type l) | while read link; do
41 target="$(readlink "${firmware}/$link")"
42 if [ -f "${firmware}/$link" ]; then
43 ln -vs -- "''${target/^${firmware}/$out}.${compressor.ext}" "$out/$link.${compressor.ext}"
44 else
45 ln -vs -- "''${target/^${firmware}/$out}" "$out/$link"
46 fi
47 done
48
49 echo "Checking for broken symlinks:"
50 find -L $out -type l -print -execdir false -- '{}' '+'
51''