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 incompatibilities #2050

Closed
vcunat opened this issue Mar 28, 2014 · 15 comments
Closed

Fontconfig incompatibilities #2050

vcunat opened this issue Mar 28, 2014 · 15 comments
Assignees

Comments

@vcunat
Copy link
Member

vcunat commented Mar 28, 2014

Situation

Currently we have fontconfig-2.10.*. With 2.11 the format of fontconfig's xmls changed a bit. Newer fontconfig probably works with old-style /etc/fonts since b16994f, but the other way won't work (it doesn't handle invalid config well).

If we want to use /etc/fonts of non-nixos, then I don't think we can do that without nontrivial patching work to make fontconfig better handle invalid files. The issue there is worse, as we don't even know/control what is in /etc/, so either of the versions probably won't work (and we don't know which).

First ideas

My long-term opinion is that generally, default configuration should be hard-coded in nix store, and /etc/* should be minimal, only specifying where that particular machine wants something different than default.

With fontconfig this is doable, IIRC, by specifying an include of some /etc/ path in the nix-stored config. If the format changes in future, I only expect it would be in a little used part again, so it seems much less likely that someone gets into a similar conflict in future.

If this config override was present on some non-standard /etc/ path in nixos, then people could do overrides in there. On non-nixos people would get the default behavior regardless of their /etc/fonts, which is IMHO the best we can currently do with fontconfig behaving this way. (I would have to check if including a non-existent file leads to similar problems, but that should be a single easily patchable case.)


The discussion started below #2020 (comment)

@vcunat vcunat added the bug label Mar 28, 2014
@ttuegel
Copy link
Member

ttuegel commented Apr 1, 2014

The only problem I see with hard-coding the default configuration for fontconfig in the store is #1827. If the configuration becomes a hard-coded in the store, users will have to suffer a massive rebuild to override the default configuration.

@vcunat
Copy link
Member Author

vcunat commented Apr 1, 2014

That's why I would add something like <include ignore_missing="yes">/etc/fonts-nix</include> to that hardcoded file, which would e.g. allow to add infinality-specific config by a switch in configuration.nix. Moreover, people can set FONTCONFIG_FILE or FONTCONFIG_PATH, e.g. by a wrapper.

@ttuegel
Copy link
Member

ttuegel commented Apr 1, 2014

I don't think loading configurations from /etc/fonts-nix would entirely solve the problem of #1827. It is very difficult to write the "inverse" of a configuration so that loading one file undoes a previous file. If you want to override a default configuration file, you must first stop fontconfig from ever loading it.

Would setting FONTCONFIG_FILE or FONTCONFIG_PATH override the Nix store settings completely? That is, if I set FONTCONFIG_FILE globally, would my fontconfig ever load the configuration in the Nix store? If the answer is "no," then I think that's fine.

@vcunat
Copy link
Member Author

vcunat commented Apr 1, 2014

I believe the answer is yes, as docs http://www.freedesktop.org/software/fontconfig/fontconfig-user.html say:

FONTCONFIG_FILE is used to override the default configuration file.
FONTCONFIG_PATH is used to override the default configuration directory.

The /etc/fonts-nix was only meant by me for easy system-wide extending by additive changes (which is what e.g. infinality's fontconfig rules are IIRC).

@shlevy
Copy link
Member

shlevy commented Apr 5, 2014

I like your initial idea. I don't think we can do much better than that without significant rework of fontconfig itself.

@vcunat vcunat self-assigned this Apr 25, 2014
@vcunat
Copy link
Member Author

vcunat commented May 6, 2014

I'm currently testing an implementation of that (including infinality ported to newest freetype). Expect a PR within a week.

@ttuegel
Copy link
Member

ttuegel commented May 25, 2014

Is there a reason to use /etc/fonts-nix for additive changes, rather than the standard /etc/fonts/local.conf? Fontconfig is very sensitive to the order files are loaded. I think there's a benefit to staying as close to upstream as possible.

The version of Fontconfig in Nixpkgs now tries to load local.conf from the Nix store, so we would need to patch the upstream configuration to load that file by absolute rather than relative path. That's just a one-line patch. In addition, other distributions use /etc/fonts/local.conf for local, system-wide customization, so patching that would help integration of Nixpkgs applications on non-NixOS systems.

@ttuegel
Copy link
Member

ttuegel commented May 25, 2014

Actually, I stand corrected about patching the configuration. Fontconfig will pick up /etc/fonts/local.conf if it exists instead of searching the Nix store. So we don't need to do anything except put additive settings there.

@vcunat
Copy link
Member Author

vcunat commented May 25, 2014

The reasons were described above; shortly: the upstream (font)config changes incompatibly, e.g. now with 2.11 bump. With common config it's probably impossible to support packages that were linked against both versions (not speaking of nixpkgs on other distros where /etc is completely out of control).

@ttuegel
Copy link
Member

ttuegel commented May 25, 2014

I think I must have misunderstood before. It sounds like the plan is to use /etc/fonts-nix for additive configuration for version 2.11+ only. Before I thought the intent was to use /etc/fonts-nix for all versions; I didn't see how that would solve the incompatibility problem anyway. Got it now, thanks!

@vcunat
Copy link
Member Author

vcunat commented May 26, 2014

Well, older versions use what they use, and we can't change what people already have in /nix/store.

@lucabrunox
Copy link
Contributor

Proposal for merging into the @vcunat branch: https://github.com/lethalman/nixpkgs/tree/fontconfig

  • It modifies $fontconfig/etc/fonts/fonts.conf to include /etc/fonts/2.11/conf.d . There's a passthru configVersion. The configVersion variable should be bumped every time fontconfig breaks backwards compatibility of the config.
  • Uses 2.11 also for cache dirs, not sure if that's any useful.
  • It removes the xml:space because new fontconfig does not like it.
  • I used the makeFontsConf approach instead of applying patch to the fonts.conf like in @vcunat branch, since I thought hardcoding also the fontconfig cache dir was a good idea, but I'm not sure about that.

Nixos

Nixos should write an /etc/fonts/fonts.conf with fontconfig 2.10, and write a /etc/fonts/2.11/conf.d/fontdirs.conf with font dirs only for 2.11 (that is, no makeFontsConf).

That means, applications using makeFontsConf can benefit of fonts specified by the user in nixos because they will be in conf.d.

Non-nixos

This still breaks non-nixos applications, since with fontconfig 2.11 the /etc/fonts/2.11 is non-existent.

The gui will be full of ugly squares, unless in nix.sh we explicitly set FONTCONFIG_FILE like we do for ca-certs: https://github.com/NixOS/nix/blob/master/scripts/nix-profile.sh.in , that will only work with nix 1.8.

@vcunat
Copy link
Member Author

vcunat commented Sep 28, 2014

Well, IMO our 2.11 should not read /etc/fonts/fonts.conf, as incompatible config may be there. That is still my aim. The problem I have (and your changes don't fix it) is that fontconfig still searches for config in there even if I set sysconfdir to whatever I want.

@vcunat
Copy link
Member Author

vcunat commented Sep 28, 2014

Ah, no, it does work. I forgot to clear the FONTCONFIG_FILE variable that we pointlessly set all the time. Note that even current (master) apps do work well without setting it.

lucabrunox pushed a commit to lucabrunox/nixpkgs that referenced this issue Oct 19, 2014
lucabrunox pushed a commit to lucabrunox/nixpkgs that referenced this issue Oct 19, 2014
vcunat pushed a commit to vcunat/nixpkgs that referenced this issue Oct 23, 2014
@vcunat
Copy link
Member Author

vcunat commented Nov 5, 2014

Resolved. Latest discussion in #4410.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants