1{
2 buildPackages,
3 fontconfig,
4 lib,
5 runCommand,
6 stdenv,
7}:
8let
9 fontconfig' = fontconfig;
10in
11{
12 fontconfig ? fontconfig',
13 fontDirectories,
14}:
15
16runCommand "fc-cache"
17 {
18 preferLocalBuild = true;
19 allowSubstitutes = false;
20 passAsFile = [ "fontDirs" ];
21 fontDirs = ''
22 <!-- Font directories -->
23 ${lib.concatStringsSep "\n" (map (font: "<dir>${font}</dir>") fontDirectories)}
24 '';
25 }
26 ''
27 export FONTCONFIG_FILE=$(pwd)/fonts.conf
28
29 cat > fonts.conf << EOF
30 <?xml version='1.0'?>
31 <!DOCTYPE fontconfig SYSTEM 'urn:fontconfig:fonts.dtd'>
32 <fontconfig>
33 <include>${fontconfig.out}/etc/fonts/fonts.conf</include>
34 <cachedir>$out</cachedir>
35 EOF
36 cat "$fontDirsPath" >> fonts.conf
37 echo "</fontconfig>" >> fonts.conf
38
39 # N.B.: fc-cache keys its cache entries by architecture.
40 # We must invoke the host `fc-cache` (not the build fontconfig) if we want
41 # the cache to be usable by the host.
42 mkdir -p $out
43 ${stdenv.hostPlatform.emulator buildPackages} ${lib.getExe' fontconfig "fc-cache"} -sv
44
45 # This is not a cache dir in the normal sense -- it won't be automatically
46 # recreated.
47 rm -f "$out/CACHEDIR.TAG"
48 ''