monaspace: refactor variants into separate packages (#452315)

This commit is contained in:
Pol Dellaiera
2025-12-02 06:45:28 +00:00
committed by GitHub
2 changed files with 109 additions and 32 deletions
+38
View File
@@ -0,0 +1,38 @@
version = "1.301"
baseUrl = "https://github.com/githubnext/monaspace/releases/download"
fontFamily = "monaspace"
[[fonts]]
hash = "sha256-/A5/zipWaaSpTGUBVZOE0EihJY9tu0JAH+6+gyHbDxo="
variant = "static"
destination = "opentype"
[[fonts]]
hash = "sha256-7O0qRA12ELPNs4919aW5rUdLs/XaLTJNthL+4Gjlx90="
variant = "frozen"
destination = "truetype"
[[fonts]]
hash = "sha256-cPAQBgrxIFXRjBRK9kvt3uYwewi5Lw/ryiwjUeVJWD4="
variant = "variable"
destination = "truetype"
[[fonts]]
hash = "sha256-3/JOe+aSSA2vxnKHjSwkxukqNYMajsIuQ68IJvY07XI="
variant = "nerdfonts"
destination = "opentype"
[[fonts]]
hash = "sha256-1VtGSqDSRaVfyCWP+ZQtiji/076JdZmRSI0nlzqcuHo="
variant = "webfont-nerdfonts"
destination = "woff"
[[fonts]]
hash = "sha256-mlK1kCun8/rUsDpNh3+dD+mDqvNdCMdIe8u9Y8ORhJ0="
variant = "webfont-static"
destination = "woff"
[[fonts]]
hash = "sha256-aHLPmQzPiA8HQFsz9u6UH0b8kINx/fQ74GcPDs+a1ys="
variant = "webfont-variable"
destination = "woff"
+71 -32
View File
@@ -1,38 +1,11 @@
{
lib,
fetchzip,
stdenvNoCC,
fetchFromGitHub,
symlinkJoin,
}:
stdenvNoCC.mkDerivation (finalAttrs: {
pname = "monaspace";
version = "1.301";
src = fetchFromGitHub {
owner = "githubnext";
repo = "monaspace";
tag = "v${finalAttrs.version}";
hash = "sha256-8tPwm92ZtaXL9qeDL+ay9PdXLUBBsspdk7/0U8VO0Tg=";
};
outputs = [
"out"
"woff"
];
installPhase = ''
# Install TrueType fonts
install -Dm644 -t $out/share/fonts/truetype fonts/Frozen\ Fonts/*/*.ttf
install -Dm644 -t $out/share/fonts/truetype fonts/Variable\ Fonts/*/*.ttf
# Install OpenType fonts
install -Dm644 -t $out/share/fonts/opentype fonts/Static\ Fonts/*/*.otf
install -Dm644 -t $out/share/fonts/opentype fonts/NerdFonts/*/*.otf
# Install Web fonts
install -Dm644 -t $woff/share/fonts/woff fonts/Web\ Fonts/*/*/*.woff
install -Dm644 -t $woff/share/fonts/woff fonts/Web\ Fonts/*/*/*.woff2
'';
let
fonts = lib.importTOML ./fonts.toml;
meta = {
description = "Innovative superfamily of fonts for code";
@@ -60,4 +33,70 @@ stdenvNoCC.mkDerivation (finalAttrs: {
maintainers = [ ];
platforms = lib.platforms.all;
};
})
makeFont =
{
pname,
fontFamily,
variant,
version,
baseUrl,
hash,
destination,
meta,
}:
stdenvNoCC.mkDerivation {
inherit pname version;
src = fetchzip {
url = "${baseUrl}/v${version}/${fontFamily}-${variant}-v${version}.zip";
inherit hash;
};
installPhase = ''
runHook preInstall
mkdir -p "$out/share/fonts/${destination}"
find . -type f \( -name "*.otf" -o -name "*.ttf" -o -name "*.woff" \) -exec install -Dm644 {} $out/share/fonts/${destination} \;
runHook postInstall
'';
inherit meta;
};
makePackages =
filteredFonts:
lib.listToAttrs (
map (
font:
let
fontAttrs = rec {
inherit (fonts) baseUrl fontFamily version;
inherit (font) variant hash destination;
inherit meta;
pname = fontFamily + "-" + variant;
};
in
{
name = fontAttrs.variant;
value = makeFont fontAttrs;
}
) filteredFonts
);
allFonts = makePackages fonts.fonts;
woffFonts = makePackages (builtins.filter (f: f.destination == "woff") fonts.fonts);
defaultFonts = lib.removeAttrs allFonts (builtins.attrNames woffFonts);
in
symlinkJoin {
pname = "monaspace";
inherit (fonts) version;
paths = builtins.attrValues defaultFonts;
passthru = allFonts // {
woff = symlinkJoin {
pname = "monaspace-webfonts";
inherit (fonts) version;
paths = builtins.attrValues woffFonts;
};
};
inherit meta;
}