This commit is contained in:
Motiejus Jakštys 2024-07-09 07:51:29 +03:00
parent 132a3d38a8
commit 2257193159

View File

@ -38,8 +38,6 @@ Inputs:
{ {
lib, lib,
runCommand, runCommand,
parallel,
xorg,
}: drv: { }: drv: {
formats, formats,
compressors, compressors,
@ -52,29 +50,22 @@ Inputs:
(matches == 1) (matches == 1)
"compressor-${ext} needs to have exactly one '{}', found ${builtins.toString matches}"; "compressor-${ext} needs to have exactly one '{}', found ${builtins.toString matches}";
compressorMap = lib.filterAttrs (k: _: (lib.hasPrefix "compressor-" k)) args; compressorMap = lib.filterAttrs (k: _: (lib.hasPrefix "compressor-" k)) args;
mkCmd = ext: prog: let mkCmd = ext: prog:
cmdline = builtins.replaceStrings ["{}"] ["\"$fname\""] prog; assert validProg ext prog; ''
in find -L $out -type f -regextype posix-extended -iregex '.*\.(${formatsPipe})' -print0 \
assert validProg ext prog; "${parallel}/bin/sem --id $$ -P$NIX_BUILD_CORES ${cmdline}"; | xargs -0 -P$NIX_BUILD_CORES -I{} ${prog}
'';
formatsPipe = builtins.concatStringsSep "|" formats; formatsPipe = builtins.concatStringsSep "|" formats;
in in
runCommand "${drv.name}-compressed" {} '' runCommand "${drv.name}-compressed" {} ''
mkdir $out mkdir $out
(cd ${drv}; find -L -type d -exec mkdir -p $out/{} ';')
(cd ${drv}; find -L -type f -exec ln -s ${drv}/{} $out/{} ';')
export PARALLEL_HOME=$(mktemp -d)
# Displaying the citation notice once per run of compressDrv is fair game
echo will cite | ${parallel}/bin/parallel --citation
${xorg.lndir}/bin/lndir ${drv}/ $out/
while IFS= read -d "" -r fname; do
${ ${
lib.concatMapStringsSep lib.concatMapStringsSep
"\n" "\n\n"
(ext: mkCmd ext (builtins.getAttr "compressor-${ext}" compressorMap)) (ext: mkCmd ext (builtins.getAttr "compressor-${ext}" compressorMap))
compressors compressors
} }
done < <(find -L $out -print0 -type f -regextype posix-extended -iregex '.*\.(${formatsPipe})')
${parallel}/bin/sem --id ''$$ --wait
'' ''