2022-02-18 23:34:39 +00:00
|
|
|
# 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
|
|
|
|
|
2017-10-09 16:37:57 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.fonts.fontconfig;
|
|
|
|
|
2019-04-21 17:31:44 +00:00
|
|
|
profileDirectory = config.home.profileDirectory;
|
|
|
|
|
2020-02-01 23:39:17 +00:00
|
|
|
in {
|
2017-10-09 16:37:57 +00:00
|
|
|
meta.maintainers = [ maintainers.rycee ];
|
|
|
|
|
2019-04-21 17:31:44 +00:00
|
|
|
imports = [
|
2020-02-01 23:39:17 +00:00
|
|
|
(mkRenamedOptionModule [ "fonts" "fontconfig" "enableProfileFonts" ] [
|
|
|
|
"fonts"
|
|
|
|
"fontconfig"
|
|
|
|
"enable"
|
|
|
|
])
|
2019-04-21 17:31:44 +00:00
|
|
|
];
|
|
|
|
|
2017-10-09 16:37:57 +00:00
|
|
|
options = {
|
|
|
|
fonts.fontconfig = {
|
2019-04-21 17:31:44 +00:00
|
|
|
enable = mkOption {
|
2017-10-09 16:37:57 +00:00
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2023-07-01 23:45:18 +00:00
|
|
|
description = ''
|
2019-04-21 17:31:44 +00:00
|
|
|
Whether to enable fontconfig configuration. This will, for
|
|
|
|
example, allow fontconfig to discover fonts and
|
|
|
|
configurations installed through
|
2023-06-30 23:30:13 +00:00
|
|
|
{var}`home.packages` and
|
|
|
|
{command}`nix-env`.
|
2017-10-09 16:37:57 +00:00
|
|
|
'';
|
|
|
|
};
|
2022-02-18 23:34:39 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2017-10-09 16:37:57 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-04-21 17:31:44 +00:00
|
|
|
config = mkIf cfg.enable {
|
2019-05-05 22:27:25 +00:00
|
|
|
home.packages = [
|
2021-10-03 21:03:26 +00:00
|
|
|
# Make sure that buildEnv creates a real directory path so that we avoid
|
|
|
|
# trying to write to a read-only location.
|
|
|
|
(pkgs.runCommandLocal "dummy-fc-dir1" { } "mkdir -p $out/lib/fontconfig")
|
|
|
|
(pkgs.runCommandLocal "dummy-fc-dir2" { } "mkdir -p $out/lib/fontconfig")
|
2019-05-05 22:27:25 +00:00
|
|
|
];
|
|
|
|
|
2019-04-21 17:31:44 +00:00
|
|
|
home.extraProfileCommands = ''
|
2019-05-05 22:27:25 +00:00
|
|
|
if [[ -d $out/lib/X11/fonts || -d $out/share/fonts ]]; then
|
|
|
|
export FONTCONFIG_FILE="$(pwd)/fonts.conf"
|
2019-04-21 17:31:44 +00:00
|
|
|
|
2019-05-05 22:27:25 +00:00
|
|
|
cat > $FONTCONFIG_FILE << EOF
|
2017-10-09 16:37:57 +00:00
|
|
|
<?xml version='1.0'?>
|
|
|
|
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
|
|
|
|
<fontconfig>
|
2019-04-21 17:31:44 +00:00
|
|
|
<dir>$out/lib/X11/fonts</dir>
|
|
|
|
<dir>$out/share/fonts</dir>
|
|
|
|
<cachedir>$out/lib/fontconfig/cache</cachedir>
|
2017-10-09 16:37:57 +00:00
|
|
|
</fontconfig>
|
2019-04-21 17:31:44 +00:00
|
|
|
EOF
|
|
|
|
|
2019-05-05 22:27:25 +00:00
|
|
|
${getBin pkgs.fontconfig}/bin/fc-cache -f
|
|
|
|
rm -f $out/lib/fontconfig/cache/CACHEDIR.TAG
|
|
|
|
rmdir --ignore-fail-on-non-empty -p $out/lib/fontconfig/cache
|
|
|
|
|
|
|
|
rm "$FONTCONFIG_FILE"
|
|
|
|
unset FONTCONFIG_FILE
|
|
|
|
fi
|
2019-04-21 17:31:44 +00:00
|
|
|
|
2021-10-03 21:03:26 +00:00
|
|
|
# Remove the fontconfig directory if no files were available.
|
2021-10-06 12:50:38 +00:00
|
|
|
if [[ -d $out/lib/fontconfig ]] ; then
|
|
|
|
rmdir --ignore-fail-on-non-empty -p $out/lib/fontconfig
|
|
|
|
fi
|
2017-10-09 16:37:57 +00:00
|
|
|
'';
|
2019-04-21 17:31:44 +00:00
|
|
|
|
2022-02-18 23:34:39 +00:00
|
|
|
xdg.configFile = let
|
|
|
|
mkFontconfigConf = conf: ''
|
2019-04-21 17:31:44 +00:00
|
|
|
<?xml version='1.0'?>
|
|
|
|
|
|
|
|
<!-- Generated by Home Manager. -->
|
|
|
|
|
2023-06-17 20:16:09 +00:00
|
|
|
<!DOCTYPE fontconfig SYSTEM 'urn:fontconfig:fonts.dtd'>
|
2019-04-21 17:31:44 +00:00
|
|
|
<fontconfig>
|
2022-02-18 23:34:39 +00:00
|
|
|
${conf}
|
|
|
|
</fontconfig>
|
|
|
|
'';
|
|
|
|
in {
|
|
|
|
"fontconfig/conf.d/10-hm-fonts.conf".text = mkFontconfigConf ''
|
|
|
|
<description>Add fonts in the Nix user profile</description>
|
2023-06-17 20:16:09 +00:00
|
|
|
|
2022-02-18 23:34:39 +00:00
|
|
|
<include ignore_missing="yes">${config.home.path}/etc/fonts/conf.d</include>
|
|
|
|
<include ignore_missing="yes">${config.home.path}/etc/fonts/fonts.conf</include>
|
2019-04-21 17:31:44 +00:00
|
|
|
|
2022-02-18 23:34:39 +00:00
|
|
|
<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>
|
2019-04-21 17:31:44 +00:00
|
|
|
|
2022-02-18 23:34:39 +00:00
|
|
|
<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"}
|
2019-04-21 17:31:44 +00:00
|
|
|
'';
|
|
|
|
};
|
2017-10-09 16:37:57 +00:00
|
|
|
};
|
|
|
|
}
|