Add new dir argument to simplify fonts with many files

This commit is contained in:
Artemis Tosini 2023-12-17 20:12:02 +00:00
parent 2374bc2ad6
commit e8f9a41e35
Signed by: artemist
GPG key ID: EE5227935FE3FF18

View file

@ -22,8 +22,13 @@
sLen = stringLength str;
in sufLen <= sLen && suffix == substring (sLen - sufLen) sufLen str;
buildFont = { name, files, license, author, }:
buildFont = { name, files ? [ ], dir ? null, license, author }:
let
types = {
ttf = "truetype";
otf = "opentype";
};
copyType = extension: pathName:
let
filteredFiles = filter (pathEndsWith ("." + extension)) files;
@ -34,14 +39,19 @@
'') + concatStringsSep "\n" (map (file:
"cp -v ${file} $out/share/fonts/${pathName}/${filename file}")
filteredFiles);
copyTypeDir = extension: pathName: ''
if [ -n "$(shopt -s nullglob; echo ${dir}/*.${extension})" ]; then
mkdir -p $out/share/fonts/${pathName}
cp -v -t $out/share/fonts/${pathName} ${dir}/*.${extension}
fi
'';
in pkgs.stdenvNoCC.mkDerivation {
inherit name;
dontUnpack = true;
installPhase = ''
${copyType "ttf" "truetype"}
${copyType "otf" "opentype"}
'';
installPhase = mapAttrsToList copyType types
++ optional (dir != null) (mapAttrsToList copyTypeDir types);
meta = {
inherit license;
@ -59,8 +69,7 @@
}
{
name = "gg sans";
files =
[ ./ggsans/ggsans-Normal.ttf ./ggsans/ggsans-Medium.ttf ./ggsans/ggsans-SemiBold.ttf ];
dir = ./ggsans;
license = licenses.unfree;
author = "Colophon Foundry";
}