1{ stdenv, substituteAll, fetchurl, fetchpatch
2, pkgconfig, freetype, expat, libxslt, dejavu_fonts
3, hostPlatform
4}:
5
6/** Font configuration scheme
7 - ./config-compat.patch makes fontconfig try the following root configs, in order:
8 $FONTCONFIG_FILE, /etc/fonts/${configVersion}/fonts.conf, /etc/fonts/fonts.conf
9 This is done not to override config of pre-2.11 versions (which just blow up)
10 and still use *global* font configuration at both NixOS or non-NixOS.
11 - NixOS creates /etc/fonts/${configVersion}/fonts.conf link to $out/etc/fonts/fonts.conf,
12 and other modifications should go to /etc/fonts/${configVersion}/conf.d
13 - See ./make-fonts-conf.xsl for config details.
14
15*/
16
17let
18 configVersion = "2.11"; # bump whenever fontconfig breaks compatibility with older configurations
19in
20stdenv.mkDerivation rec {
21 name = "fontconfig-2.12.1";
22
23 src = fetchurl {
24 url = "http://fontconfig.org/release/${name}.tar.bz2";
25 sha256 = "1wy7svvp7df6bjpg1m5vizb3ngd7rhb20vpclv3x3qa71khs6jdl";
26 };
27
28 patches = [
29 (substituteAll {
30 src = ./config-compat.patch;
31 inherit configVersion;
32 })
33 (fetchpatch {
34 name = "glibc-2.25.diff";
35 url = "https://cgit.freedesktop.org/fontconfig/patch/?id=1ab5258f7c";
36 sha256 = "0x2a4qx51j3gqcp1kp4lisdzmhrkw1zw0r851d82ksgjlc0vkbaz";
37 })
38 ];
39 # additionally required for the glibc-2.25 patch; avoid requiring gperf
40 postPatch = ''
41 sed s/CHAR_WIDTH/CHARWIDTH/g -i src/fcobjshash.{h,gperf}
42 touch src/*
43 '';
44
45 outputs = [ "bin" "dev" "lib" "out" ]; # $out contains all the config
46
47 propagatedBuildInputs = [ freetype ];
48 nativeBuildInputs = [ pkgconfig ];
49 buildInputs = [ expat ];
50
51 configureFlags = [
52 "--with-cache-dir=/var/cache/fontconfig" # otherwise the fallback is in $out/
53 "--disable-docs"
54 # just <1MB; this is what you get when loading config fails for some reason
55 "--with-default-fonts=${dejavu_fonts.minimal}"
56 ];
57
58 # We should find a better way to access the arch reliably.
59 crossArch = hostPlatform.arch or null;
60
61 preConfigure = ''
62 if test -n "$crossConfig"; then
63 configureFlags="$configureFlags --with-arch=$crossArch";
64 fi
65 '';
66
67 enableParallelBuilding = true;
68
69 doCheck = true;
70
71 # Don't try to write to /var/cache/fontconfig at install time.
72 installFlags = "fc_cachedir=$(TMPDIR)/dummy RUN_FC_CACHE_TEST=false";
73
74 postInstall = ''
75 cd "$out/etc/fonts"
76 "${libxslt.bin}/bin/xsltproc" --stringparam fontDirectories "${dejavu_fonts.minimal}" \
77 --stringparam fontconfigConfigVersion "${configVersion}" \
78 --path $out/share/xml/fontconfig \
79 ${./make-fonts-conf.xsl} $out/etc/fonts/fonts.conf \
80 > fonts.conf.tmp
81 mv fonts.conf.tmp $out/etc/fonts/fonts.conf
82 '';
83
84 passthru = {
85 inherit configVersion;
86 };
87
88 meta = with stdenv.lib; {
89 description = "A library for font customization and configuration";
90 homepage = http://fontconfig.org/;
91 license = licenses.bsd2; # custom but very bsd-like
92 platforms = platforms.all;
93 maintainers = [ maintainers.vcunat ];
94 };
95}
96