diff --git a/nixos/modules/config/fonts/fontconfig.nix b/nixos/modules/config/fonts/fontconfig.nix index be6662decea..e078a75b295 100644 --- a/nixos/modules/config/fonts/fontconfig.nix +++ b/nixos/modules/config/fonts/fontconfig.nix @@ -129,6 +129,14 @@ with lib; }; + cache32Bit = mkOption { + default = false; + type = types.bool; + description = '' + Generate system fonts cache for 32-bit applications. + ''; + }; + }; }; @@ -231,12 +239,19 @@ with lib; "${pkgs.fontconfig}/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} + ''} ''; diff --git a/pkgs/development/libraries/fontconfig/make-fonts-cache.nix b/pkgs/development/libraries/fontconfig/make-fonts-cache.nix new file mode 100644 index 00000000000..1321948c3c8 --- /dev/null +++ b/pkgs/development/libraries/fontconfig/make-fonts-cache.nix @@ -0,0 +1,27 @@ +{ runCommand, lib, writeText, fontconfig, fontbhttf, fontDirectories }: + +runCommand "fc-cache" + rec { + buildInputs = [ fontconfig ]; + passAsFile = [ "fontDirs" ]; + fontDirs = '' + + ${lib.concatStringsSep "\n" (map (font: "${font}") fontDirectories)} + ''; + } + '' + export FONTCONFIG_FILE=$(pwd)/fonts.conf + + cat > fonts.conf << EOF + + + + ${fontconfig}/etc/fonts/fonts.conf + $out + EOF + cat "$fontDirsPath" >> fonts.conf + echo "" >> fonts.conf + + mkdir -p $out + fc-cache -sv + '' diff --git a/pkgs/development/libraries/fontconfig/make-fonts-conf.xsl b/pkgs/development/libraries/fontconfig/make-fonts-conf.xsl index 1b79834c894..b59fcd0187b 100644 --- a/pkgs/development/libraries/fontconfig/make-fonts-conf.xsl +++ b/pkgs/development/libraries/fontconfig/make-fonts-conf.xsl @@ -23,16 +23,16 @@ - - /etc/fonts/conf.d - - /etc/fonts//conf.d - fontconfig /var/cache/fontconfig + + /etc/fonts/conf.d + + /etc/fonts//conf.d + fonts diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index cfa474d5b1f..6e743e2d713 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -6520,6 +6520,11 @@ let inherit fontconfig fontDirectories; }; + makeFontsCache = let fontconfig_ = fontconfig; in {fontconfig ? fontconfig_, fontDirectories}: + callPackage ../development/libraries/fontconfig/make-fonts-cache.nix { + inherit fontconfig fontDirectories; + }; + freealut = callPackage ../development/libraries/freealut { }; freeglut = callPackage ../development/libraries/freeglut { };