I’m writing some code that generates PDF, and needs to be told the exact location of some font files.
I now realize that I’m woefully ignorant of how fonts are managed, so ignorant that I don’t really know what questions I’m trying to ask:
How can I ensure that the flake.nix which provisions the environment for this project, provides the required fonts?
Where should my program look for these fonts?
Some details
I’m using genpdf - Rust, and managed to get its hello-world example to work by hard-wiring /nix/var/nix/profiles/system/sw/share/X11/fonts on NixOS, but how can I ensure that it will also work on non-NixOS?
I haven’t worked with fonts much, but here are my thoughts:
How can I ensure that the flake.nix which provisions the environment for this project, provides the required fonts?
Include the font package as a dependency in the inputs section, I suppose? You can find a lot of fonts available from nixpkgs.
Where should my program look for these fonts?
fc-list tells you the name and location of available fonts. Depending on what programming language you’re using, there’s probably a library package that will run the query for you.
As this wasn’t mentioned yet:
In a development shell you will probably want to set:
export FONTCONFIG_FILE=...
In nixpkgs there’s a makeFontsConf that you can use with that.
See e.g.
Note that this can lead to undesired situations where globally installed fonts won’t be able to be found anymore inside this development shell unless you explicitly list global directories in your call to makeFontsConf.