smc-fonts-flake/default.nix

77 lines
2.4 KiB
Nix
Raw Normal View History

2024-10-13 17:17:19 +00:00
{ stdenv, fetchzip, lib
# To select only certain fonts, put a list of strings to `fonts`: every key in
# ./shas.nix is an optional font
, fonts ? [ ] }:
2024-07-26 23:58:36 +00:00
2024-10-13 17:17:19 +00:00
let
version = "version-20241013";
fontsShas = import ./shas.nix;
knownFonts = builtins.attrNames fontsShas;
selectedFonts = if (fonts == [ ]) then
knownFonts
else
let unknown = lib.subtractLists knownFonts fonts;
in if (unknown != [ ]) then
throw "Unknown font(s): ${lib.concatStringsSep " " unknown}"
else
fonts;
# Filter the fonts by selectedFonts list
filteredFonts =
builtins.filter (fontName: builtins.elem fontName selectedFonts)
(builtins.attrNames fontsShas);
# Function to generate a list of srcs that look like
# [
# (fetchurl {
2024-10-13 17:33:49 +00:00
# name = "namezzxs"
2024-10-13 17:17:19 +00:00
# url = "";
# sha256 = "sha256-abc123...";
# })
# (fetchurl {
2024-10-13 17:33:49 +00:00
# name = "namezzxy"
2024-10-13 17:17:19 +00:00
# url = "";
# sha256 = "sha256-def456...";
# })
# ]
generateUrls = fontAttrs: fontName:
builtins.map (variant:
let sha = fontAttrs.${variant};
in fetchzip {
2024-10-13 17:33:49 +00:00
name = "${fontName}-${variant}";
2024-10-13 17:17:19 +00:00
url = "https://smc.org.in/downloads/fonts/${fontName}/${variant}.zip";
sha256 = sha;
stripRoot = false;
}) (builtins.attrNames fontAttrs);
# Generate srcs for the filtered fonts
srcs = builtins.concatLists
(builtins.map (fontName: generateUrls fontsShas.${fontName} fontName)
filteredFonts);
in stdenv.mkDerivation (finalAttrs: {
inherit version;
inherit srcs;
pname = "smc-fonts";
2024-10-13 17:33:49 +00:00
sourceRoot = ".";
2024-10-13 17:17:19 +00:00
buildPhase = ''
echo "selected fonts are ${toString selectedFonts}"
ls *.otf *.ttf
'';
installPhase = ''
2024-10-13 17:33:49 +00:00
find -name \*.otf -exec mkdir -p $out/share/fonts/opentype/SMCFonts \; -exec mv {} $out/share/fonts/opentype/SMCFonts \;
find -name \*.ttf -exec mkdir -p $out/share/fonts/truetype/SMCFonts \; -exec mv {} $out/share/fonts/truetype/SMCFonts \;
2024-10-13 17:17:19 +00:00
'';
meta = with lib; {
2024-10-13 20:50:28 +00:00
description = "Malayalam typefaces made by smc.org.in";
2024-10-13 17:17:19 +00:00
longDescription = ''
2024-10-13 20:50:28 +00:00
Swathanthra Malayalam Computing (SMC) is a free software collective engaged in the development, localization, standardization and popularization of various Free and Open Source Software in the Malayalam language. This derivation builds all fonts made by SMC.
2024-10-13 17:17:19 +00:00
'';
homepage = "https://smc.org.in/";
license = licenses.ofl;
platforms = platforms.all;
maintainers = with maintainers; [ aashiks ];
};
})