Merge pull request #324748 from OPNA2608/add/input-fonts-postFetch-parallelism

input-fonts: Parallelise postFetch
This commit is contained in:
Franz Pletz 2024-07-09 17:13:49 +02:00 committed by GitHub
commit 67c3af4c39
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -4,6 +4,8 @@
, python3
, config
, acceptLicense ? config.input-fonts.acceptLicense or false
, parallel
, writeShellApplication
}:
let
@ -44,17 +46,28 @@ stdenv.mkDerivation rec {
sha256 = "BESZ4Bjgm2hvQ7oPpMvYSlE8EqvQjqHZtXWIovqyIzA=";
stripRoot = false;
postFetch = ''
# Reset the timestamp to release date for determinism.
PATH=${lib.makeBinPath [ python3.pkgs.fonttools ]}:$PATH
for ttf_file in $out/Input_Fonts/*/*/*.ttf; do
ttx_file=$(dirname "$ttf_file")/$(basename "$ttf_file" .ttf).ttx
ttx "$ttf_file"
rm "$ttf_file"
touch -m -t ${builtins.replaceStrings [ "-" ] [ "" ] releaseDate}0000 "$ttx_file"
ttx --recalc-timestamp "$ttx_file"
rm "$ttx_file"
done
# Reset the timestamp to release date for determinism.
postFetch = let
ttf-fixup = writeShellApplication {
name = "ttf-fixup";
runtimeInputs = [ python3.pkgs.fonttools ];
text = ''
if [ $# != 1 ]; then
echo "Usage: $0 <file.ttf>: Resets timestamp on <file.ttf> for determinism" >&2
exit 1
fi
ttf_file="$1"
ttx_file=$(dirname "$ttf_file")/$(basename "$ttf_file" .ttf).ttx
ttx "$ttf_file"
rm "$ttf_file"
touch -m -t ${builtins.replaceStrings [ "-" ] [ "" ] releaseDate}0000 "$ttx_file"
ttx --recalc-timestamp "$ttx_file"
rm "$ttx_file"
'';
};
in ''
find $out/Input_Fonts -type f -name '*.ttf' -print0 | ${lib.getExe parallel} -0 -j $NIX_BUILD_CORES ${lib.getExe ttf-fixup} {}
'';
};