fontconfig: fix build error

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
This commit is contained in:
Robert Helgesson 2019-05-06 00:27:25 +02:00
parent 939274281a
commit b256e3a44f
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
6 changed files with 85 additions and 6 deletions

View file

@ -36,8 +36,27 @@ in
}; };
config = mkIf cfg.enable { 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 = '' home.extraProfileCommands = ''
export FONTCONFIG_FILE=$(pwd)/fonts.conf if [[ -d $out/lib/X11/fonts || -d $out/share/fonts ]]; then
export FONTCONFIG_FILE="$(pwd)/fonts.conf"
cat > $FONTCONFIG_FILE << EOF cat > $FONTCONFIG_FILE << EOF
<?xml version='1.0'?> <?xml version='1.0'?>
@ -51,8 +70,15 @@ in
${getBin pkgs.fontconfig}/bin/fc-cache -f ${getBin pkgs.fontconfig}/bin/fc-cache -f
rm -f $out/lib/fontconfig/cache/CACHEDIR.TAG 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 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 = { xdg.configFile = {

View file

@ -35,6 +35,7 @@ import nmt {
// import ./modules/systemd // import ./modules/systemd
) )
// import ./modules/home-environment // import ./modules/home-environment
// import ./modules/misc/fontconfig
// import ./modules/programs/bash // import ./modules/programs/bash
// import ./modules/programs/ssh // import ./modules/programs/ssh
// import ./modules/programs/tmux // import ./modules/programs/tmux

View file

@ -0,0 +1,5 @@
{
fontconfig-no-font-package = ./no-font-package.nix;
fontconfig-single-font-package = ./single-font-package.nix;
fontconfig-multiple-font-packages = ./multiple-font-packages.nix;
}

View file

@ -0,0 +1,15 @@
{ config, lib, pkgs, ... }:
with lib;
{
config = {
home.packages = [ pkgs.comic-relief pkgs.unifont ];
fonts.fontconfig.enable = true;
nmt.script = ''
assertDirectoryNotEmpty home-path/lib/fontconfig/cache
'';
};
}

View file

@ -0,0 +1,17 @@
{ config, lib, pkgs, ... }:
with lib;
{
config = {
home.packages = [
# Look, no font!
];
fonts.fontconfig.enable = true;
nmt.script = ''
assertPathNotExists home-path/lib/fontconfig/cache
'';
};
}

View file

@ -0,0 +1,15 @@
{ config, lib, pkgs, ... }:
with lib;
{
config = {
home.packages = [ pkgs.comic-relief ];
fonts.fontconfig.enable = true;
nmt.script = ''
assertDirectoryNotEmpty home-path/lib/fontconfig/cache
'';
};
}