fonts/flake.nix

202 lines
6.8 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";
artemist = {
url = "git+https://git.mildlyfunctional.gay/artemist/packages.git";
inputs.utils.follows = "flake-utils";
inputs.nixpkgs.follows = "nixpkgs";
};
2023-09-10 02:59:56 +00:00
};
outputs = { self, nixpkgs, flake-utils, artemist }:
2023-09-10 02:59:56 +00:00
with nixpkgs.lib;
2023-12-18 03:55:26 +00:00
{
overlays.default = (final: prev:
let
localFonts = [
{
# Popular font, used on NYC Subway
name = "Akzidenz-Grotesk Pro";
dir = ./Akzidenz-Grotesk-Pro;
license = licenses.unfree;
author = "Berthold Type Foundry";
}
2024-07-15 19:20:39 +00:00
{
# Font used on DSB departure boards
name = "AtB";
dir = ./AtB;
license = licenses.unfree;
author = "Kontrapunkt";
}
{
# Brussels-specific font
name = "Brusseline";
dir = ./Brusseline;
license = licenses.unfree;
author = "Eric de Berranger";
}
2023-12-18 03:55:26 +00:00
{
# Free handwriting font
name = "Caveat";
files = [ ./Caveat.ttf ];
license = licenses.ofl;
author = "Pablo Impallari and Alexi Vanyashin";
}
2023-12-18 20:39:02 +00:00
{
# Twitter custom font, based on GT America
name = "Chirp";
dir = ./Chirp;
license = licenses.unfree;
author = "Grilli Type Foundry";
}
2023-12-18 03:55:26 +00:00
{
# Deutsche Bahn website font
name = "DB Screen";
dir = ./DB-Screen;
license = licenses.unfree;
author = "URW Type Foundry";
}
2024-02-09 19:51:14 +00:00
{
# Font with a large number of invented scripts
name = "Fairfax HD";
dir = ./Fairfax-HD;
license = licenses.ofl;
author = "Kreative Software";
}
2023-12-18 03:55:26 +00:00
{
# Popular font, used on Amtrak
name = "Frutiger";
dir = ./Frutiger;
license = licenses.unfree;
author = "Adrian Frutiger";
}
{
# Discord custom font
name = "gg sans";
dir = ./ggsans;
license = licenses.unfree;
author = "Colophon Foundry";
}
2024-07-15 19:20:39 +00:00
{
# Several related fonts used for London Underground:
# * Johnston 100: Extension of original Johnston
# * New Johnston: Modification of original Johnston
# * P22 Underground: Version sold to public
name = "Johnston";
dir = ./Johnston;
license = licenses.unfree;
author = "Edward Johnston et al";
}
{
# Mysterious all-uppercase hand-style font for MIVB/STIB
name = "MIVB STIB";
dir = ./MIVB;
license = licenses.unfree;
author = "unknown";
}
2023-12-18 03:55:26 +00:00
{
# Also called "NR Brunel, used on UK railways in 2010s
name = "New Brunel";
dir = ./New-Brunel;
license = licenses.unfree;
author = "David Quay";
}
{
# Modern expansion of machine-readable font
name = "OCR-B";
files = [ ./OCR-B-Regular.otf ];
license = licenses.cc-by-40;
author = "Matthew Anderson";
}
{
2024-07-15 19:20:39 +00:00
# Custom font used for RATP services in Parism
name = "Parisine";
dir = ./Parisine;
license = licenses.unfree;
author = "Jean-François Porchez";
}
{
# Font used on DSB website, similar to signage
name = "Via";
dir = ./Via;
2023-12-18 03:55:26 +00:00
license = licenses.unfree;
2024-07-15 19:20:39 +00:00
author = "Kontrapunkt";
2023-12-18 03:55:26 +00:00
}
];
buildLocalFont = { name, files ? [ ], dir ? null, license, author }:
let
types = {
ttf = "truetype";
otf = "opentype";
};
2023-12-18 03:55:26 +00:00
pathEndsWith = suffix: path:
let
str = toString path;
sufLen = stringLength suffix;
sLen = stringLength str;
in sufLen <= sLen && suffix
== substring (sLen - sufLen) sufLen str;
2023-12-18 03:55:26 +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);
2023-09-10 02:59:56 +00:00
2023-12-18 03:55:26 +00:00
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-09-10 02:59:56 +00:00
2023-12-18 03:55:26 +00:00
in final.stdenvNoCC.mkDerivation {
inherit name;
dontUnpack = true;
installPhase = mapAttrsToList copyType types
++ optional (dir != null) (mapAttrsToList copyTypeDir types);
2023-12-19 07:45:49 +00:00
passthru.font = true;
2023-12-18 03:55:26 +00:00
meta = {
inherit license;
platforms = platforms.all;
maintainers = [ maintainers.artemist ];
2023-12-18 03:55:26 +00:00
description = "${name} font by ${author}";
};
2023-09-10 02:59:56 +00:00
};
2023-12-18 03:55:26 +00:00
in {
extraFonts = listToAttrs (map (font: {
name = replaceStrings [ " " ] [ "-" ] (toLower font.name);
value = buildLocalFont font;
}) localFonts);
appleFonts = final.callPackage ./apple {
ipsw = if final ? ipsw then final.ipsw else artemist.packages.${final.stdenv.system}.ipsw;
};
2023-12-18 03:55:26 +00:00
});
} // flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ self.overlays.default artemist.overlays.default ];
2023-12-18 03:55:26 +00:00
config.allowUnfree = true;
};
2023-09-10 02:59:56 +00:00
in {
packages = builtins.listToAttrs (map (name: {
inherit name;
value = pkgs.${name} // {
type = "derivation";
name = "dummy-attrset";
};
}) [ "extraFonts" "appleFonts" ]);
2023-12-17 19:19:46 +00:00
formatter = pkgs.nixfmt;
2023-09-10 02:59:56 +00:00
});
}