at 15.09-beta 6.3 kB view raw
1{ config, pkgs, lib, ... }: 2 3with lib; 4 5let fcBool = x: if x then "<bool>true</bool>" else "<bool>false</bool>"; 6in 7{ 8 9 options = { 10 11 fonts = { 12 13 fontconfig = { 14 15 ultimate = { 16 enable = mkOption { 17 type = types.bool; 18 default = true; 19 description = '' 20 Enable fontconfig-ultimate settings (formerly known as 21 Infinality). Besides the customizable settings in this NixOS 22 module, fontconfig-ultimate also provides many font-specific 23 rendering tweaks. 24 ''; 25 }; 26 27 allowBitmaps = mkOption { 28 type = types.bool; 29 default = true; 30 description = '' 31 Allow bitmap fonts. Set to <literal>false</literal> to ban all 32 bitmap fonts. 33 ''; 34 }; 35 36 allowType1 = mkOption { 37 type = types.bool; 38 default = false; 39 description = '' 40 Allow Type-1 fonts. Default is <literal>false</literal> because of 41 poor rendering. 42 ''; 43 }; 44 45 useEmbeddedBitmaps = mkOption { 46 type = types.bool; 47 default = false; 48 description = ''Use embedded bitmaps in fonts like Calibri.''; 49 }; 50 51 forceAutohint = mkOption { 52 type = types.bool; 53 default = false; 54 description = '' 55 Force use of the TrueType Autohinter. Useful for debugging or 56 free-software purists. 57 ''; 58 }; 59 60 renderMonoTTFAsBitmap = mkOption { 61 type = types.bool; 62 default = false; 63 description = ''Render some monospace TTF fonts as bitmaps.''; 64 }; 65 66 substitutions = mkOption { 67 type = types.str // { 68 check = flip elem ["none" "free" "combi" "ms"]; 69 }; 70 default = "free"; 71 description = '' 72 Font substitutions to replace common Type 1 fonts with nicer 73 TrueType fonts. <literal>free</literal> uses free fonts, 74 <literal>ms</literal> uses Microsoft fonts, 75 <literal>combi</literal> uses a combination, and 76 <literal>none</literal> disables the substitutions. 77 ''; 78 }; 79 80 rendering = mkOption { 81 type = types.attrs; 82 default = pkgs.fontconfig-ultimate.rendering.ultimate; 83 description = '' 84 FreeType rendering settings presets. The default is 85 <literal>pkgs.fontconfig-ultimate.rendering.ultimate</literal>. 86 The other available styles are: 87 <literal>ultimate-lighter</literal>, 88 <literal>ultimate-darker</literal>, 89 <literal>ultimate-lightest</literal>, 90 <literal>ultimate-darkest</literal>, 91 <literal>default</literal> (the original Infinality default), 92 <literal>osx</literal>, 93 <literal>ipad</literal>, 94 <literal>ubuntu</literal>, 95 <literal>linux</literal>, 96 <literal>winxplight</literal>, 97 <literal>win7light</literal>, 98 <literal>winxp</literal>, 99 <literal>win7</literal>, 100 <literal>vanilla</literal>, 101 <literal>classic</literal>, 102 <literal>nudge</literal>, 103 <literal>push</literal>, 104 <literal>shove</literal>, 105 <literal>sharpened</literal>, 106 <literal>infinality</literal>. Any of the presets may be 107 customized by editing the attributes. To disable, set this option 108 to the empty attribute set <literal>{}</literal>. 109 ''; 110 }; 111 }; 112 }; 113 }; 114 115 }; 116 117 118 config = 119 let ultimate = config.fonts.fontconfig.ultimate; 120 fontconfigUltimateConf = '' 121 <?xml version="1.0"?> 122 <!DOCTYPE fontconfig SYSTEM "fonts.dtd"> 123 <fontconfig> 124 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 }; 192 193}