How to install fonts on a non-NixOS system?

I recently installed the Libertinus font family using Nix on an Ubuntu system, but it doesn’t seem to be available system-wide.

I searched around and found some resources that I thought might help, but Fonts in nix-installed packages on a non-NixOS system is about making Nix-installed programs be able to see non-Nix-installed system fonts (whereas I want the opposite), and Fonts - NixOS Wiki appears to only provide instructions for working with fonts on NixOS systems.

Any advice on how to set up Nix-installed fonts to be available system-wide to other applications? Or is this something that could/should be done directly in the nix expression for the font?

2 Likes

If you use nix-env, you could add appropriate directory in your profile (e.g. ~/.nix-profile/share/fonts/) to your fontconfig settings, see e.g. fontconfig - Adding a new per-user font directory - Unix & Linux Stack Exchange

Alternately, home-manager can handle that for you.

1 Like

Wow, thanks! So for future reference, what I did was:

# Create the local fontconfig directory 
$ mkdir -p ~/.config/fontconfig/conf.d/

# Create a file in that directory for the Nix fonts
$ cat << EOF > ~/.config/fontconfig/conf.d/10-nix-fonts.conf
<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
<fontconfig>
 <dir>~/.nix-profile/share/fonts/</dir>
</fontconfig>
EOF

Since these steps are (I presume) identical for any standard Nix setup in non-NixOS systems, I wonder if it would be possible or desirable for the installation of fonts by Nix to either automatically set these up, or at least print instructions to do so manually. Do you have any thoughts on that?

1 Like

Instructions would probably be the best option since IIRC, we want Nix to be easy to uninstall – that would be impossible if it created random files everywhere.

2 Likes

Makes sense. Are you aware of an existing Nix expression that prints this kind of instructions, which I could use as a base of a PR to edit libertinux.nix?

Hosted by Flying Circus.