nixos/fontconfig: Fix compatibility with unstable apps

Fontconfig 2.14 from unstable reverted back to using /etc/fonts/fonts.conf
for its configuration. Unfortunately, on NixOS 20.03, this still points
to configuration for Fontconfig 2.10, with cache version 3.

When an app linked against Fontconfig 2.14 reads the config and does not
find a compatible cache, it writes a new cache entries to ~/.cache/fontconfig.
Unfortunately, the fontconfig 2.14 uses the same cache version as 2.12 in 20.03 (7)
so when the apps from 20.03 later read the cache, they cannot make much sense
of it and are unable to find any fonts.

I added a new fonts.fontconfig.disableVersionedFontConfiguration option, which,
when enabled, makes /etc/fonts/fonts.conf point to the configuration file
for the latest fontconfig, instead of the ancient 2.10 version.
This is necessary to prevent packages from Nixpkgs unstable breaking apps
from 20.03.

Enabling this should not cause any issues as there are no programs
using the legacy fontconfig version since NixOS 15.03.

Unfortunately, if a person already ran an app from unstable
before applying this patch, they will need to delete ~/.cache/fontconfig manually.
This commit is contained in:
Jan Tojnar
2020-09-08 12:59:32 +02:00
parent 4bd1938e03
commit eb6ac6ab68

View File

@@ -195,7 +195,7 @@ let
confPkg = pkgs.runCommand "fontconfig-conf" {
preferLocalBuild = true;
} ''
support_folder=$out/etc/fonts/conf.d
support_folder=$out/etc/fonts/${lib.optionalString cfg.disableVersionedFontConfiguration "2.10/"}conf.d
latest_folder=$out/etc/fonts/${latestVersion}/conf.d
mkdir -p $support_folder
@@ -206,6 +206,11 @@ let
ln -s ${latestPkg.out}/etc/fonts/fonts.conf \
$latest_folder/../fonts.conf
${lib.optionalString cfg.disableVersionedFontConfiguration ''
ln -s $latest_folder/../fonts.conf \
$latest_folder/../../fonts.conf
''}
# fontconfig default config files
ln -s ${supportPkg.out}/etc/fonts/conf.d/*.conf \
$support_folder/
@@ -292,6 +297,23 @@ in
'';
};
disableVersionedFontConfiguration = mkOption {
type = types.bool;
default = true;
description = ''
If enabled, /etc/fonts/fonts.conf will contain configuration file
for the latest fontconfig, instead of the ancient 2.10 version.
This is necessary for using packages from Nixpkgs unstable.
Without it, running programs from unstable will populate
~/.cache/fontconfig with values incompatible with
programs from NixOS 20.03.
Enabling this should not cause any issues as there are no programs
using the legacy fontconfig version since NixOS 15.03.
'';
};
confPackages = mkOption {
internal = true;
type = with types; listOf path;