From e8f9a41e351bad1c4918313466570317c416b7b5 Mon Sep 17 00:00:00 2001 From: Artemis Tosini Date: Sun, 17 Dec 2023 20:12:02 +0000 Subject: [PATCH] Add new dir argument to simplify fonts with many files --- flake.nix | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/flake.nix b/flake.nix index 0a6abe8..1a4cb37 100644 --- a/flake.nix +++ b/flake.nix @@ -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"; }