diff options
-rw-r--r-- | home-manager/default.nix | 1 | ||||
-rw-r--r-- | home-manager/fontconfig.nix | 83 | ||||
-rw-r--r-- | home-manager/resources/fontconfig/90-commit-mono-options.conf | 17 | ||||
-rw-r--r-- | home-manager/resources/fontconfig/90-tamzen-disable-anti-aliasing.conf | 14 |
4 files changed, 115 insertions, 0 deletions
diff --git a/home-manager/default.nix b/home-manager/default.nix index da8d936..6b0be87 100644 --- a/home-manager/default.nix +++ b/home-manager/default.nix @@ -2,6 +2,7 @@ imports = [ ./clone-repos.nix ./firefox.nix + ./fontconfig.nix ./home-cleanup.nix ./htop.nix ./mint-theme.nix diff --git a/home-manager/fontconfig.nix b/home-manager/fontconfig.nix new file mode 100644 index 0000000..4473d1a --- /dev/null +++ b/home-manager/fontconfig.nix @@ -0,0 +1,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; + }; +} diff --git a/home-manager/resources/fontconfig/90-commit-mono-options.conf b/home-manager/resources/fontconfig/90-commit-mono-options.conf new file mode 100644 index 0000000..9c7373a --- /dev/null +++ b/home-manager/resources/fontconfig/90-commit-mono-options.conf @@ -0,0 +1,17 @@ +<?xml version="1.0"?> +<!DOCTYPE fontconfig SYSTEM "fonts.dtd"> + +<fontconfig> + <description>Enable opentype features for CommitMono to make it match better with Inter as its monospace counterpart</description> + <match target="font"> + <test name="family" compare="eq" ignore-blanks="true"> + <string>CommitMono</string> + </test> + <edit name="fontfeatures" mode="append"> + <string>ss03 on</string> <!-- smart case --> + <string>ss04 on</string> <!-- symbol spacing --> + <string>cv02 on</string> <!-- alt g --> + <string>cv06 on</string> <!-- alt 6 & 9 --> + </edit> + </match> +</fontconfig> diff --git a/home-manager/resources/fontconfig/90-tamzen-disable-anti-aliasing.conf b/home-manager/resources/fontconfig/90-tamzen-disable-anti-aliasing.conf new file mode 100644 index 0000000..5bf94d7 --- /dev/null +++ b/home-manager/resources/fontconfig/90-tamzen-disable-anti-aliasing.conf @@ -0,0 +1,14 @@ +<?xml version="1.0"?> +<!DOCTYPE fontconfig SYSTEM "fonts.dtd"> + +<fontconfig> + <description>Disable anti-aliasing for Tamzen since it is a bitmap font</description> + <match target="pattern"> + <test name="family" compare="eq" qual="any"> + <string>Tamzen</string> + </test> + <edit name="antialias" mode="assign"> + <bool>false</bool> + </edit> + </match> +</fontconfig> |