fontconfig: fix etc priority

authored by Eric Sagnes and committed by Nikolay Amiantov cd2948a7 edb94162

+303 -206
+93 -73
nixos/modules/config/fonts/fontconfig-ultimate.nix
··· 3 3 with lib; 4 4 5 5 let fcBool = x: if x then "<bool>true</bool>" else "<bool>false</bool>"; 6 + 7 + cfg = config.fonts.fontconfig.ultimate; 8 + 9 + latestVersion = pkgs.fontconfig.configVersion; 10 + 11 + # fontconfig ultimate main configuration file 12 + # priority 52 13 + fontconfigUltimateConf = pkgs.writeText "fc-52-fontconfig-ultimate.conf" '' 14 + <?xml version="1.0"?> 15 + <!DOCTYPE fontconfig SYSTEM "fonts.dtd"> 16 + <fontconfig> 17 + 18 + ${optionalString (!cfg.allowBitmaps) '' 19 + <!-- Reject bitmap fonts --> 20 + <selectfont> 21 + <rejectfont> 22 + <pattern> 23 + <patelt name="scalable"><bool>false</bool></patelt> 24 + </pattern> 25 + </rejectfont> 26 + </selectfont> 27 + ''} 28 + 29 + ${optionalString cfg.allowType1 '' 30 + <!-- Reject Type 1 fonts --> 31 + <selectfont> 32 + <rejectfont> 33 + <pattern> 34 + <patelt name="fontformat"> 35 + <string>Type 1</string> 36 + </patelt> 37 + </pattern> 38 + </rejectfont> 39 + </selectfont> 40 + ''} 41 + 42 + <!-- Use embedded bitmaps in fonts like Calibri? --> 43 + <match target="font"> 44 + <edit name="embeddedbitmap" mode="assign"> 45 + ${fcBool cfg.useEmbeddedBitmaps} 46 + </edit> 47 + </match> 48 + 49 + <!-- Force autohint always --> 50 + <match target="font"> 51 + <edit name="force_autohint" mode="assign"> 52 + ${fcBool cfg.forceAutohint} 53 + </edit> 54 + </match> 55 + 56 + <!-- Render some monospace TTF fonts as bitmaps --> 57 + <match target="pattern"> 58 + <edit name="bitmap_monospace" mode="assign"> 59 + ${fcBool cfg.renderMonoTTFAsBitmap} 60 + </edit> 61 + </match> 62 + 63 + </fontconfig> 64 + ''; 65 + 66 + # The configuration to be included in /etc/font/ 67 + confPkg = pkgs.runCommand "font-ultimate-conf" {} '' 68 + support_folder=$out/etc/fonts/conf.d 69 + latest_folder=$out/etc/fonts/${latestVersion}/conf.d 70 + 71 + mkdir -p $support_folder 72 + mkdir -p $latest_folder 73 + 74 + # 52-fontconfig-ultimate.conf 75 + ln -s ${fontconfigUltimateConf} \ 76 + $support_folder/52-fontconfig-ultimate.conf 77 + ln -s ${fontconfigUltimateConf} \ 78 + $latest_folder/52-fontconfig-ultimate.conf 79 + 80 + # fontconfig ultimate substitutions 81 + ${optionalString (cfg.substitutions != "none") '' 82 + ln -s ${pkgs.fontconfig-ultimate.confd}/etc/fonts/presets/${cfg.substitutions}/*.conf \ 83 + $support_folder 84 + ln -s ${pkgs.fontconfig-ultimate.confd}/etc/fonts/presets/${cfg.substitutions}/*.conf \ 85 + $latest_folder 86 + ''} 87 + 88 + # fontconfig ultimate various configuration files 89 + ln -s ${pkgs.fontconfig-ultimate.confd}/etc/fonts/conf.d/*.conf \ 90 + $support_folder 91 + ln -s ${pkgs.fontconfig-ultimate.confd}/etc/fonts/conf.d/*.conf \ 92 + $latest_folder 93 + ''; 94 + 6 95 in 7 96 { 8 97 ··· 114 203 115 204 }; 116 205 206 + config = mkIf (config.fonts.fontconfig.enable && cfg.enable) { 117 207 118 - config = 119 - let ultimate = config.fonts.fontconfig.ultimate; 120 - fontconfigUltimateConf = '' 121 - <?xml version="1.0"?> 122 - <!DOCTYPE fontconfig SYSTEM "fonts.dtd"> 123 - <fontconfig> 208 + fonts.fontconfig.confPackages = [ confPkg ]; 209 + environment.variables = cfg.rendering; 124 210 125 - ${optionalString (!ultimate.allowBitmaps) '' 126 - <!-- Reject bitmap fonts --> 127 - <selectfont> 128 - <rejectfont> 129 - <pattern> 130 - <patelt name="scalable"><bool>false</bool></patelt> 131 - </pattern> 132 - </rejectfont> 133 - </selectfont> 134 - ''} 135 - 136 - ${optionalString ultimate.allowType1 '' 137 - <!-- Reject Type 1 fonts --> 138 - <selectfont> 139 - <rejectfont> 140 - <pattern> 141 - <patelt name="fontformat"> 142 - <string>Type 1</string> 143 - </patelt> 144 - </pattern> 145 - </rejectfont> 146 - </selectfont> 147 - ''} 148 - 149 - <!-- Use embedded bitmaps in fonts like Calibri? --> 150 - <match target="font"> 151 - <edit name="embeddedbitmap" mode="assign"> 152 - ${fcBool ultimate.useEmbeddedBitmaps} 153 - </edit> 154 - </match> 155 - 156 - <!-- Force autohint always --> 157 - <match target="font"> 158 - <edit name="force_autohint" mode="assign"> 159 - ${fcBool ultimate.forceAutohint} 160 - </edit> 161 - </match> 162 - 163 - <!-- Render some monospace TTF fonts as bitmaps --> 164 - <match target="pattern"> 165 - <edit name="bitmap_monospace" mode="assign"> 166 - ${fcBool ultimate.renderMonoTTFAsBitmap} 167 - </edit> 168 - </match> 169 - 170 - ${optionalString (ultimate.substitutions != "none") '' 171 - <!-- Type 1 font substitutions --> 172 - <include ignore_missing="yes">${pkgs.fontconfig-ultimate.confd}/etc/fonts/presets/${ultimate.substitutions}</include> 173 - ''} 174 - 175 - <include ignore_missing="yes">${pkgs.fontconfig-ultimate.confd}/etc/fonts/conf.d</include> 176 - 177 - </fontconfig> 178 - ''; 179 - in mkIf (config.fonts.fontconfig.enable && ultimate.enable) { 180 - 181 - environment.etc."fonts/conf.d/52-fontconfig-ultimate.conf" = { 182 - text = fontconfigUltimateConf; 183 - }; 184 - 185 - environment.etc."fonts/${pkgs.fontconfig.configVersion}/conf.d/52-fontconfig-ultimate.conf" = { 186 - text = fontconfigUltimateConf; 187 - }; 188 - 189 - environment.variables = ultimate.rendering; 190 - 191 - }; 211 + }; 192 212 193 213 }
+210 -130
nixos/modules/config/fonts/fontconfig.nix
··· 1 + /* 2 + 3 + NixOS support 2 fontconfig versions, "support" and "latest". 4 + 5 + - "latest" refers to default fontconfig package (pkgs.fontconfig). 6 + configuration files are linked to /etc/fonts/VERSION/conf.d/ 7 + - "support" refers to supportPkg (pkgs."fontconfig_${supportVersion}"). 8 + configuration files are linked to /etc/fonts/conf.d/ 9 + 10 + This module generates a package containing configuration files and link it in /etc/fonts. 11 + 12 + Fontconfig reads files in folder name / file name order, so the number prepended to the configuration file name decide the order of parsing. 13 + Low number means high priority. 14 + 15 + Default fonts should have a high priority (low number) to be at the head of the preferred fonts list, fontconfig advise the 30~40 range. 16 + 17 + */ 18 + 1 19 { config, lib, pkgs, ... }: 2 20 3 21 with lib; 4 22 23 + let cfg = config.fonts.fontconfig; 24 + 25 + fcBool = x: "<bool>" + (if x then "true" else "false") + "</bool>"; 26 + 27 + # back-supported fontconfig version and package 28 + # version is used for font cache generation 29 + supportVersion = "210"; 30 + supportPkg = pkgs."fontconfig_${supportVersion}"; 31 + 32 + # latest fontconfig version and package 33 + # version is used for configuration folder name, /etc/fonts/VERSION/ 34 + # note: format differs from supportVersion and can not be used with makeCacheConf 35 + latestVersion = pkgs.fontconfig.configVersion; 36 + latestPkg = pkgs.fontconfig; 37 + 38 + # supported version fonts.conf 39 + supportFontsConf = pkgs.makeFontsConf { fontconfig = supportPkg; fontDirectories = config.fonts.fonts; }; 40 + 41 + # configuration file to read fontconfig cache 42 + # version dependent 43 + # priority 0 44 + cacheConfSupport = makeCacheConf { version = supportVersion; }; 45 + cacheConfLatest = makeCacheConf {}; 46 + 47 + # generate the font cache setting file for a fontconfig version 48 + # use latest when no version is passed 49 + makeCacheConf = { version ? null }: 50 + let 51 + fcPackage = if builtins.isNull version 52 + then "fontconfig" 53 + else "fontconfig_${version}"; 54 + makeCache = fontconfig: pkgs.makeFontsCache { inherit fontconfig; fontDirectories = config.fonts.fonts; }; 55 + cache = makeCache pkgs."${fcPackage}"; 56 + cache32 = makeCache pkgs.pkgsi686Linux."${fcPackage}"; 57 + in 58 + pkgs.writeText "fc-00-nixos-cache.conf" '' 59 + <?xml version='1.0'?> 60 + <!DOCTYPE fontconfig SYSTEM 'fonts.dtd'> 61 + <fontconfig> 62 + <!-- Font directories --> 63 + ${concatStringsSep "\n" (map (font: "<dir>${font}</dir>") config.fonts.fonts)} 64 + <!-- Pre-generated font caches --> 65 + <cachedir>${cache}</cachedir> 66 + ${optionalString (pkgs.stdenv.isx86_64 && cfg.cache32Bit) '' 67 + <cachedir>${cache32}</cachedir> 68 + ''} 69 + </fontconfig> 70 + ''; 71 + 72 + # rendering settings configuration file 73 + # priority 10 74 + renderConf = pkgs.writeText "fc-10-nixos-rendering.conf" '' 75 + <?xml version='1.0'?> 76 + <!DOCTYPE fontconfig SYSTEM 'fonts.dtd'> 77 + <fontconfig> 78 + 79 + <!-- Default rendering settings --> 80 + <match target="font"> 81 + <edit mode="assign" name="hinting"> 82 + ${fcBool cfg.hinting.enable} 83 + </edit> 84 + <edit mode="assign" name="autohint"> 85 + ${fcBool cfg.hinting.autohint} 86 + </edit> 87 + <edit mode="assign" name="hintstyle"> 88 + <const>hint${cfg.hinting.style}</const> 89 + </edit> 90 + <edit mode="assign" name="antialias"> 91 + ${fcBool cfg.antialias} 92 + </edit> 93 + <edit mode="assign" name="rgba"> 94 + <const>${cfg.subpixel.rgba}</const> 95 + </edit> 96 + <edit mode="assign" name="lcdfilter"> 97 + <const>lcd${cfg.subpixel.lcdfilter}</const> 98 + </edit> 99 + </match> 100 + 101 + ${optionalString (cfg.dpi != 0) '' 102 + <match target="pattern"> 103 + <edit name="dpi" mode="assign"> 104 + <double>${toString cfg.dpi}</double> 105 + </edit> 106 + </match> 107 + ''} 108 + 109 + </fontconfig> 110 + ''; 111 + 112 + # prefered default fonts configuration file 113 + # priority 30 114 + genericAliasConf = 115 + let genDefault = fonts: name: 116 + optionalString (fonts != []) '' 117 + <alias> 118 + <family>${name}</family> 119 + <prefer> 120 + ${concatStringsSep "" 121 + (map (font: '' 122 + <family>${font}</family> 123 + '') fonts)} 124 + </prefer> 125 + </alias> 126 + ''; 127 + in 128 + pkgs.writeText "fc-30-nixos-generic-alias.conf" '' 129 + <?xml version='1.0'?> 130 + <!DOCTYPE fontconfig SYSTEM 'fonts.dtd'> 131 + <fontconfig> 132 + 133 + <!-- Default fonts --> 134 + ${genDefault cfg.defaultFonts.sansSerif "sans-serif"} 135 + 136 + ${genDefault cfg.defaultFonts.serif "serif"} 137 + 138 + ${genDefault cfg.defaultFonts.monospace "monospace"} 139 + 140 + </fontconfig> 141 + ''; 142 + 143 + # user settings configuration file 144 + # priority 99 145 + userConf = pkgs.writeText "fc-99-user.conf" '' 146 + <?xml version="1.0"?> 147 + <!DOCTYPE fontconfig SYSTEM "fonts.dtd"> 148 + <fontconfig> 149 + <include ignore_missing="yes" prefix="xdg">fontconfig/conf.d</include> 150 + <include ignore_missing="yes" prefix="xdg">fontconfig/fonts.conf</include> 151 + </fontconfig> 152 + ''; 153 + 154 + # fontconfig configuration package 155 + confPkg = pkgs.runCommand "fontconfig-conf" {} '' 156 + support_folder=$out/etc/fonts 157 + latest_folder=$out/etc/fonts/${latestVersion} 158 + 159 + mkdir -p $support_folder/conf.d 160 + mkdir -p $latest_folder/conf.d 161 + 162 + # fonts.conf 163 + ln -s ${supportFontsConf} $support_folder/fonts.conf 164 + ln -s ${latestPkg.out}/etc/fonts/fonts.conf \ 165 + $latest_folder/fonts.conf 166 + 167 + # fontconfig default config files 168 + ln -s ${supportPkg.out}/etc/fonts/conf.d/*.conf \ 169 + $support_folder/conf.d/ 170 + ln -s ${latestPkg.out}/etc/fonts/conf.d/*.conf \ 171 + $latest_folder/conf.d/ 172 + 173 + # 00-nixos-cache.conf 174 + ln -s ${cacheConfSupport} \ 175 + $support_folder/conf.d/00-nixos-cache.conf 176 + ln -s ${cacheConfLatest} $latest_folder/conf.d/00-nixos-cache.conf 177 + 178 + # 10-nixos-rendering.conf 179 + ln -s ${renderConf} $support_folder/conf.d/10-nixos-rendering.conf 180 + ln -s ${renderConf} $latest_folder/conf.d/10-nixos-rendering.conf 181 + 182 + # 30-nixos-generic-alias.conf 183 + ln -s ${genericAliasConf} $support_folder/conf.d/30-nixos-generic-alias.conf 184 + ln -s ${genericAliasConf} $latest_folder/conf.d/30-nixos-generic-alias.conf 185 + 186 + # 99-user.conf 187 + ${optionalString cfg.includeUserConf '' 188 + ln -s ${userConf} $support_folder/conf.d/99-user.conf 189 + ln -s ${userConf} $latest_folder/conf.d/99-user.conf 190 + ''} 191 + ''; 192 + 193 + # Package with configuration files 194 + # this merge all the packages in the fonts.fontconfig.confPackages list 195 + fontconfigEtc = pkgs.buildEnv { 196 + name = "fontconfig-etc"; 197 + paths = cfg.confPackages; 198 + ignoreCollisions = true; 199 + }; 200 + in 5 201 { 6 202 7 203 options = { ··· 18 214 running X11 applications or any other program that uses 19 215 Fontconfig, you can turn this option off and prevent a 20 216 dependency on all those fonts. 217 + ''; 218 + }; 219 + 220 + confPackages = mkOption { 221 + internal = true; 222 + type = with types; listOf path; 223 + default = [ ]; 224 + description = '' 225 + Fontconfig configuration packages. 21 226 ''; 22 227 }; 23 228 ··· 142 347 }; 143 348 144 349 }; 145 - 146 - config = 147 - let fontconfig = config.fonts.fontconfig; 148 - fcBool = x: "<bool>" + (if x then "true" else "false") + "</bool>"; 149 - renderConf = '' 150 - <?xml version='1.0'?> 151 - <!DOCTYPE fontconfig SYSTEM 'fonts.dtd'> 152 - <fontconfig> 153 - 154 - <!-- Default rendering settings --> 155 - <match target="font"> 156 - <edit mode="assign" name="hinting"> 157 - ${fcBool fontconfig.hinting.enable} 158 - </edit> 159 - <edit mode="assign" name="autohint"> 160 - ${fcBool fontconfig.hinting.autohint} 161 - </edit> 162 - <edit mode="assign" name="hintstyle"> 163 - <const>hint${fontconfig.hinting.style}</const> 164 - </edit> 165 - <edit mode="assign" name="antialias"> 166 - ${fcBool fontconfig.antialias} 167 - </edit> 168 - <edit mode="assign" name="rgba"> 169 - <const>${fontconfig.subpixel.rgba}</const> 170 - </edit> 171 - <edit mode="assign" name="lcdfilter"> 172 - <const>lcd${fontconfig.subpixel.lcdfilter}</const> 173 - </edit> 174 - </match> 175 - 176 - ${optionalString (fontconfig.dpi != 0) '' 177 - <match target="pattern"> 178 - <edit name="dpi" mode="assign"> 179 - <double>${toString fontconfig.dpi}</double> 180 - </edit> 181 - </match> 182 - ''} 183 - 184 - </fontconfig> 185 - ''; 186 - genericAliasConf = '' 187 - <?xml version='1.0'?> 188 - <!DOCTYPE fontconfig SYSTEM 'fonts.dtd'> 189 - <fontconfig> 190 - 191 - <!-- Default fonts --> 192 - ${optionalString (fontconfig.defaultFonts.sansSerif != []) '' 193 - <alias> 194 - <family>sans-serif</family> 195 - <prefer> 196 - ${concatStringsSep "\n" 197 - (map (font: "<family>${font}</family>") 198 - fontconfig.defaultFonts.sansSerif)} 199 - </prefer> 200 - </alias> 201 - ''} 202 - ${optionalString (fontconfig.defaultFonts.serif != []) '' 203 - <alias> 204 - <family>serif</family> 205 - <prefer> 206 - ${concatStringsSep "\n" 207 - (map (font: "<family>${font}</family>") 208 - fontconfig.defaultFonts.serif)} 209 - </prefer> 210 - </alias> 211 - ''} 212 - ${optionalString (fontconfig.defaultFonts.monospace != []) '' 213 - <alias> 214 - <family>monospace</family> 215 - <prefer> 216 - ${concatStringsSep "\n" 217 - (map (font: "<family>${font}</family>") 218 - fontconfig.defaultFonts.monospace)} 219 - </prefer> 220 - </alias> 221 - ''} 350 + config = mkIf cfg.enable { 351 + fonts.fontconfig.confPackages = [ confPkg ]; 222 352 223 - </fontconfig> 224 - ''; 225 - in mkIf fontconfig.enable { 226 - 227 - # Fontconfig 2.10 backward compatibility 228 - 229 - # Bring in the default (upstream) fontconfig configuration, only for fontconfig 2.10 230 - environment.etc."fonts/fonts.conf".source = 231 - pkgs.makeFontsConf { fontconfig = pkgs.fontconfig_210; fontDirectories = config.fonts.fonts; }; 232 - 233 - environment.etc."fonts/conf.d/10-nixos-rendering.conf".text = renderConf; 234 - environment.etc."fonts/conf.d/60-nixos-generic-alias.conf".text = genericAliasConf; 235 - 236 - # Versioned fontconfig > 2.10. Take shared fonts.conf from fontconfig. 237 - # Otherwise specify only font directories. 238 - environment.etc."fonts/${pkgs.fontconfig.configVersion}/fonts.conf".source = 239 - "${pkgs.fontconfig.out}/etc/fonts/fonts.conf"; 240 - 241 - environment.etc."fonts/${pkgs.fontconfig.configVersion}/conf.d/00-nixos.conf".text = 242 - let 243 - cache = fontconfig: pkgs.makeFontsCache { inherit fontconfig; fontDirectories = config.fonts.fonts; }; 244 - in '' 245 - <?xml version='1.0'?> 246 - <!DOCTYPE fontconfig SYSTEM 'fonts.dtd'> 247 - <fontconfig> 248 - <!-- Font directories --> 249 - ${concatStringsSep "\n" (map (font: "<dir>${font}</dir>") config.fonts.fonts)} 250 - <!-- Pre-generated font caches --> 251 - <cachedir>${cache pkgs.fontconfig}</cachedir> 252 - ${optionalString (pkgs.stdenv.isx86_64 && config.fonts.fontconfig.cache32Bit) '' 253 - <cachedir>${cache pkgs.pkgsi686Linux.fontconfig}</cachedir> 254 - ''} 255 - </fontconfig> 256 - ''; 257 - 258 - environment.etc."fonts/${pkgs.fontconfig.configVersion}/conf.d/10-nixos-rendering.conf".text = renderConf; 259 - environment.etc."fonts/${pkgs.fontconfig.configVersion}/conf.d/60-nixos-generic-alias.conf".text = genericAliasConf; 260 - 261 - environment.etc."fonts/${pkgs.fontconfig.configVersion}/conf.d/99-user.conf" = { 262 - enable = fontconfig.includeUserConf; 263 - text = '' 264 - <?xml version="1.0"?> 265 - <!DOCTYPE fontconfig SYSTEM "fonts.dtd"> 266 - <fontconfig> 267 - <include ignore_missing="yes" prefix="xdg">fontconfig/conf.d</include> 268 - <include ignore_missing="yes" prefix="xdg">fontconfig/fonts.conf</include> 269 - </fontconfig> 270 - ''; 271 - }; 272 - 273 - environment.systemPackages = [ pkgs.fontconfig ]; 274 - 275 - }; 353 + environment.systemPackages = [ pkgs.fontconfig ]; 354 + environment.etc.fonts.source = "${fontconfigEtc}/etc/fonts/"; 355 + }; 276 356 277 357 }
-1
pkgs/development/libraries/fontconfig/default.nix
··· 68 68 cd "$out/etc/fonts" 69 69 rm conf.d/{50-user,51-local}.conf 70 70 "${libxslt.bin}/bin/xsltproc" --stringparam fontDirectories "${fontbhttf}" \ 71 - --stringparam fontconfig "$out" \ 72 71 --stringparam fontconfigConfigVersion "${configVersion}" \ 73 72 --path $out/share/xml/fontconfig \ 74 73 ${./make-fonts-conf.xsl} $out/etc/fonts/fonts.conf \
-2
pkgs/development/libraries/fontconfig/make-fonts-conf.xsl
··· 28 28 <!-- /var/cache/fontconfig is useful for non-nixos systems --> 29 29 <cachedir>/var/cache/fontconfig</cachedir> 30 30 31 - <!-- fontconfig distribution conf.d --> 32 - <include><xsl:value-of select="$fontconfig" />/etc/fonts/conf.d</include> 33 31 <!-- versioned system-wide config --> 34 32 <include ignore_missing="yes">/etc/fonts/<xsl:value-of select="$fontconfigConfigVersion" />/conf.d</include> 35 33