Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fontconfig: Stop using versioned config dirs #95358

Merged
merged 3 commits into from
Sep 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions nixos/modules/config/fonts/fontconfig.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*

Configuration files are linked to /etc/fonts/${pkgs.fontconfig.configVersion}/conf.d/
Configuration files are linked to /etc/fonts/conf.d/

This module generates a package containing configuration files and link it in /etc/fonts.

Expand Down Expand Up @@ -176,15 +176,16 @@ let
confPkg = pkgs.runCommand "fontconfig-conf" {
preferLocalBuild = true;
} ''
dst=$out/etc/fonts/${pkg.configVersion}/conf.d
dst=$out/etc/fonts/conf.d
mkdir -p $dst

# fonts.conf
ln -s ${pkg.out}/etc/fonts/fonts.conf \
$dst/../fonts.conf
# TODO: remove this legacy symlink once people stop using packages built before #95358 was merged
ln -s /etc/fonts/${pkg.configVersion}/fonts.conf \
$out/etc/fonts/fonts.conf
mkdir -p $out/etc/fonts/2.11
ln -s /etc/fonts/fonts.conf \
$out/etc/fonts/2.11/fonts.conf

# fontconfig default config files
ln -s ${pkg.out}/etc/fonts/conf.d/*.conf \
Expand Down
36 changes: 0 additions & 36 deletions pkgs/development/libraries/fontconfig/config-compat.patch

This file was deleted.

50 changes: 14 additions & 36 deletions pkgs/development/libraries/fontconfig/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,6 @@
, autoreconfHook
}:

/** Font configuration scheme
- ./config-compat.patch makes fontconfig try the following root configs, in order:
$FONTCONFIG_FILE, /etc/fonts/${configVersion}/fonts.conf, ${fontconfig.out}/etc/fonts/fonts.conf
This is done not to override config of pre-2.11 versions (which just blow up)
and still use *global* font configuration at NixOS,
falling back to upstream defaults on non-NixOS.
- NixOS creates /etc/fonts/${configVersion}/fonts.conf link to $out/etc/fonts/fonts.conf,
and other modifications should go to /etc/fonts/${configVersion}/conf.d
- See ./make-fonts-conf.xsl for config details.

*/

