fonts/flake.nix

130 lines
4 KiB
Nix
Raw Normal View History

2023-09-10 02:59:56 +00:00
{
description = "Various fonts I've found online";
inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:nixos/nixpkgs";
};
2023-12-17 19:19:46 +00:00
outputs = { self, nixpkgs, flake-utils, }:
2023-09-10 02:59:56 +00:00
with builtins;
with nixpkgs.lib;
2023-12-17 19:19:46 +00:00
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
config.allowUnfree = true;
};
2023-12-17 19:19:46 +00:00
pathEndsWith = suffix: path:
let
str = toString path;
sufLen = stringLength suffix;
sLen = stringLength str;
in sufLen <= sLen && suffix == substring (sLen - sufLen) sufLen str;
buildFont = { name, files ? [ ], dir ? null, license, author }:
2023-12-17 19:19:46 +00:00
let
types = {
ttf = "truetype";
otf = "opentype";
};
2023-12-17 19:19:46 +00:00
copyType = extension: pathName:
let
filteredFiles = filter (pathEndsWith ("." + extension)) files;
filename = file:
lists.last (strings.splitString "/" (toString file));
in (optionalString (filteredFiles != [ ]) ''
mkdir -p $out/share/fonts/${pathName}
'') + 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
'';
2023-12-17 19:19:46 +00:00
in pkgs.stdenvNoCC.mkDerivation {
2023-09-10 02:59:56 +00:00
inherit name;
dontUnpack = true;
installPhase = mapAttrsToList copyType types
++ optional (dir != null) (mapAttrsToList copyTypeDir types);
2023-09-10 02:59:56 +00:00
meta = {
inherit license;
platforms = platforms.all;
description = "${name} font by ${author}";
};
};
fonts = [
{
2023-12-17 22:06:20 +00:00
# Popular font, used on NYC Subway
2023-12-17 21:06:09 +00:00
name = "Akzidenz-Grotesk Pro";
dir = ./Akzidenz-Grotesk-Pro;
license = licenses.unfree;
author = "Berthold Type Foundry";
}
{
2023-12-17 22:06:20 +00:00
# Free handwriting font
2023-12-17 21:06:09 +00:00
name = "Caveat";
files = [ ./Caveat.ttf ];
license = licenses.ofl;
author = "Pablo Impallari and Alexi Vanyashin";
2023-09-10 02:59:56 +00:00
}
2023-12-18 01:41:32 +00:00
{
# Deutsche Bahn website font
name = "DB Screen";
dir = ./DB-Screen;
license = licenses.unfree;
author = "URW Type Foundry";
}
2023-12-17 22:03:50 +00:00
{
2023-12-17 22:06:20 +00:00
# Popular font, used on Amtrak
2023-12-17 22:03:50 +00:00
name = "Frutiger";
dir = ./Frutiger;
license = licenses.unfree;
author = "Adrian Frutiger";
}
{
2023-12-17 22:06:20 +00:00
# Discord custom font
name = "gg sans";
dir = ./ggsans;
license = licenses.unfree;
author = "Colophon Foundry";
}
2023-12-17 22:04:20 +00:00
{
# Also called "NR Brunel, used on UK railways in 2010s
name = "New Brunel";
dir = ./New-Brunel;
license = licenses.unfree;
author = "David Quay";
}
2023-12-17 21:06:09 +00:00
{
2023-12-17 22:06:20 +00:00
# Modern expansion of machine-readable font
2023-12-17 21:06:09 +00:00
name = "OCR-B";
files = [ ./OCR-B-Regular.otf ];
license = licenses.cc-by-40;
author = "Matthew Anderson";
}
2023-12-17 20:17:08 +00:00
{
2023-12-17 22:06:20 +00:00
# Modern expansion of Johnston Sans, used on London Underground
2023-12-17 20:17:08 +00:00
name = "P22 Underground";
dir = ./P22-Underground;
license = licenses.unfree;
author = "P22 Type Foundry";
}
2023-09-10 02:59:56 +00:00
];
in {
packages = listToAttrs (map (font: {
2023-12-17 19:19:46 +00:00
name = replaceStrings [ " " ] [ "-" ] (toLower font.name);
value = buildFont font;
}) fonts);
2023-09-10 02:59:56 +00:00
2023-12-17 19:19:46 +00:00
formatter = pkgs.nixfmt;
2023-09-10 02:59:56 +00:00
});
}