mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-25 16:33:15 +00:00
4124eb7bd5
Among other things, this preserves the package priority, which is important when building the `hardware.firmware` environment in NixOS.
21 lines
669 B
Nix
21 lines
669 B
Nix
{ runCommand, lib }:
|
|
|
|
firmware:
|
|
|
|
let
|
|
args = lib.optionalAttrs (firmware ? meta) { inherit (firmware) meta; };
|
|
in
|
|
|
|
runCommand "${firmware.name}-xz" args ''
|
|
mkdir -p $out/lib
|
|
(cd ${firmware} && find lib/firmware -type d -print0) |
|
|
(cd $out && xargs -0 mkdir -v --)
|
|
(cd ${firmware} && find lib/firmware -type f -print0) |
|
|
(cd $out && xargs -0rtP "$NIX_BUILD_CORES" -n1 \
|
|
sh -c 'xz -9c -T1 -C crc32 --lzma2=dict=2MiB "${firmware}/$1" > "$1.xz"' --)
|
|
(cd ${firmware} && find lib/firmware -type l) | while read link; do
|
|
target="$(readlink "${firmware}/$link")"
|
|
ln -vs -- "''${target/^${firmware}/$out}.xz" "$out/$link.xz"
|
|
done
|
|
''
|