fotnconfig: push cross patches upstream (partially)

This commit is contained in:
2025-03-19 14:55:41 +00:00
parent 208a88b8ca
commit 0dc62d7fe2
2 changed files with 20 additions and 28 deletions

View File

@@ -9,31 +9,11 @@
let
# see: <repo:nixos/nixpkgs:nixos/modules/config/fonts/fontconfig.nix>
# and: <repo:nixos/nixpkgs:pkgs/development/libraries/fontconfig/make-fonts-cache.nix>
# nixpkgs creates a fontconfig cache, but only when *not* cross compiling.
# but the alternative is that fonts are cached purely at runtime, in ~/.cache/fontconfig,
# nixpkgs creates a fontconfig cache, which covers 99% of apps.
# if build-time caching fails for some reason, then fonts are cached at runtime, in ~/.cache/fontconfig,
# and that needs to either be added to the sandbox of *every* app,
# or font-heavy apps are several *seconds* slower to launch.
#
# N.B.: fc-cache produces output based on the architecture it's run on,
# e.g. /var/fontconfig/cache/<hash>-aarch64.cache-9 or <hash>-x86_64.cache-9
# this means we'd better emulate it -- don't run the host binary.
#
# TODO: upstream this into `make-fonts-cache.nix`?
cache = (pkgs.makeFontsCache { fontDirectories = config.fonts.packages; }).overrideAttrs (upstream: {
buildCommand = lib.replaceStrings
[ "fc-cache" ]
[ "${pkgs.stdenv.hostPlatform.emulator pkgs.buildPackages} ${lib.getExe' pkgs.fontconfig.bin "fc-cache"}" ]
upstream.buildCommand
;
});
cacheConf = pkgs.writeTextDir "etc/fonts/conf.d/01-nixos-cache-cross.conf" ''
<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'urn:fontconfig:fonts.dtd'>
<fontconfig>
<!-- Pre-generated font caches -->
<cachedir>${cache}</cachedir>
</fontconfig>
'';
noUserCacheConf = pkgs.runCommandNoCC "etc-fonts-fonts.conf-no-user" {} ''
cp ${pkgs.fontconfig.out}/etc/fonts/fonts.conf .
substituteInPlace fonts.conf \
@@ -55,6 +35,7 @@ in
fonts = lib.mkIf config.sane.programs.fontconfig.enabled {
fontconfig.enable = true;
fontconfig.cache32Bit = true; #< TODO: remove (here for testing)
fontconfig.defaultFonts = {
emoji = [
"Noto Color Emoji"
@@ -78,16 +59,13 @@ in
];
};
fontconfig.confPackages = lib.mkBefore ([
fontconfig.confPackages = lib.mkBefore [
# XXX(2024-12-18): electron apps (signal-desktop, discord) duplicate the entire font cache (1-2MB) to ~/.cache/fontconfig
# just to update a tiny section (4KB).
# patch instead to not have a user font cache. they will work, but complain "Fontconfig error: No writable cache directories".
# proper fix: see if electron apps need some specific font i'm missing, or are just being dumb?
noUserCacheConf
] ++ lib.optionals (pkgs.stdenv.hostPlatform != pkgs.stdenv.buildPlatform) [
# nixpkgs builds a cache file, but only for non-cross. i want it always, so add my own cache -- but ONLY for cross.
cacheConf
]);
];
#vvv enables dejavu_fonts, freefont_ttf, gyre-fonts, liberation_ttf, unifont, noto-fonts-emoji
enableDefaultPackages = false;

View File

@@ -40,7 +40,21 @@ in
hash = "sha256-D8Royett8CSZD7xHYEj6qvJCMFaFKz8SNOIBABapgDc=";
})
# TODO: send branch `pr-make-fonts-cache` out for review:
# remove `fontconfig.cache32Bit = true` from fontconfig.nix after merge (and maybe after seeing if it's beneficial for signal/electron apps?)
(fetchpatch' {
name = "makeFontsCache: fix cross compilation";
saneCommit = "e021ee13f909e6eb7c019b5cd1acf9eac0cd0f67";
hash = "sha256-3fJtcYfIDIIcn2p9LunPmRX1DWlcQ33OAw3Ok3sUs8g=";
})
(fetchpatch' {
name = "nixos/fonts: ship fontconfig caches even for cross-compiled hosts";
saneCommit = "9435a2b422f090b25f4aa5aee53be1341626672d";
hash = "sha256-4bhzdWxQ650+4bq4+2K4vJb/iQSPtppp3tBrs+qGdNQ=";
})
(fetchpatch' {
# 2025-03-18: merged into master
name = "nvimpager: enable strictDeps & cleanup inputs";
prUrl = "https://github.com/NixOS/nixpkgs/pull/390878";
# saneCommit = "e55b9041bc27a89549995a8d5f4f458f770ae8fd";