fork/home-manager
git clone https://git.julia.blue/fork/home-manager
75790441
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6 7cfg = config . fonts . fontconfig ; 8 9profileDirectory = config . home . profileDirectory ; 10 11in { 12meta . maintainers = [ maintainers . rycee ]; 13 14imports = [ 15( mkRenamedOptionModule [ "fonts" "fontconfig" "enableProfileFonts" ] [ 16"fonts" 17"fontconfig" 18"enable" 19]) 20]; 21 22options = { 23fonts . fontconfig = { 24enable = mkOption { 25type = types . bool ; 26default = false ; 27description = '' 28Whether to enable fontconfig configuration. This will, for 29example, allow fontconfig to discover fonts and 30configurations installed through 31{var}`home.packages` and 32{command}`nix-env`. 33'' ; 34}; 35}; 36}; 37 38config = mkIf cfg . enable { 39home . packages = [ 40# Make sure that buildEnv creates a real directory path so that we avoid 41# trying to write to a read-only location. 42( pkgs . runCommandLocal "dummy-fc-dir1" { } "mkdir -p $out/lib/fontconfig" ) 43( pkgs . runCommandLocal "dummy-fc-dir2" { } "mkdir -p $out/lib/fontconfig" ) 44]; 45 46home . extraProfileCommands = '' 47if [[ -d $out/lib/X11/fonts || -d $out/share/fonts ]]; then 48export FONTCONFIG_FILE="$(pwd)/fonts.conf" 49 50cat > $FONTCONFIG_FILE << EOF 51<?xml version='1.0'?> 52<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'> 53<fontconfig> 54<dir>$out/lib/X11/fonts</dir> 55<dir>$out/share/fonts</dir> 56<cachedir>$out/lib/fontconfig/cache</cachedir> 57</fontconfig> 58EOF 59 60${ getBin pkgs . fontconfig } /bin/fc-cache -f 61rm -f $out/lib/fontconfig/cache/CACHEDIR.TAG 62rmdir --ignore-fail-on-non-empty -p $out/lib/fontconfig/cache 63 64rm "$FONTCONFIG_FILE" 65unset FONTCONFIG_FILE 66fi 67 68# Remove the fontconfig directory if no files were available. 69if [[ -d $out/lib/fontconfig ]] ; then 70rmdir --ignore-fail-on-non-empty -p $out/lib/fontconfig 71fi 72'' ; 73 74xdg . configFile = { 75"fontconfig/conf.d/10-hm-fonts.conf" . text = '' 76<?xml version='1.0'?> 77 78<!-- Generated by Home Manager. --> 79 80<!DOCTYPE fontconfig SYSTEM 'urn:fontconfig:fonts.dtd'> 81<fontconfig> 82<description>Add fonts in the Nix user profile</description> 83 84<include ignore_missing="yes"> ${ config . home . path } /etc/fonts/conf.d</include> 85<include ignore_missing="yes"> ${ config . home . path } /etc/fonts/fonts.conf</include> 86 87<dir> ${ config . home . path } /lib/X11/fonts</dir> 88<dir> ${ config . home . path } /share/fonts</dir> 89<dir> ${ profileDirectory } /lib/X11/fonts</dir> 90<dir> ${ profileDirectory } /share/fonts</dir> 91 92<cachedir> ${ config . home . path } /lib/fontconfig/cache</cachedir> 93</fontconfig> 94'' ; 95}; 96}; 97}