fontconfig: add defaultFonts.* options
This commit is contained in:
parent
e6a315900d
commit
f2c5ba5e72
|
@ -1,3 +1,7 @@
|
||||||
|
# This module is heavily inspired by the corresponding NixOS module. See
|
||||||
|
#
|
||||||
|
# https://github.com/NixOS/nixpkgs/blob/23.11/nixos/modules/config/fonts/fontconfig.nix
|
||||||
|
|
||||||
{ config, lib, pkgs, ... }:
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
with lib;
|
with lib;
|
||||||
|
@ -32,6 +36,50 @@ in {
|
||||||
{command}`nix-env`.
|
{command}`nix-env`.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
defaultFonts = {
|
||||||
|
monospace = mkOption {
|
||||||
|
type = with types; listOf str;
|
||||||
|
default = [ ];
|
||||||
|
description = ''
|
||||||
|
Per-user default monospace font(s). Multiple fonts may be listed in
|
||||||
|
case multiple languages must be supported.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
sansSerif = mkOption {
|
||||||
|
type = with types; listOf str;
|
||||||
|
default = [ ];
|
||||||
|
description = ''
|
||||||
|
Per-user default sans serif font(s). Multiple fonts may be listed
|
||||||
|
in case multiple languages must be supported.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
serif = mkOption {
|
||||||
|
type = with types; listOf str;
|
||||||
|
default = [ ];
|
||||||
|
description = ''
|
||||||
|
Per-user default serif font(s). Multiple fonts may be listed in
|
||||||
|
case multiple languages must be supported.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
emoji = mkOption {
|
||||||
|
type = with types; listOf str;
|
||||||
|
default = [ ];
|
||||||
|
description = ''
|
||||||
|
Per-user default emoji font(s). Multiple fonts may be listed in
|
||||||
|
case a font does not support all emoji.
|
||||||
|
|
||||||
|
Note that fontconfig matches color emoji fonts preferentially,
|
||||||
|
so if you want to use a black and white font while having
|
||||||
|
a color font installed (eg. Noto Color Emoji installed alongside
|
||||||
|
Noto Emoji), fontconfig will still choose the color font even
|
||||||
|
when it is later in the list.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -71,27 +119,53 @@ in {
|
||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
|
|
||||||
xdg.configFile = {
|
xdg.configFile = let
|
||||||
"fontconfig/conf.d/10-hm-fonts.conf".text = ''
|
mkFontconfigConf = conf: ''
|
||||||
<?xml version='1.0'?>
|
<?xml version='1.0'?>
|
||||||
|
|
||||||
<!-- Generated by Home Manager. -->
|
<!-- Generated by Home Manager. -->
|
||||||
|
|
||||||
<!DOCTYPE fontconfig SYSTEM 'urn:fontconfig:fonts.dtd'>
|
<!DOCTYPE fontconfig SYSTEM 'urn:fontconfig:fonts.dtd'>
|
||||||
<fontconfig>
|
<fontconfig>
|
||||||
<description>Add fonts in the Nix user profile</description>
|
${conf}
|
||||||
|
|
||||||
<include ignore_missing="yes">${config.home.path}/etc/fonts/conf.d</include>
|
|
||||||
<include ignore_missing="yes">${config.home.path}/etc/fonts/fonts.conf</include>
|
|
||||||
|
|
||||||
<dir>${config.home.path}/lib/X11/fonts</dir>
|
|
||||||
<dir>${config.home.path}/share/fonts</dir>
|
|
||||||
<dir>${profileDirectory}/lib/X11/fonts</dir>
|
|
||||||
<dir>${profileDirectory}/share/fonts</dir>
|
|
||||||
|
|
||||||
<cachedir>${config.home.path}/lib/fontconfig/cache</cachedir>
|
|
||||||
</fontconfig>
|
</fontconfig>
|
||||||
'';
|
'';
|
||||||
|
in {
|
||||||
|
"fontconfig/conf.d/10-hm-fonts.conf".text = mkFontconfigConf ''
|
||||||
|
<description>Add fonts in the Nix user profile</description>
|
||||||
|
|
||||||
|
<include ignore_missing="yes">${config.home.path}/etc/fonts/conf.d</include>
|
||||||
|
<include ignore_missing="yes">${config.home.path}/etc/fonts/fonts.conf</include>
|
||||||
|
|
||||||
|
<dir>${config.home.path}/lib/X11/fonts</dir>
|
||||||
|
<dir>${config.home.path}/share/fonts</dir>
|
||||||
|
<dir>${profileDirectory}/lib/X11/fonts</dir>
|
||||||
|
<dir>${profileDirectory}/share/fonts</dir>
|
||||||
|
|
||||||
|
<cachedir>${config.home.path}/lib/fontconfig/cache</cachedir>
|
||||||
|
'';
|
||||||
|
|
||||||
|
"fontconfig/conf.d/52-hm-default-fonts.conf".text = let
|
||||||
|
genDefault = fonts: name:
|
||||||
|
optionalString (fonts != [ ]) ''
|
||||||
|
<alias binding="same">
|
||||||
|
<family>${name}</family>
|
||||||
|
<prefer>
|
||||||
|
${
|
||||||
|
concatStringsSep "" (map (font: ''
|
||||||
|
<family>${font}</family>
|
||||||
|
'') fonts)
|
||||||
|
}
|
||||||
|
</prefer>
|
||||||
|
</alias>
|
||||||
|
'';
|
||||||
|
in mkFontconfigConf ''
|
||||||
|
<!-- Default fonts -->
|
||||||
|
${genDefault cfg.defaultFonts.sansSerif "sans-serif"}
|
||||||
|
${genDefault cfg.defaultFonts.serif "serif"}
|
||||||
|
${genDefault cfg.defaultFonts.monospace "monospace"}
|
||||||
|
${genDefault cfg.defaultFonts.emoji "emoji"}
|
||||||
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue