1{
2 stdenv,
3 lib,
4 fetchurl,
5 pkg-config,
6 python3,
7 freetype,
8 expat,
9 libxslt,
10 gperf,
11 dejavu_fonts,
12 autoreconfHook,
13 versionCheckHook,
14 testers,
15 gitUpdater,
16}:
17
18stdenv.mkDerivation (finalAttrs: {
19 pname = "fontconfig";
20 version = "2.16.2";
21
22 outputs = [
23 "bin"
24 "dev"
25 "lib"
26 "out"
27 ]; # $out contains all the config
28
29 # GitLab repositrory does not include pre-generated man pages.
30 # ref: https://github.com/NixOS/nixpkgs/pull/401037#discussion_r2055430206
31 src = fetchurl {
32 url = "https://gitlab.freedesktop.org/api/v4/projects/890/packages/generic/fontconfig/${finalAttrs.version}/fontconfig-${finalAttrs.version}.tar.xz";
33 hash = "sha256-FluP0qEZhkyHRksjOYbEobwJ77CcZd4cpAzB6F/7d+I=";
34 };
35
36 nativeBuildInputs = [
37 autoreconfHook
38 gperf
39 libxslt
40 pkg-config
41 python3
42 ];
43
44 buildInputs = [
45 expat
46 ];
47
48 propagatedBuildInputs = [
49 freetype
50 ];
51
52 postPatch = ''
53 # Requires networking.
54 sed -i '/check_PROGRAMS += test-crbug1004254/d' test/Makefile.am
55
56 # Test causes error without patch shebangs.
57 patchShebangs doc/check-whitespace-in-args.py
58 '';
59
60 configureFlags = [
61 "--sysconfdir=/etc"
62 "--with-arch=${stdenv.hostPlatform.parsed.cpu.name}"
63 "--with-cache-dir=/var/cache/fontconfig" # otherwise the fallback is in $out/
64 # just <1MB; this is what you get when loading config fails for some reason
65 "--with-default-fonts=${dejavu_fonts.minimal}"
66 ]
67 ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
68 "--with-arch=${stdenv.hostPlatform.parsed.cpu.name}"
69 ];
70
71 enableParallelBuilding = true;
72
73 doCheck = true;
74
75 installFlags = [
76 # Don't try to write to /var/cache/fontconfig at install time.
77 "fc_cachedir=$(TMPDIR)/dummy"
78 "RUN_FC_CACHE_TEST=false"
79 "sysconfdir=${placeholder "out"}/etc"
80 ];
81
82 postInstall = ''
83 cd "$out/etc/fonts"
84 xsltproc --stringparam fontDirectories "${dejavu_fonts.minimal}" \
85 --stringparam includes /etc/fonts/conf.d \
86 --path $out/share/xml/fontconfig \
87 ${./make-fonts-conf.xsl} $out/etc/fonts/fonts.conf \
88 > fonts.conf.tmp
89 mv fonts.conf.tmp $out/etc/fonts/fonts.conf
90 # We don't keep section 3 of the manpages, as they are quite large and
91 # probably not so useful.
92 rm -r $bin/share/man/man3
93 '';
94
95 nativeInstallCheckInputs = [
96 versionCheckHook
97 ];
98 doInstallCheck = true;
99 versionCheckProgram = "${placeholder "bin"}/bin/fc-list";
100 versionCheckProgramArg = "--version";
101
102 installCheckPhase = ''
103 runHook preInstallCheck
104
105 [ -d "$bin/share/man/man1" ]
106 [ -d "$bin/share/man/man5" ]
107 echo "man pages exist"
108
109 runHook postInstallCheck
110 '';
111
112 passthru = {
113 tests = {
114 pkg-config = testers.hasPkgConfigModules {
115 package = finalAttrs.finalPackage;
116 };
117 };
118
119 updateScript = gitUpdater {
120 url = "https://gitlab.freedesktop.org/fontconfig/fontconfig.git";
121 };
122 };
123
124 meta = with lib; {
125 description = "Library for font customization and configuration";
126 homepage = "http://fontconfig.org/";
127 license = licenses.bsd2; # custom but very bsd-like
128 platforms = platforms.all;
129 teams = [ teams.freedesktop ];
130 pkgConfigModules = [ "fontconfig" ];
131 };
132})