Get filename from metadata, add gg sans

This commit is contained in:
Artemis Tosini 2023-09-10 04:34:58 +00:00
parent ecdb1288eb
commit 4013f8df73
Signed by: artemist
GPG key ID: EE5227935FE3FF18
4 changed files with 28 additions and 14 deletions

View file

@ -13,13 +13,11 @@
with builtins; with builtins;
with nixpkgs.lib; with nixpkgs.lib;
flake-utils.lib.eachDefaultSystem (system: let flake-utils.lib.eachDefaultSystem (system: let
pkgs = import nixpkgs {inherit system;}; pkgs = import nixpkgs {
buildFont = { inherit system;
name, config.allowUnfree = true;
files, };
license,
author,
}: let
pathEndsWith = suffix: path: let pathEndsWith = suffix: path: let
str = toString path; str = toString path;
sufLen = stringLength suffix; sufLen = stringLength suffix;
@ -27,20 +25,30 @@
in in
sufLen <= sLen && suffix == substring (sLen - sufLen) sufLen str; sufLen <= sLen && suffix == substring (sLen - sufLen) sufLen str;
installType = extension: pathName: let buildFont = {
name,
files,
license,
author,
}: let
copyType = extension: pathName: let
filteredFiles = filter (pathEndsWith ("." + extension)) files; filteredFiles = filter (pathEndsWith ("." + extension)) files;
filename = file: lists.last (strings.splitString "/" (toString file));
in in
(optionalString (filteredFiles != []) "mkdir -p $out/share/fonts/${pathName}\n") (optionalString (filteredFiles != []) "mkdir -p $out/share/fonts/${pathName}\n")
+ concatStringsSep "\n" (map (file: "cp -v ${file} $out/share/fonts/${pathName}/${filename file}") filteredFiles); + concatStringsSep "\n" (map (file: ''
filename=$(${pkgs.fontconfig}/bin/fc-query -f %{postscriptname} ${file}).${extension}
cp -v ${file} $out/share/fonts/${pathName}/$filename
'')
filteredFiles);
in in
pkgs.stdenvNoCC.mkDerivation { pkgs.stdenvNoCC.mkDerivation {
inherit name; inherit name;
dontUnpack = true; dontUnpack = true;
installPhase = '' installPhase = ''
${installType "ttf" "truetype"} ${copyType "ttf" "truetype"}
${installType "otf" "opentype"} ${copyType "otf" "opentype"}
${copyType "woff2" "woff2"}
''; '';
meta = { meta = {
@ -57,10 +65,16 @@
license = licenses.cc-by-40; license = licenses.cc-by-40;
author = "Matthew Anderson"; author = "Matthew Anderson";
} }
{
name = "gg sans";
files = [./ggsans-Normal.woff2 ./ggsans-Medium.woff2 ./ggsans-SemiBold.woff2];
license = licenses.unfree;
author = "Colophon Foundry";
}
]; ];
in { in {
packages = listToAttrs (map (font: { packages = listToAttrs (map (font: {
name = toLower font.name; name = replaceStrings [" "] ["-"] (toLower font.name);
value = buildFont font; value = buildFont font;
}) })
fonts); fonts);

BIN
ggsans-Medium.woff2 Normal file

Binary file not shown.

BIN
ggsans-Normal.woff2 Normal file

Binary file not shown.

BIN
ggsans-SemiBold.woff2 Normal file

Binary file not shown.