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?
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?
If the program solely relies on font-cache I wouldn’t know a why to do it in a nix-shell. Can you supply it directories to search fonts in?
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:
In nixpkgs there’s a
makeFontsConf that you can use with that.
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