Setting a local font directory

When I used 23.11 I could specify a local font directory like this

    fonts.packages = [ "/persistent/fonts" ];

But this seems to not work anymore when I tried latest unstable

error: builder for '/nix/store/3gkdprjb871g512y9c84lgy1is5miv9w-X11-fonts.drv' failed with exit code 1;
       last 1 log lines:
       > find: '/persistent/fonts': No such file or directory
       For full logs, run 'nix log /nix/store/3gkdprjb871g512y9c84lgy1is5miv9w-X11-fonts.drv'.
error: 1 dependencies of derivation '/nix/store/l3pp0m8v0q52qic817xg20ld1p7rby8s-system-path.drv' failed to build
error: 1 dependencies of derivation '/nix/store/im96gq0050kwvx3izb4cv4dkx4yzlnd6-xserver.conf.drv' failed to build
error: 1 dependencies of derivation '/nix/store/iajqn75sb3f98al6rj53jma1345pbbrp-nixos-system-nixhpix-24.05.20240507.b211b39.drv' failed to build

The usage I have for this is to be able to specify a persistent directory in which I keep the fonts which I have paid for. Therefore, I do not want to package them as part of a potentially public config.

I tried to look at the latest changes in the font related modules in nixpkgs, but I was unable to find any obvious changes that would affect this error added in the last 6 months.

Should I report this as a regression in nixpkgs and does anybody know a nice alternative/workaround for my use case?

Looks like it is because of this change of flatpak module enabling X11 fontdir module, which expects packages, not paths in fonts.packages option. (Found by greping the derivation name in Nixpkgs.)

You can work around it by force disabling it with mkForce.

Alternately, if you have the directory on devices where you evaluate your configuration, you can interpolate the path "${/persistent/fonts}" to have Nix copy the directory to the Nix store. That way the X11-fonts derivation will be able to access it in build sandbox. And so will the fontconfig cache builder, which probably just silently ignores the missing directory.

I would consider this a bug but I am not sure which is the best solution. Maybe we should revert nixos/fonts: rename fonts.fonts option to fonts.packages, other cleanups · NixOS/nixpkgs@5162df3 · GitHub since the option expects a path. Or change its type to pathInStore and add extraPaths option for your use case.

1 Like

Thanks! Setting it to "${/persistent/fonts}" is a good enough solution for me right now.

Just note that going this way, the system will refer to the directory in Nix store. So if you change the fonts in the original directory, you will need to rebuild your system for programs to become aware of the change. And if the font collection is large, a new copy with each change might quickly fill up your drive.