diff --git a/modules/misc/fontconfig.nix b/modules/misc/fontconfig.nix index 9f3def77..8dbcce53 100644 --- a/modules/misc/fontconfig.nix +++ b/modules/misc/fontconfig.nix @@ -36,10 +36,29 @@ in }; config = mkIf cfg.enable { - home.extraProfileCommands = '' - export FONTCONFIG_FILE=$(pwd)/fonts.conf + # 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"; + }) - cat > $FONTCONFIG_FILE << EOF + (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 @@ -49,10 +68,17 @@ in EOF - ${getBin pkgs.fontconfig}/bin/fc-cache -f - rm -f $out/lib/fontconfig/cache/CACHEDIR.TAG + ${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 - unset FONTCONFIG_FILE + 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 = { diff --git a/tests/default.nix b/tests/default.nix index d186ee04..91942a65 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -35,6 +35,7 @@ import nmt { // import ./modules/systemd ) // import ./modules/home-environment + // import ./modules/misc/fontconfig // import ./modules/programs/bash // import ./modules/programs/ssh // import ./modules/programs/tmux diff --git a/tests/modules/misc/fontconfig/default.nix b/tests/modules/misc/fontconfig/default.nix new file mode 100644 index 00000000..b669e1c3 --- /dev/null +++ b/tests/modules/misc/fontconfig/default.nix @@ -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; +} diff --git a/tests/modules/misc/fontconfig/multiple-font-packages.nix b/tests/modules/misc/fontconfig/multiple-font-packages.nix new file mode 100644 index 00000000..3845b4ba --- /dev/null +++ b/tests/modules/misc/fontconfig/multiple-font-packages.nix @@ -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 + ''; + }; +} diff --git a/tests/modules/misc/fontconfig/no-font-package.nix b/tests/modules/misc/fontconfig/no-font-package.nix new file mode 100644 index 00000000..c4c687a1 --- /dev/null +++ b/tests/modules/misc/fontconfig/no-font-package.nix @@ -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 + ''; + }; +} diff --git a/tests/modules/misc/fontconfig/single-font-package.nix b/tests/modules/misc/fontconfig/single-font-package.nix new file mode 100644 index 00000000..b70bdf8a --- /dev/null +++ b/tests/modules/misc/fontconfig/single-font-package.nix @@ -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 + ''; + }; +}