diff --git a/nixos/modules/config/fonts/fontconfig-ultimate.nix b/nixos/modules/config/fonts/fontconfig-ultimate.nix index 47d7cc5924d4..02568f9de51e 100644 --- a/nixos/modules/config/fonts/fontconfig-ultimate.nix +++ b/nixos/modules/config/fonts/fontconfig-ultimate.nix @@ -3,84 +3,6 @@ with lib; let fcBool = x: if x then "true" else "false"; - cfg = config.fonts.fontconfig.ultimate; - fontconfigUltimateConf = pkgs.writeText "ultimate-conf" '' - - - - - ${optionalString (!cfg.allowBitmaps) '' - - - - - false - - - - ''} - - ${optionalString cfg.allowType1 '' - - - - - - Type 1 - - - - - ''} - - - - - ${fcBool cfg.useEmbeddedBitmaps} - - - - - - - ${fcBool cfg.forceAutohint} - - - - - - - ${fcBool cfg.renderMonoTTFAsBitmap} - - - - - ''; - confPkg = - let version = pkgs.fontconfig.configVersion; - in pkgs.runCommand "font-ultimate-conf" {} '' - mkdir -p $out/etc/fonts/{,${version}/}conf.d/ - - cp ${fontconfigUltimateConf} \ - $out/etc/fonts/conf.d/52-fontconfig-ultimate.conf - - cp ${fontconfigUltimateConf} \ - $out/etc/fonts/${version}/conf.d/52-fontconfig-ultimate.conf - - ${optionalString (cfg.substitutions != "none") '' - cp ${pkgs.fontconfig-ultimate.confd}/etc/fonts/presets/${cfg.substitutions}/*.conf \ - $out/etc/fonts/conf.d/ - cp ${pkgs.fontconfig-ultimate.confd}/etc/fonts/presets/${cfg.substitutions}/*.conf \ - $out/etc/fonts/${version}/conf.d/ - ''} - - ln -s ${pkgs.fontconfig-ultimate.confd}/etc/fonts/conf.d/*.conf \ - $out/etc/fonts/conf.d/ - - ln -s ${pkgs.fontconfig-ultimate.confd}/etc/fonts/conf.d/*.conf \ - $out/etc/fonts/${version}/conf.d/ - ''; - in { @@ -193,11 +115,78 @@ in }; - config = mkIf (config.fonts.fontconfig.enable && cfg.enable) { + config = + let ultimate = config.fonts.fontconfig.ultimate; + fontconfigUltimateConf = '' + + + - fonts.fontconfig.confPkgs = [ confPkg ]; - - environment.variables = cfg.rendering; + ${optionalString (!ultimate.allowBitmaps) '' + + + + + false + + + + ''} + + ${optionalString ultimate.allowType1 '' + + + + + + Type 1 + + + + + ''} + + + + + ${fcBool ultimate.useEmbeddedBitmaps} + + + + + + + ${fcBool ultimate.forceAutohint} + + + + + + + ${fcBool ultimate.renderMonoTTFAsBitmap} + + + + ${optionalString (ultimate.substitutions != "none") '' + + ${pkgs.fontconfig-ultimate.confd}/etc/fonts/presets/${ultimate.substitutions} + ''} + + ${pkgs.fontconfig-ultimate.confd}/etc/fonts/conf.d + + + ''; + in mkIf (config.fonts.fontconfig.enable && ultimate.enable) { + + environment.etc."fonts/conf.d/52-fontconfig-ultimate.conf" = { + text = fontconfigUltimateConf; + }; + + environment.etc."fonts/${pkgs.fontconfig.configVersion}/conf.d/52-fontconfig-ultimate.conf" = { + text = fontconfigUltimateConf; + }; + + environment.variables = ultimate.rendering; }; diff --git a/nixos/modules/config/fonts/fontconfig.nix b/nixos/modules/config/fonts/fontconfig.nix index fcf5add45197..1eaebe4b2bbd 100644 --- a/nixos/modules/config/fonts/fontconfig.nix +++ b/nixos/modules/config/fonts/fontconfig.nix @@ -2,121 +2,6 @@ with lib; -let cfg = config.fonts.fontconfig; - fcBool = x: "" + (if x then "true" else "false") + ""; - renderConf = pkgs.writeText "render-conf" '' - - - - - - - - ${fcBool cfg.hinting.enable} - - - ${fcBool cfg.hinting.autohint} - - - hint${cfg.hinting.style} - - - ${fcBool cfg.antialias} - - - ${cfg.subpixel.rgba} - - - lcd${cfg.subpixel.lcdfilter} - - - - ${optionalString (cfg.dpi != 0) '' - - - ${toString cfg.dpi} - - - ''} - - - ''; - genericAliasConf = - let genDefault = fonts: name: - optionalString (fonts != []) '' - - ${name} - - ${concatStringsSep "" - (map (font: '' - ${font} - '') fonts)} - - - ''; - in - pkgs.writeText "generic-alias-conf" '' - - - - - - ${genDefault cfg.defaultFonts.sansSerif "sans-serif"} - - ${genDefault cfg.defaultFonts.serif "serif"} - - ${genDefault cfg.defaultFonts.monospace "monospace"} - - - ''; - cacheConf = let - cache = fontconfig: pkgs.makeFontsCache { inherit fontconfig; fontDirectories = config.fonts.fonts; }; - in - pkgs.writeText "cache-conf" '' - - - - - ${concatStringsSep "\n" (map (font: "${font}") config.fonts.fonts)} - - ${cache pkgs.fontconfig} - ${optionalString (pkgs.stdenv.isx86_64 && cfg.cache32Bit) '' - ${cache pkgs.pkgsi686Linux.fontconfig} - ''} - - ''; - userConf = pkgs.writeText "user-conf" '' - - - - fontconfig/conf.d - fontconfig/fonts.conf - - ''; - fontsConf = pkgs.makeFontsConf { fontconfig = pkgs.fontconfig_210; fontDirectories = config.fonts.fonts; }; - confPkg = - let version = pkgs.fontconfig.configVersion; - in pkgs.runCommand "fontconfig-conf" {} '' - mkdir -p $out/etc/fonts/{,${version}/}conf.d - - ln -s ${fontsConf} $out/etc/fonts/fonts.conf - - ln -s ${pkgs.fontconfig.out}/etc/fonts/fonts.conf $out/etc/fonts/${version}/fonts.conf - ln -s ${pkgs.fontconfig.out}/etc/fonts/conf.d/* $out/etc/fonts/${version}/conf.d/ - - ln -s ${renderConf} $out/etc/fonts/conf.d/10-nixos-rendering.conf - ln -s ${genericAliasConf} $out/etc/fonts/conf.d/60-nixos-generic-alias.conf - - ln -s ${cacheConf} $out/etc/fonts/${version}/conf.d/00-nixos.conf - - ln -s ${renderConf} $out/etc/fonts/${version}/conf.d/10-nixos-rendering.conf - ln -s ${genericAliasConf} $out/etc/fonts/${version}/conf.d/30-nixos-generic-alias.conf - - ${optionalString cfg.includeUserConf - "ln -s ${userConf} $out/etc/fonts/${version}/conf.d/99-user.conf"} - - ''; -in { options = { @@ -136,15 +21,6 @@ in ''; }; - confPkgs = mkOption { - internal = true; - type = with types; listOf path; - default = [ ]; - description = '' - Fontconfig configuration packages. - ''; - }; - antialias = mkOption { type = types.bool; default = true; @@ -267,17 +143,135 @@ in }; - config = mkIf cfg.enable { - fonts.fontconfig.confPkgs = [ confPkg ]; + config = + let fontconfig = config.fonts.fontconfig; + fcBool = x: "" + (if x then "true" else "false") + ""; + renderConf = '' + + + - environment.etc.fonts.source = - let fontConf = pkgs.symlinkJoin { - name = "fontconfig-etc"; - paths = cfg.confPkgs; - }; - in "${fontConf}/etc/fonts/"; + + + + ${fcBool fontconfig.hinting.enable} + + + ${fcBool fontconfig.hinting.autohint} + + + hint${fontconfig.hinting.style} + + + ${fcBool fontconfig.antialias} + + + ${fontconfig.subpixel.rgba} + + + lcd${fontconfig.subpixel.lcdfilter} + + - environment.systemPackages = [ pkgs.fontconfig ]; - }; + ${optionalString (fontconfig.dpi != 0) '' + + + ${toString fontconfig.dpi} + + + ''} + + + ''; + genericAliasConf = '' + + + + + + ${optionalString (fontconfig.defaultFonts.sansSerif != []) '' + + sans-serif + + ${concatStringsSep "\n" + (map (font: "${font}") + fontconfig.defaultFonts.sansSerif)} + + + ''} + ${optionalString (fontconfig.defaultFonts.serif != []) '' + + serif + + ${concatStringsSep "\n" + (map (font: "${font}") + fontconfig.defaultFonts.serif)} + + + ''} + ${optionalString (fontconfig.defaultFonts.monospace != []) '' + + monospace + + ${concatStringsSep "\n" + (map (font: "${font}") + fontconfig.defaultFonts.monospace)} + + + ''} + + + ''; + in mkIf fontconfig.enable { + + # Fontconfig 2.10 backward compatibility + + # Bring in the default (upstream) fontconfig configuration, only for fontconfig 2.10 + environment.etc."fonts/fonts.conf".source = + pkgs.makeFontsConf { fontconfig = pkgs.fontconfig_210; fontDirectories = config.fonts.fonts; }; + + environment.etc."fonts/conf.d/10-nixos-rendering.conf".text = renderConf; + environment.etc."fonts/conf.d/60-nixos-generic-alias.conf".text = genericAliasConf; + + # Versioned fontconfig > 2.10. Take shared fonts.conf from fontconfig. + # Otherwise specify only font directories. + environment.etc."fonts/${pkgs.fontconfig.configVersion}/fonts.conf".source = + "${pkgs.fontconfig.out}/etc/fonts/fonts.conf"; + + environment.etc."fonts/${pkgs.fontconfig.configVersion}/conf.d/00-nixos.conf".text = + let + cache = fontconfig: pkgs.makeFontsCache { inherit fontconfig; fontDirectories = config.fonts.fonts; }; + in '' + + + + + ${concatStringsSep "\n" (map (font: "${font}") config.fonts.fonts)} + + ${cache pkgs.fontconfig} + ${optionalString (pkgs.stdenv.isx86_64 && config.fonts.fontconfig.cache32Bit) '' + ${cache pkgs.pkgsi686Linux.fontconfig} + ''} + + ''; + + environment.etc."fonts/${pkgs.fontconfig.configVersion}/conf.d/10-nixos-rendering.conf".text = renderConf; + environment.etc."fonts/${pkgs.fontconfig.configVersion}/conf.d/60-nixos-generic-alias.conf".text = genericAliasConf; + + environment.etc."fonts/${pkgs.fontconfig.configVersion}/conf.d/99-user.conf" = { + enable = fontconfig.includeUserConf; + text = '' + + + + fontconfig/conf.d + fontconfig/fonts.conf + + ''; + }; + + environment.systemPackages = [ pkgs.fontconfig ]; + + }; } diff --git a/pkgs/development/libraries/fontconfig/default.nix b/pkgs/development/libraries/fontconfig/default.nix index f18ea5948f15..6acf1ebce29c 100644 --- a/pkgs/development/libraries/fontconfig/default.nix +++ b/pkgs/development/libraries/fontconfig/default.nix @@ -68,6 +68,7 @@ stdenv.mkDerivation rec { cd "$out/etc/fonts" rm conf.d/{50-user,51-local}.conf "${libxslt.bin}/bin/xsltproc" --stringparam fontDirectories "${fontbhttf}" \ + --stringparam fontconfig "$out" \ --stringparam fontconfigConfigVersion "${configVersion}" \ --path $out/share/xml/fontconfig \ ${./make-fonts-conf.xsl} $out/etc/fonts/fonts.conf \ diff --git a/pkgs/development/libraries/fontconfig/make-fonts-conf.xsl b/pkgs/development/libraries/fontconfig/make-fonts-conf.xsl index dddbbe9e516b..b59fcd0187b8 100644 --- a/pkgs/development/libraries/fontconfig/make-fonts-conf.xsl +++ b/pkgs/development/libraries/fontconfig/make-fonts-conf.xsl @@ -28,6 +28,8 @@ /var/cache/fontconfig + + /etc/fonts/conf.d /etc/fonts//conf.d