flake: Add overlay
This commit is contained in:
parent
e98f4ef83b
commit
8b4185445f
225
flake.nix
225
flake.nix
|
@ -6,124 +6,127 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = { self, nixpkgs, flake-utils, }:
|
outputs = { self, nixpkgs, flake-utils, }:
|
||||||
with builtins;
|
|
||||||
with nixpkgs.lib;
|
with nixpkgs.lib;
|
||||||
flake-utils.lib.eachDefaultSystem (system:
|
{
|
||||||
|
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";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
# Free handwriting font
|
||||||
|
name = "Caveat";
|
||||||
|
files = [ ./Caveat.ttf ];
|
||||||
|
license = licenses.ofl;
|
||||||
|
author = "Pablo Impallari and Alexi Vanyashin";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
# Deutsche Bahn website font
|
||||||
|
name = "DB Screen";
|
||||||
|
dir = ./DB-Screen;
|
||||||
|
license = licenses.unfree;
|
||||||
|
author = "URW Type Foundry";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
# 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";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
# 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";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
# Modern expansion of Johnston Sans, used on London Underground
|
||||||
|
name = "P22 Underground";
|
||||||
|
dir = ./P22-Underground;
|
||||||
|
license = licenses.unfree;
|
||||||
|
author = "P22 Type Foundry";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
buildLocalFont = { name, files ? [ ], dir ? null, license, author }:
|
||||||
|
let
|
||||||
|
types = {
|
||||||
|
ttf = "truetype";
|
||||||
|
otf = "opentype";
|
||||||
|
};
|
||||||
|
|
||||||
|
pathEndsWith = suffix: path:
|
||||||
|
let
|
||||||
|
str = toString path;
|
||||||
|
sufLen = stringLength suffix;
|
||||||
|
sLen = stringLength str;
|
||||||
|
in sufLen <= sLen && suffix
|
||||||
|
== substring (sLen - sufLen) sufLen str;
|
||||||
|
|
||||||
|
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
|
||||||
|
'';
|
||||||
|
|
||||||
|
in final.stdenvNoCC.mkDerivation {
|
||||||
|
inherit name;
|
||||||
|
dontUnpack = true;
|
||||||
|
installPhase = mapAttrsToList copyType types
|
||||||
|
++ optional (dir != null) (mapAttrsToList copyTypeDir types);
|
||||||
|
meta = {
|
||||||
|
inherit license;
|
||||||
|
platforms = platforms.all;
|
||||||
|
description = "${name} font by ${author}";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
in {
|
||||||
|
extraFonts = listToAttrs (map (font: {
|
||||||
|
name = replaceStrings [ " " ] [ "-" ] (toLower font.name);
|
||||||
|
value = buildLocalFont font;
|
||||||
|
}) localFonts);
|
||||||
|
});
|
||||||
|
} // flake-utils.lib.eachDefaultSystem (system:
|
||||||
let
|
let
|
||||||
pkgs = import nixpkgs {
|
pkgs = import nixpkgs {
|
||||||
inherit system;
|
inherit system;
|
||||||
|
overlays = [ self.overlays.default ];
|
||||||
config.allowUnfree = true;
|
config.allowUnfree = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
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 }:
|
|
||||||
let
|
|
||||||
types = {
|
|
||||||
ttf = "truetype";
|
|
||||||
otf = "opentype";
|
|
||||||
};
|
|
||||||
|
|
||||||
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
|
|
||||||
'';
|
|
||||||
in pkgs.stdenvNoCC.mkDerivation {
|
|
||||||
inherit name;
|
|
||||||
|
|
||||||
dontUnpack = true;
|
|
||||||
installPhase = mapAttrsToList copyType types
|
|
||||||
++ optional (dir != null) (mapAttrsToList copyTypeDir types);
|
|
||||||
|
|
||||||
meta = {
|
|
||||||
inherit license;
|
|
||||||
platforms = platforms.all;
|
|
||||||
description = "${name} font by ${author}";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
fonts = [
|
|
||||||
{
|
|
||||||
# Popular font, used on NYC Subway
|
|
||||||
name = "Akzidenz-Grotesk Pro";
|
|
||||||
dir = ./Akzidenz-Grotesk-Pro;
|
|
||||||
license = licenses.unfree;
|
|
||||||
author = "Berthold Type Foundry";
|
|
||||||
}
|
|
||||||
{
|
|
||||||
# Free handwriting font
|
|
||||||
name = "Caveat";
|
|
||||||
files = [ ./Caveat.ttf ];
|
|
||||||
license = licenses.ofl;
|
|
||||||
author = "Pablo Impallari and Alexi Vanyashin";
|
|
||||||
}
|
|
||||||
{
|
|
||||||
# Deutsche Bahn website font
|
|
||||||
name = "DB Screen";
|
|
||||||
dir = ./DB-Screen;
|
|
||||||
license = licenses.unfree;
|
|
||||||
author = "URW Type Foundry";
|
|
||||||
}
|
|
||||||
{
|
|
||||||
# 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";
|
|
||||||
}
|
|
||||||
{
|
|
||||||
# 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";
|
|
||||||
}
|
|
||||||
{
|
|
||||||
# Modern expansion of Johnston Sans, used on London Underground
|
|
||||||
name = "P22 Underground";
|
|
||||||
dir = ./P22-Underground;
|
|
||||||
license = licenses.unfree;
|
|
||||||
author = "P22 Type Foundry";
|
|
||||||
}
|
|
||||||
];
|
|
||||||
in {
|
in {
|
||||||
packages = listToAttrs (map (font: {
|
packages = pkgs.extraFonts;
|
||||||
name = replaceStrings [ " " ] [ "-" ] (toLower font.name);
|
|
||||||
value = buildFont font;
|
|
||||||
}) fonts);
|
|
||||||
|
|
||||||
formatter = pkgs.nixfmt;
|
formatter = pkgs.nixfmt;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue