flake: Add overlay

This commit is contained in:
Artemis Tosini 2023-12-18 03:55:26 +00:00
parent e98f4ef83b
commit 8b4185445f
Signed by: artemist
GPG key ID: ADFFE553DCBB831E

119
flake.nix
View file

@ -6,61 +6,11 @@
}; };
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 let
pkgs = import nixpkgs { localFonts = [
inherit system;
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 # Popular font, used on NYC Subway
name = "Akzidenz-Grotesk Pro"; name = "Akzidenz-Grotesk Pro";
@ -118,12 +68,65 @@
author = "P22 Type Foundry"; author = "P22 Type Foundry";
} }
]; ];
in { buildLocalFont = { name, files ? [ ], dir ? null, license, author }:
packages = listToAttrs (map (font: { let
name = replaceStrings [ " " ] [ "-" ] (toLower font.name); types = {
value = buildFont font; ttf = "truetype";
}) fonts); 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
pkgs = import nixpkgs {
inherit system;
overlays = [ self.overlays.default ];
config.allowUnfree = true;
};
in {
packages = pkgs.extraFonts;
formatter = pkgs.nixfmt; formatter = pkgs.nixfmt;
}); });
} }