about summary refs log tree commit diff
path: root/pkgs/development/libraries/fontconfig/make-fonts-conf.nix
blob: 669b66267f879ca627ba0cb6653c460025b0ba38 (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
{ runCommand, stdenv, lib, libxslt, fontconfig, dejavu_fonts }:

let fontconfig_ = fontconfig; in
{
  fontconfig ? fontconfig_
  # an array of fonts, e.g. `[ pkgs.dejavu_fonts.minimal ]`
  ,  fontDirectories
  , impureFontDirectories ? [
    # nix user profile
    "~/.nix-profile/lib/X11/fonts" "~/.nix-profile/share/fonts"
  ]
  ++ lib.optional stdenv.hostPlatform.isDarwin "~/Library/Fonts"
  ++ [
    # FHS paths for non-NixOS platforms
    "/usr/share/fonts" "/usr/local/share/fonts"
  ]
  # darwin paths
  ++ lib.optionals stdenv.hostPlatform.isDarwin [ "/Library/Fonts" "/System/Library/Fonts" ]
  # nix default profile
  ++ [ "/nix/var/nix/profiles/default/lib/X11/fonts" "/nix/var/nix/profiles/default/share/fonts" ]

  # to include custom config
  , includes ? ["/etc/fonts/conf.d"]
}:

runCommand "fonts.conf"
  {
    nativeBuildInputs = [ libxslt ];
    buildInputs = [ fontconfig ];
    inherit fontDirectories includes;
    # Add a default font for non-nixos systems, <1MB and in nixos defaults.
    impureFontDirectories = impureFontDirectories ++ [ dejavu_fonts.minimal ];
  }
  ''
    xsltproc --stringparam fontDirectories "$fontDirectories" \
      --stringparam impureFontDirectories "$impureFontDirectories" \
      --stringparam includes "$includes" \
      --path ${fontconfig.out}/share/xml/fontconfig \
      ${./make-fonts-conf.xsl} ${fontconfig.out}/etc/fonts/fonts.conf \
      > $out
  ''