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 # The configuration to be included in /etc/font/
12 confPkg = pkgs.runCommand "font-ultimate-conf" {} ''
13 support_folder=$out/etc/fonts/conf.d
14 latest_folder=$out/etc/fonts/${latestVersion}/conf.d
15
16 mkdir -p $support_folder
17 mkdir -p $latest_folder
18
19 # fontconfig ultimate substitutions
20 ${optionalString (cfg.substitutions != "none") ''
21 ln -s ${pkgs.fontconfig-ultimate}/etc/fonts/presets/${cfg.substitutions}/*.conf \
22 $support_folder
23 ln -s ${pkgs.fontconfig-ultimate}/etc/fonts/presets/${cfg.substitutions}/*.conf \
24 $latest_folder
25 ''}
26
27 # fontconfig ultimate various configuration files
28 ln -s ${pkgs.fontconfig-ultimate}/etc/fonts/conf.d/*.conf \
29 $support_folder
30 ln -s ${pkgs.fontconfig-ultimate}/etc/fonts/conf.d/*.conf \
31 $latest_folder
32 '';
33
34in
35{
36
37 options = {
38
39 fonts = {
40
41 fontconfig = {
42
43 ultimate = {
44 enable = mkOption {
45 type = types.bool;
46 default = false;
47 description = ''
48 Enable fontconfig-ultimate settings (formerly known as
49 Infinality). Besides the customizable settings in this NixOS
50 module, fontconfig-ultimate also provides many font-specific
51 rendering tweaks.
52 '';
53 };
54
55 substitutions = mkOption {
56 type = types.nullOr (types.enum ["free" "combi" "ms"]);
57 default = "free";
58 description = ''
59 Font substitutions to replace common Type 1 fonts with nicer
60 TrueType fonts. <literal>free</literal> uses free fonts,
61 <literal>ms</literal> uses Microsoft fonts,
62 <literal>combi</literal> uses a combination, and
63 <literal>none</literal> disables the substitutions.
64 '';
65 };
66
67 preset = mkOption {
68 type = types.enum ["ultimate1" "ultimate2" "ultimate3" "ultimate4" "ultimate5" "osx" "windowsxp"];
69 default = "ultimate3";
70 description = ''
71 FreeType rendering settings preset. Any of the presets may be
72 customized by setting environment variables.
73 '';
74 };
75 };
76 };
77 };
78
79 };
80
81 config = mkIf (config.fonts.fontconfig.enable && cfg.enable) {
82
83 fonts.fontconfig.confPackages = [ confPkg ];
84 environment.variables."INFINALITY_FT" = cfg.preset;
85
86 };
87
88}