Fontconfig problems with Nix on Guix System
Since I started using Guix System about a year ago, I’ve absolutely loved it. I can easily say it’s my favourite OS out of any I’ve used, thus far. Although, compared to Nix (which Guix is based on), it has comparatively few software packages packaged for it. This is no wonder when considering the sheer amount of packages for Nix.
Fortunately this “problem” is easily remedied by just using Nix on Guix System! This is made
extra easy by using the system service nix-service-type (documentation).
Now I use Nix on Guix System, mostly using Home Manager, and for the most parts it works great. One of the few problems I’ve run into is that graphical programs installed via Nix get the wrong fonts, like they couldn’t find any fonts and always used a fallback. In this case, Iosevka, which I had installed with Guix. No matter which font packages I installed, every application would use Iosevka.
For example, Firefox (installed via Nix) would log this error whenever started:
Fontconfig error: Cannot load default config file: File not found:
Turns out that this is a problem with Fontconfig. Or rather, that Guix and Nix manages their Fontconfig configs
differently. Guix System does not set the environment variables FONTCONFIG_FILE or FONTCONFIG_PATH,
which are used by Fontconfig to figure out where configurations are placed. By default, Fontconfig looks
in the directory /etc/fonts to find fonts and configs, but this is not where Guix places them. Guix instead
places font configuration in the active system configuration directory, under /run/current-system/profile.
So, to fix the font problems with Nix applications, all we have to do is to set the following environment variables:
FONTCONFIG_PATH=/run/current-system/profile/etc/fonts
FONTCONFIG_FILE=/run/current-system/profile/etc/fonts/fonts.conf
In my case, I opted to do this in my Guix Home configuration, using the home-bash-service-type service, like so:
(home-environment
(services
(append (list (service home-bash-service-type
(home-bash-configuration
(environment-variables
'(("FONTCONFIG_FILE" . "/run/current-system/profile/etc/fonts/fonts.conf")
("FONTCONFIG_PATH" . "/run/current-system/profile/etc/fonts")))))
)
%base-home-services)))
But you can set them however you like. After the environment variables are set, applications installed with Nix should find your installed fonts.