{ 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 home.packages and nix-env. ''; }; }; }; config = mkIf cfg.enable { home.packages = [ # 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") ]; home.extraProfileCommands = '' if [[ -d $out/lib/X11/fonts || -d $out/share/fonts ]]; then export FONTCONFIG_FILE="$(pwd)/fonts.conf" cat > $FONTCONFIG_FILE << EOF $out/lib/X11/fonts $out/share/fonts $out/lib/fontconfig/cache 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 the fontconfig directory if no files were available. if [[ -d $out/lib/fontconfig ]] ; then rmdir --ignore-fail-on-non-empty -p $out/lib/fontconfig fi ''; xdg.configFile = { "fontconfig/conf.d/10-hm-fonts.conf".text = '' ${config.home.path}/etc/fonts/conf.d ${config.home.path}/etc/fonts/fonts.conf ${config.home.path}/lib/X11/fonts ${config.home.path}/share/fonts ${profileDirectory}/lib/X11/fonts ${profileDirectory}/share/fonts ${config.home.path}/lib/fontconfig/cache ''; }; }; }