2017-10-09 18:37:57 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.fonts.fontconfig;
|
|
|
|
|
2019-04-21 19:31:44 +02:00
|
|
|
profileDirectory = config.home.profileDirectory;
|
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
in {
|
2017-10-09 18:37:57 +02:00
|
|
|
meta.maintainers = [ maintainers.rycee ];
|
|
|
|
|
2019-04-21 19:31:44 +02:00
|
|
|
imports = [
|
2020-02-02 00:39:17 +01:00
|
|
|
(mkRenamedOptionModule [ "fonts" "fontconfig" "enableProfileFonts" ] [
|
|
|
|
"fonts"
|
|
|
|
"fontconfig"
|
|
|
|
"enable"
|
|
|
|
])
|
2019-04-21 19:31:44 +02:00
|
|
|
];
|
|
|
|
|
2017-10-09 18:37:57 +02:00
|
|
|
options = {
|
|
|
|
fonts.fontconfig = {
|
2019-04-21 19:31:44 +02:00
|
|
|
enable = mkOption {
|
2017-10-09 18:37:57 +02:00
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
2019-04-21 19:31:44 +02:00
|
|
|
Whether to enable fontconfig configuration. This will, for
|
|
|
|
example, allow fontconfig to discover fonts and
|
|
|
|
configurations installed through
|
2017-10-09 18:37:57 +02:00
|
|
|
<varname>home.packages</varname> and
|
|
|
|
<command>nix-env</command>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-04-21 19:31:44 +02:00
|
|
|
config = mkIf cfg.enable {
|
2019-05-06 00:27:25 +02:00
|
|
|
home.packages = [
|
2021-10-03 23:03:26 +02: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-06 00:27:25 +02:00
|
|
|
];
|
|
|
|
|
2019-04-21 19:31:44 +02:00
|
|
|
home.extraProfileCommands = ''
|
2019-05-06 00:27:25 +02:00
|
|
|
if [[ -d $out/lib/X11/fonts || -d $out/share/fonts ]]; then
|
|
|
|
export FONTCONFIG_FILE="$(pwd)/fonts.conf"
|
2019-04-21 19:31:44 +02:00
|
|
|
|
2019-05-06 00:27:25 +02:00
|
|
|
cat > $FONTCONFIG_FILE << EOF
|
2017-10-09 18:37:57 +02:00
|
|
|
<?xml version='1.0'?>
|
|
|
|
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
|
|
|
|
<fontconfig>
|
2019-04-21 19:31:44 +02:00
|
|
|
<dir>$out/lib/X11/fonts</dir>
|
|
|
|
<dir>$out/share/fonts</dir>
|
|
|
|
<cachedir>$out/lib/fontconfig/cache</cachedir>
|
2017-10-09 18:37:57 +02:00
|
|
|
</fontconfig>
|
2019-04-21 19:31:44 +02:00
|
|
|
EOF
|
|
|
|
|
2019-05-06 00:27:25 +02: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 19:31:44 +02:00
|
|
|
|
2021-10-03 23:03:26 +02:00
|
|
|
# Remove the fontconfig directory if no files were available.
|
2019-05-06 00:27:25 +02:00
|
|
|
rmdir --ignore-fail-on-non-empty -p $out/lib/fontconfig
|
2017-10-09 18:37:57 +02:00
|
|
|
'';
|
2019-04-21 19:31:44 +02:00
|
|
|
|
|
|
|
xdg.configFile = {
|
|
|
|
"fontconfig/conf.d/10-hm-fonts.conf".text = ''
|
|
|
|
<?xml version='1.0'?>
|
|
|
|
|
|
|
|
<!-- Generated by Home Manager. -->
|
|
|
|
|
|
|
|
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
|
|
|
|
<fontconfig>
|
|
|
|
<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>
|
|
|
|
'';
|
|
|
|
};
|
2017-10-09 18:37:57 +02:00
|
|
|
};
|
|
|
|
}
|