at 16.09-beta 5.6 kB view raw
1{ config, pkgs, lib, ... }: 2 3with lib; 4 5let 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}/etc/fonts/presets/${cfg.substitutions}/*.conf \ 83 $support_folder 84 ln -s ${pkgs.fontconfig-ultimate}/etc/fonts/presets/${cfg.substitutions}/*.conf \ 85 $latest_folder 86 ''} 87 88 # fontconfig ultimate various configuration files 89 ln -s ${pkgs.fontconfig-ultimate}/etc/fonts/conf.d/*.conf \ 90 $support_folder 91 ln -s ${pkgs.fontconfig-ultimate}/etc/fonts/conf.d/*.conf \ 92 $latest_folder 93 ''; 94 95in 96{ 97 98 options = { 99 100 fonts = { 101 102 fontconfig = { 103 104 ultimate = { 105 enable = mkOption { 106 type = types.bool; 107 default = true; 108 description = '' 109 Enable fontconfig-ultimate settings (formerly known as 110 Infinality). Besides the customizable settings in this NixOS 111 module, fontconfig-ultimate also provides many font-specific 112 rendering tweaks. 113 ''; 114 }; 115 116 allowBitmaps = mkOption { 117 type = types.bool; 118 default = true; 119 description = '' 120 Allow bitmap fonts. Set to <literal>false</literal> to ban all 121 bitmap fonts. 122 ''; 123 }; 124 125 allowType1 = mkOption { 126 type = types.bool; 127 default = false; 128 description = '' 129 Allow Type-1 fonts. Default is <literal>false</literal> because of 130 poor rendering. 131 ''; 132 }; 133 134 useEmbeddedBitmaps = mkOption { 135 type = types.bool; 136 default = false; 137 description = ''Use embedded bitmaps in fonts like Calibri.''; 138 }; 139 140 forceAutohint = mkOption { 141 type = types.bool; 142 default = false; 143 description = '' 144 Force use of the TrueType Autohinter. Useful for debugging or 145 free-software purists. 146 ''; 147 }; 148 149 renderMonoTTFAsBitmap = mkOption { 150 type = types.bool; 151 default = false; 152 description = ''Render some monospace TTF fonts as bitmaps.''; 153 }; 154 155 substitutions = mkOption { 156 type = types.nullOr (types.enum ["free" "combi" "ms"]); 157 default = "free"; 158 description = '' 159 Font substitutions to replace common Type 1 fonts with nicer 160 TrueType fonts. <literal>free</literal> uses free fonts, 161 <literal>ms</literal> uses Microsoft fonts, 162 <literal>combi</literal> uses a combination, and 163 <literal>none</literal> disables the substitutions. 164 ''; 165 }; 166 167 preset = mkOption { 168 type = types.enum ["ultimate1" "ultimate2" "ultimate3" "ultimate4" "ultimate5" "osx" "windowsxp"]; 169 default = "ultimate3"; 170 description = '' 171 FreeType rendering settings preset. Any of the presets may be 172 customized by setting environment variables. 173 ''; 174 }; 175 }; 176 }; 177 }; 178 179 }; 180 181 config = mkIf (config.fonts.fontconfig.enable && cfg.enable) { 182 183 fonts.fontconfig.confPackages = [ confPkg ]; 184 environment.variables."INFINALITY_FT" = cfg.preset; 185 186 }; 187 188}