mirror of
https://github.com/nix-community/home-manager
synced 2024-11-23 13:13:26 +00:00
b256e3a44f
This fixes a build error occurring when building a configuration having fontconfig enabled and `home.packages` only containing one package installing things to `/lib`. Also adds a number of test cases to verify the fontconfig cache generation functionality. Fixes #703
105 lines
2.8 KiB
Nix
105 lines
2.8 KiB
Nix
{ config, lib, pkgs, ... }:
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
cfg = config.fonts.fontconfig;
|
|
|
|
profileDirectory = config.home.profileDirectory;
|
|
|
|
in
|
|
|
|
{
|
|
meta.maintainers = [ maintainers.rycee ];
|
|
|
|
imports = [
|
|
(mkRenamedOptionModule
|
|
[ "fonts" "fontconfig" "enableProfileFonts" ]
|
|
[ "fonts" "fontconfig" "enable" ])
|
|
];
|
|
|
|
options = {
|
|
fonts.fontconfig = {
|
|
enable = mkOption {
|
|
type = types.bool;
|
|
default = false;
|
|
description = ''
|
|
Whether to enable fontconfig configuration. This will, for
|
|
example, allow fontconfig to discover fonts and
|
|
configurations installed through
|
|
<varname>home.packages</varname> and
|
|
<command>nix-env</command>.
|
|
'';
|
|
};
|
|
};
|
|
};
|
|
|
|
config = mkIf cfg.enable {
|
|
# Create two dummy files in /lib/fontconfig to make sure that
|
|
# buildEnv creates a real directory path. These files are removed
|
|
# in home.extraProfileCommands below so the packages will not
|
|
# become "runtime" dependencies.
|
|
home.packages = [
|
|
(pkgs.writeTextFile {
|
|
name = "hm-dummy1";
|
|
destination = "/lib/fontconfig/hm-dummy1";
|
|
text = "dummy";
|
|
})
|
|
|
|
(pkgs.writeTextFile {
|
|
name = "hm-dummy2";
|
|
destination = "/lib/fontconfig/hm-dummy2";
|
|
text = "dummy";
|
|
})
|
|
];
|
|
|
|
home.extraProfileCommands = ''
|
|
if [[ -d $out/lib/X11/fonts || -d $out/share/fonts ]]; then
|
|
export FONTCONFIG_FILE="$(pwd)/fonts.conf"
|
|
|
|
cat > $FONTCONFIG_FILE << EOF
|
|
<?xml version='1.0'?>
|
|
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
|
|
<fontconfig>
|
|
<dir>$out/lib/X11/fonts</dir>
|
|
<dir>$out/share/fonts</dir>
|
|
<cachedir>$out/lib/fontconfig/cache</cachedir>
|
|
</fontconfig>
|
|
EOF
|
|
|
|
${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
|
|
|
|
# Remove hacky dummy files.
|
|
rm $out/lib/fontconfig/hm-dummy?
|
|
rmdir --ignore-fail-on-non-empty -p $out/lib/fontconfig
|
|
'';
|
|
|
|
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>
|
|
'';
|
|
};
|
|
};
|
|
}
|