Add new dir argument to simplify fonts with many files
This commit is contained in:
parent
2374bc2ad6
commit
e8f9a41e35
23
flake.nix
23
flake.nix
|
@ -22,8 +22,13 @@
|
||||||
sLen = stringLength str;
|
sLen = stringLength str;
|
||||||
in sufLen <= sLen && suffix == substring (sLen - sufLen) sufLen str;
|
in sufLen <= sLen && suffix == substring (sLen - sufLen) sufLen str;
|
||||||
|
|
||||||
buildFont = { name, files, license, author, }:
|
buildFont = { name, files ? [ ], dir ? null, license, author }:
|
||||||
let
|
let
|
||||||
|
types = {
|
||||||
|
ttf = "truetype";
|
||||||
|
otf = "opentype";
|
||||||
|
};
|
||||||
|
|
||||||
copyType = extension: pathName:
|
copyType = extension: pathName:
|
||||||
let
|
let
|
||||||
filteredFiles = filter (pathEndsWith ("." + extension)) files;
|
filteredFiles = filter (pathEndsWith ("." + extension)) files;
|
||||||
|
@ -34,14 +39,19 @@
|
||||||
'') + concatStringsSep "\n" (map (file:
|
'') + concatStringsSep "\n" (map (file:
|
||||||
"cp -v ${file} $out/share/fonts/${pathName}/${filename file}")
|
"cp -v ${file} $out/share/fonts/${pathName}/${filename file}")
|
||||||
filteredFiles);
|
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 {
|
in pkgs.stdenvNoCC.mkDerivation {
|
||||||
inherit name;
|
inherit name;
|
||||||
|
|
||||||
dontUnpack = true;
|
dontUnpack = true;
|
||||||
installPhase = ''
|
installPhase = mapAttrsToList copyType types
|
||||||
${copyType "ttf" "truetype"}
|
++ optional (dir != null) (mapAttrsToList copyTypeDir types);
|
||||||
${copyType "otf" "opentype"}
|
|
||||||
'';
|
|
||||||
|
|
||||||
meta = {
|
meta = {
|
||||||
inherit license;
|
inherit license;
|
||||||
|
@ -59,8 +69,7 @@
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
name = "gg sans";
|
name = "gg sans";
|
||||||
files =
|
dir = ./ggsans;
|
||||||
[ ./ggsans/ggsans-Normal.ttf ./ggsans/ggsans-Medium.ttf ./ggsans/ggsans-SemiBold.ttf ];
|
|
||||||
license = licenses.unfree;
|
license = licenses.unfree;
|
||||||
author = "Colophon Foundry";
|
author = "Colophon Foundry";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue