Fonts in nix-installed packages on a non-NixOS system

I’m currently using nix to manage some of my builds on my non-NixOS system (Gentoo). Though I’m interested in switching over eventually, I’m not currently able to. It works great, but I’m running into some font-based problems for nix-installed programs.

Programs that I install with nix don’t seem to be able to see any installed fonts: they either have only fonts bundled with them, or no fonts at all. I’ve found advice for how to handle fonts on a NixOS system, but not for how to give my own derivations access to fonts without the configuration.nix infrastructure. Just including the fonts in the buildDepends doesn’t work, as expected.

I would be happy either with bundling fonts into the nix environment, or with allowing my nix-installed programs to see the ordinary system fonts. A potential complication is that my system fontconfig is version 2.13.0, while nixpkgs-unstable seems to only have 2.12.6.

Any ideas how to go about this? The main problem I’m encountering at the moment is that generating graphs with ggplot2 in R cannot display any text, and every character is just a little box with a unicode codepoint. But I also have the same problem installing the standard firefox derivation: it just has a horrible-looking default font everywhere.


I have similar problems with Emacs from emacs-overlay (didn’t check from nixpkgs yet).

Menus are just falling back to boxes with unicode codepoint in hex, while actual editor buffer seems to be fine.

Also no problems on my nixOS box with the same Emacs installation.

I use Nix at work in Chrome OS’s “Termina” VM (which is running almost-stock Debian 9), and don’t see this issue with the graphical apps I have installed. I’m using home-manager with fonts.fontconfig.enable = true though, and suspect it’s that module’s magic is what’s solving the issue. Perhaps something from that module could be adapted?

Adding that flag does not change anything :frowning:

Though with and without that flag set, I do see this when starting emacs:

(process:18836): Gtk-WARNING **: 11:28:45.592: Locale not supported by C library.
	Using the fallback 'C' locale.
Fontconfig warning: "/etc/fonts/fonts.conf", line 5: unknown element "its:rules"
Fontconfig warning: "/etc/fonts/fonts.conf", line 6: unknown element "its:translateRule"
Fontconfig error: "/etc/fonts/fonts.conf", line 6: invalid attribute 'translate'
Fontconfig error: "/etc/fonts/fonts.conf", line 6: invalid attribute 'selector'
Fontconfig error: "/etc/fonts/fonts.conf", line 7: invalid attribute 'xmlns:its'
Fontconfig error: "/etc/fonts/fonts.conf", line 7: invalid attribute 'version'
Fontconfig warning: "/etc/fonts/fonts.conf", line 9: unknown element "description"
Fontconfig error: Cannot load config file from /etc/fonts/fonts.conf

I do not see any of those when starting systems emacs.

I got those warnings and errors too. I think it’s a result of an incompatibility between nix’s version of fontconfig and your system version (2.13 vs 2.12). Commenting out the offending lines made the errors go away, but otherwise didn’t solve any problems for me.

Yeah, I’m pretty sure that @xitian is right that those errors are due to the Fontconfig version mismatch (Debian 9 is running Fontconfig 2.11 and doesn’t encounter this issue).

My only other thoughts are really just throwing spaghetti against the wall:

  1. On my system I have to set home.sessionVariables.LOCALE_ARCHIVE = "${pkgs.glibcLocales}/lib/locale/locale-archive"; to work around locale errors (which screw up some of the terminal apps I use). I don’t think this would be causing your problem, though it should get rid of the first warning in @NobbZ’s output.

  2. I’ve found it virtually impossible to get all of the environment set up by home-manager to be respected by Chrome OS’s launchers, and thus have resorted to changing all of my GUI app Exec= lines to Exec=bash -le $APP. However, temporarily reverting this change doesn’t mess up my fonts, so it’s probably also not the solution.

Having had the opportunity to test things out on my work system now, I can see that fonts.fontconfig.enable = true; was a red herring… Disabling results in my GUI apps not being able to find the fonts I’ve installed via home-manager, but doesn’t actually produce the tofu you’re describing.


  1. I also have that variable set (albeit in a different place), so unfortunately that doesn’t help.
  2. I also get the problem with generating png files with a command-line program, so this doesn’t help either.

I use fish, so you’ll have to adapt this to whichever shell you use, but this works for me:

  set --global --export FONTCONFIG_FILE ${pkgs.fontconfig.out}/etc/fonts/fonts.conf

EDIT: (add that to your home-manager’d shell config)

So would the equivalent for someone using a bash shell be export FONTCONFIG_FILE ${pkgs.fontconfig.out}/etc/fonts/fonts.conf?

What worked directly for me in my mkShell was:

shellHook = ''
      export FONTCONFIG_FILE=${pkgs.fontconfig.out}/etc/fonts/fonts.conf
      source ~/.bashrc

But now my GUI emacs is broken… :frowning: Gotta figure out how to help it find inconsolata 14.

1 Like

I have the same problem with eclipse-java on Debian Testing (Bullseys).

The input method engines on Xfce installed on the host are also not working.
There is an issue about this: