From e021ee13f909e6eb7c019b5cd1acf9eac0cd0f67 Mon Sep 17 00:00:00 2001 From: Colin Date: Wed, 19 Mar 2025 06:59:49 +0000 Subject: [PATCH 1/2] makeFontsCache: fix cross compilation lifting the `callPackage` to scope level ensures splicing works as expected. we still need to emulate fc-cache to produce usable cache entries though. --- .../libraries/fontconfig/make-fonts-cache.nix | 18 ++++++++++++++---- pkgs/top-level/all-packages.nix | 5 +---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/pkgs/development/libraries/fontconfig/make-fonts-cache.nix b/pkgs/development/libraries/fontconfig/make-fonts-cache.nix index a1ac7d1b9859..9054cf6756ba 100644 --- a/pkgs/development/libraries/fontconfig/make-fonts-cache.nix +++ b/pkgs/development/libraries/fontconfig/make-fonts-cache.nix @@ -1,13 +1,20 @@ { - runCommand, - lib, + buildPackages, fontconfig, + lib, + runCommand, + stdenv, +}: +let + fontconfig' = fontconfig; +in +{ + fontconfig ? fontconfig', fontDirectories, }: runCommand "fc-cache" { - nativeBuildInputs = [ fontconfig.bin ]; preferLocalBuild = true; allowSubstitutes = false; passAsFile = [ "fontDirs" ]; @@ -29,8 +36,11 @@ runCommand "fc-cache" cat "$fontDirsPath" >> fonts.conf echo "" >> fonts.conf + # N.B.: fc-cache keys its cache entries by architecture. + # We must invoke the host `fc-cache` (not the build fontconfig) if we want + # the cache to be usable by the host. mkdir -p $out - fc-cache -sv + ${stdenv.hostPlatform.emulator buildPackages} ${lib.getExe' fontconfig "fc-cache"} -sv # This is not a cache dir in the normal sense -- it won't be automatically # recreated. diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index db392a2b84ea..9d8ccbae637d 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -8764,10 +8764,7 @@ with pkgs; makeFontsConf = callPackage ../development/libraries/fontconfig/make-fonts-conf.nix { }; - makeFontsCache = let fontconfig_ = fontconfig; in {fontconfig ? fontconfig_, fontDirectories}: - callPackage ../development/libraries/fontconfig/make-fonts-cache.nix { - inherit fontconfig fontDirectories; - }; + makeFontsCache = callPackage ../development/libraries/fontconfig/make-fonts-cache.nix { }; freenect = callPackage ../development/libraries/freenect { inherit (darwin.apple_sdk.frameworks) Cocoa GLUT; From 9435a2b422f090b25f4aa5aee53be1341626672d Mon Sep 17 00:00:00 2001 From: Colin Date: Wed, 19 Mar 2025 07:53:24 +0000 Subject: [PATCH 2/2] nixos/fonts: ship fontconfig caches even for cross-compiled hosts --- nixos/modules/config/fonts/fontconfig.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixos/modules/config/fonts/fontconfig.nix b/nixos/modules/config/fonts/fontconfig.nix index 984daec20431..89c537ff3868 100644 --- a/nixos/modules/config/fonts/fontconfig.nix +++ b/nixos/modules/config/fonts/fontconfig.nix @@ -58,7 +58,7 @@ let ${lib.concatStringsSep "\n" (map (font: "${font}") config.fonts.packages)} - ${lib.optionalString (pkgs.stdenv.hostPlatform == pkgs.stdenv.buildPlatform) '' + ${lib.optionalString (pkgs.stdenv.hostPlatform.emulatorAvailable pkgs.buildPackages) '' ${cache} ${lib.optionalString (pkgs.stdenv.hostPlatform.isx86_64 && cfg.cache32Bit) ''