blob: 4473d1aac659e85d22676a78540a7a519b4ac5c3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
{ config, lib, ... }: let
cfg = config.fonts.fontconfig;
fcConfd = "fontconfig/conf.d";
fcResources = ./resources/fontconfig;
extraConfigFile = lib.types.submodule ({ name, ... }: {
options = {
enable = lib.mkEnableOption "Whether this font config file should be generated.";
text = lib.mkOption {
type = lib.types.nullOr lib.types.lines;
default = null;
description = "Verbatim contents of the config file. If this option is null then the 'source' option must be set.";
};
source = lib.mkOption {
type = lib.types.nullOr lib.types.path;
default = null;
description = "Config file to source. Alternatively, use the 'text' option instead.";
};
label = lib.mkOption {
type = lib.types.str;
default = "name";
description = "Label to use for the name of the config file.";
};
priority = lib.mkOption {
type = lib.types.addCheck lib.types.int (x: x >= 0 && x <= 99);
default = 90;
description = ''
Determines the order in which configs are loaded.
Must be a value within the range of 0-99, where priority 0 is the highest priority and 99 is the lowest.
'';
};
};
config = {
label = lib.mkDefault name;
};
});
in {
options.fonts.fontconfig = {
_extraConfigFiles = lib.mkOption {
type = lib.types.attrsOf extraConfigFile;
default = {};
description = ''
Extra font config files that will be added to `~/.config/fontconfig/conf.d/`.
Files are added as `conf.d/{priority}-{label}.conf`.
'';
example = ''
{
tamzen = {
enable = true;
label = "tamzen-disable-antialiasing";
text = tamzenFontConfig; # Pretend this is defined elsewhere
priority = 90;
}; # => conf.d/90-tamzen-disable-antialiasing.conf
commit-mono-options = {
enable = true;
source = ./resources/fontconfig/commit-mono.conf;
priority = 80;
}; # => conf.d/80-commit-mono-options.conf
};
'';
};
};
config = lib.mkIf cfg.enable {
fonts.fontconfig._extraConfigFiles = {
tamzen-disable-antialiasing = {
enable = true;
text = builtins.readFile ./resources/fontconfig/90-tamzen-disable-anti-aliasing.conf;
priority = 90;
};
commit-mono-options = {
enable = true;
source = ./resources/fontconfig/90-commit-mono-options.conf;
priority = 90;
};
};
xdg.configFile = lib.mapAttrs' (name: config:
lib.nameValuePair "${fcConfd}/${builtins.toString config.priority}-${config.label}.conf"
{ inherit (config) text; source = lib.mkIf (config.source != null) config.source; }
) cfg._extraConfigFiles;
};
}
|