let
configVersion = "2.11"; # bump whenever fontconfig breaks compatibility with older configurations
in
stdenv.mkDerivation rec {
pname = "fontconfig";
version = "2.13.92";
Expand All @@ -36,11 +21,6 @@ stdenv.mkDerivation rec {
};

patches = [
(substituteAll {
src = ./config-compat.patch;
inherit configVersion;
})

# Fix fonts not being loaded when missing included configs that have ignore_missing="yes".
# https://bugzilla.redhat.com/show_bug.cgi?id=1744377
(fetchpatch {
Expand Down Expand Up @@ -73,6 +53,13 @@ stdenv.mkDerivation rec {
url = "https://gitlab.freedesktop.org/fontconfig/fontconfig/commit/37c7c748740bf6f2468d59e67951902710240b34.patch";
sha256 = "1rz5zrfwhpn9g49wrzzrmdglj78pbvpnw8ksgsw6bxq8l5d84jfr";
})

# Show warning instead of error when encountering unknown attribute in config.
# https://gitlab.freedesktop.org/fontconfig/fontconfig/merge_requests/111
(fetchpatch {
url = "https://gitlab.freedesktop.org/fontconfig/fontconfig/commit/409b37c62780728755c908991c912a6b16f2389c.patch";
sha256 = "zJFh37QErSAINPGFkFVJyhYRP27BuIN7PIgoDl/PIwI=";
})
];

outputs = [ "bin" "dev" "lib" "out" ]; # $out contains all the config
Expand All @@ -93,6 +80,7 @@ stdenv.mkDerivation rec {
];

configureFlags = [
"--sysconfdir=/etc"
"--with-arch=${stdenv.hostPlatform.parsed.cpu.name}"
"--with-cache-dir=/var/cache/fontconfig" # otherwise the fallback is in $out/
"--disable-docs"
Expand All @@ -106,32 +94,22 @@ stdenv.mkDerivation rec {

doCheck = true;

# Don't try to write to /var/cache/fontconfig at install time.
installFlags = [ "fc_cachedir=$(TMPDIR)/dummy" "RUN_FC_CACHE_TEST=false" ];
installFlags = [
# Don't try to write to /var/cache/fontconfig at install time.
"fc_cachedir=$(TMPDIR)/dummy"
"RUN_FC_CACHE_TEST=false"
"sysconfdir=${placeholder "out"}/etc"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to set sysconfdir for both install and configure?

Copy link
Member Author

@jtojnar jtojnar Aug 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the configure makes /etc hardcoded into the code but we cannot install to /etc so we need to move the installation path into the derivation. It is quite common idiom.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay 👍

];

postInstall = ''
cd "$out/etc/fonts"
xsltproc --stringparam fontDirectories "${dejavu_fonts.minimal}" \
--stringparam fontconfig "$out" \
--stringparam fontconfigConfigVersion "${configVersion}" \
--path $out/share/xml/fontconfig \
${./make-fonts-conf.xsl} $out/etc/fonts/fonts.conf \
> fonts.conf.tmp
mv fonts.conf.tmp $out/etc/fonts/fonts.conf

# Make it easier to remove user config in NixOS module.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vcunat this probably should have been kept?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(or https://github.com/NixOS/nixpkgs/pull/95358/files#diff-376672cba12c87d4103e6134632e306fR203 remove the symlink in case cfg.includeUserConf is false?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to revert also 8425726.

mkdir -p $out/etc/fonts/conf.d.bak
mv $out/etc/fonts/conf.d/50-user.conf $out/etc/fonts/conf.d.bak

# update latest 51-local.conf path to look at the latest local.conf
substituteInPlace $out/etc/fonts/conf.d/51-local.conf \
--replace local.conf /etc/fonts/${configVersion}/local.conf
'';

passthru = {
inherit configVersion;
};

meta = with stdenv.lib; {
description = "A library for font customization and configuration";
homepage = "http://fontconfig.org/";
Expand Down
2 changes: 0 additions & 2 deletions pkgs/development/libraries/fontconfig/make-fonts-conf.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ runCommand "fonts.conf"
}
''
xsltproc --stringparam fontDirectories "$fontDirectories" \
--stringparam fontconfig "${fontconfig.out}" \
--stringparam fontconfigConfigVersion "${fontconfig.configVersion}" \
--path ${fontconfig.out}/share/xml/fontconfig \
${./make-fonts-conf.xsl} ${fontconfig.out}/etc/fonts/fonts.conf \
> $out
Expand Down
9 changes: 2 additions & 7 deletions pkgs/development/libraries/fontconfig/make-fonts-conf.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
<xsl:output method='xml' encoding="UTF-8" doctype-system="fonts.dtd" />

<xsl:param name="fontDirectories" />
<xsl:param name="fontconfig" />
<xsl:param name="fontconfigConfigVersion" />

<xsl:template match="/fontconfig">

Expand All @@ -28,11 +26,8 @@
<!-- /var/cache/fontconfig is useful for non-nixos systems -->
<cachedir>/var/cache/fontconfig</cachedir>

<!-- versioned system-wide config -->
<include ignore_missing="yes">/etc/fonts/<xsl:value-of select="$fontconfigConfigVersion" />/conf.d</include>

<!-- upstream config -->
<include><xsl:value-of select="$fontconfig" />/etc/fonts/conf.d</include>
<!-- system-wide config -->
<include ignore_missing="yes">/etc/fonts/conf.d</include>

<dir prefix="xdg">fonts</dir>
<xsl:for-each select="str:tokenize($fontDirectories)">
Expand Down