about summary refs log tree commit diff
path: root/nixpkgs/pkgs/data/fonts/openmoji/default.nix
blob: 3f19bbe91f3383f7661a1906d81a4d4cb8f4447b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
{ lib
, stdenvNoCC
, fetchFromGitHub
, nanoemoji
, python3Packages
, woff2
, xmlstarlet
  # available color formats: ["cbdt" "glyf_colr_0" "glyf_colr_1" "sbix" "picosvgz" "untouchedsvgz"]
  # available black formats: ["glyf"]
, fontFormats ? [ "glyf" "cbdt" "glyf_colr_0" "glyf_colr_1" ]
  # when at least one of the glyf_colr_0/1 formats is specified, whether to build maximum color fonts
  # "none" to not build any, "svg" to build colr+svg, "bitmap" to build cbdt+colr+svg fonts
, buildMaximumColorFonts ? "bitmap"
}:
let
  # all available methods
  methods = {
    black = [ "glyf" ];
    color = [ "cbdt" "glyf_colr_0" "glyf_colr_1" "sbix" "picosvgz" "untouchedsvgz" ];
  };
in

assert lib.asserts.assertEachOneOf "fontFormats" fontFormats (methods.black ++ methods.color);
assert lib.asserts.assertOneOf "buildMaximumColorFonts" buildMaximumColorFonts [ "none" "bitmap" "svg" ];

stdenvNoCC.mkDerivation rec {
  pname = "openmoji";
  version = "15.0.0";

  src = fetchFromGitHub {
    owner = "hfg-gmuend";
    repo = pname;
    rev = version;
    hash = "sha256-659ONkHU45Z2789ay0yLero9j5nFWhslpJad++4oNN8=";
  };

  patches = [
    # fix paths and variables for nix build and skip generating font demos
    ./build.patch
  ];

  nativeBuildInputs = [
    nanoemoji
    python3Packages.fonttools
    woff2
    xmlstarlet
  ];

  methods_black = builtins.filter (m: builtins.elem m fontFormats) methods.black;
  methods_color = builtins.filter (m: builtins.elem m fontFormats) methods.color;
  saturations = lib.optional (methods_black != [ ]) "black" ++ lib.optional (methods_color != [ ]) "color";
  maximumColorVersions = lib.optionals (buildMaximumColorFonts != "none") (
    lib.optional (builtins.elem "glyf_colr_0" fontFormats) "0"
    ++ lib.optional (builtins.elem "glyf_colr_1" fontFormats) "1"
  );

  postPatch = lib.optionalString (buildMaximumColorFonts == "bitmap") ''
    substituteInPlace helpers/generate-fonts-runner.sh \
      --replace 'maximum_color' 'maximum_color --bitmaps'
  '';

  buildPhase = ''
    runHook preBuild

    bash helpers/generate-fonts-runner.sh "$(pwd)/build" "${version}"

    runHook postBuild
  '';

  installPhase = ''
    runHook preInstall

    mkdir -p $out/share/fonts/truetype $out/share/fonts/woff2
    cp build/fonts/*/*.ttf $out/share/fonts/truetype/
    cp build/fonts/*/*.woff2 $out/share/fonts/woff2/

    runHook postInstall
  '';

  meta = with lib; {
    license = licenses.cc-by-sa-40;
    maintainers = with maintainers; [ _999eagle fgaz ];
    platforms = platforms.all;
    homepage = "https://openmoji.org/";
    downloadPage = "https://github.com/hfg-gmuend/openmoji/releases";
    description = "Open-source emojis for designers, developers and everyone else";
  };
}