Thought this would be fun and potentially handy for others to share. I recently did some work with Typst, and the template I ended up using made use of fonts not in my system install.

I was curious if you could use fonts in a nix-shell. Simply adding a font package via nix-shell doesn’t make it accesible to applications. Thanks to this forum post, I ran a test using makeFontsConf, and it works! The way I used it it does require a .nix file, but I’m sure you could turn it into some one-line magic.

{ pkgs ? import <nixpkgs> {} }:

let
  fontsConf = pkgs.makeFontsConf {
    fontDirectories = [
      pkgs.font-awesome
      pkgs.fira
      pkgs.noto-fonts
      pkgs.roboto
    ];
  };
in

pkgs.mkShell {
  nativeBuildInputs = with pkgs.buildPackages; [ typst ];

  shellHook = ''
    export FONTCONFIG_FILE="${fontsConf}"
  '';
}