nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{ lib
2, stdenvNoCC
3, fetchFromGitHub
4, fonts ? []
5}:
6
7stdenvNoCC.mkDerivation {
8 pname = "google-fonts";
9 version = "unstable-2022-11-14";
10
11 # Adobe Blank is split out in a separate output,
12 # because it causes crashes with `libfontconfig`.
13 # It has an absurd number of symbols
14 outputs = [ "out" "adobeBlank" ];
15
16 src = fetchFromGitHub {
17 owner = "google";
18 repo = "fonts";
19 rev = "83e116a566eda04a2469a11ee562cef1d7b33e4f";
20 sha256 = "sha256-sSabk+VWkoXj1Nzv9ufgIU/nkfKf4XkZU1SO+j+eSPA=";
21 };
22
23 postPatch = ''
24 # These directories need to be removed because they contain
25 # older or duplicate versions of fonts also present in other
26 # directories. This causes non-determinism in the install since
27 # the installation order of font files with the same name is not
28 # fixed.
29 rm -rv ofl/cabincondensed \
30 ofl/signikanegative \
31 ofl/signikanegativesc \
32 axisregistry/tests/data
33
34 if find . -name "*.ttf" | sed 's|.*/||' | sort | uniq -c | sort -n | grep -v '^.*1 '; then
35 echo "error: duplicate font names"
36 exit 1
37 fi
38 '';
39
40 dontBuild = true;
41
42 # The font files are in the fonts directory and use two naming schemes:
43 # FamilyName-StyleName.ttf and FamilyName[param1,param2,...].ttf
44 # This installs all fonts if fonts is empty and otherwise only
45 # the specified fonts by FamilyName. To do this, it invokes
46 # `find` 2 times for every font, anyone is free to do this
47 # in a more efficient way.
48 fonts = map (font: builtins.replaceStrings [" "] [""] font) fonts;
49 installPhase = ''
50 adobeBlankDest=$adobeBlank/share/fonts/truetype
51 install -m 444 -Dt $adobeBlankDest ofl/adobeblank/AdobeBlank-Regular.ttf
52 rm -r ofl/adobeblank
53 dest=$out/share/fonts/truetype
54 '' + (if fonts == [] then ''
55 find . -name '*.ttf' -exec install -m 444 -Dt $dest '{}' +
56 '' else ''
57 for font in $fonts; do
58 find . -name "$font-*.ttf" -exec install -m 444 -Dt $dest '{}' +
59 find . -name "$font[*.ttf" -exec install -m 444 -Dt $dest '{}' +
60 done
61 '');
62
63 meta = with lib; {
64 homepage = "https://fonts.google.com";
65 description = "Font files available from Google Fonts";
66 license = with licenses; [ asl20 ofl ufl ];
67 platforms = platforms.all;
68 hydraPlatforms = [];
69 maintainers = with maintainers; [ manveru ];
70 };
71}