fonts: allow disabling font packages
I assert that this feature request is relevant for Stylix
- [x] I assert that this is not a duplicate of an existing feature request.
Description
It was briefly discussed in this issue: https://github.com/nix-community/stylix/issues/366. I want to skip installing font packages for a headless system (server).
This can't be done right now since the fonts all need a package, but I could kinda work around it by setting stylix.fonts.packages = lib.mkForce [];, since I don't pull any graphical packages, no fonts should be referenced in the final derivation.
This is not possible right now due to this line: https://github.com/nix-community/stylix/blob/4bc15ef13c970981e37506491e18d1158af9a70c/stylix/fonts.nix#L116. Removing it would fix my issue, but I don't know if that is the best option, maybe adding a stylix.fonts.installFonts option would be better?
Notify maintainers
@danth @trueNAHO
Unfortunately, I'm not sure that your solution would be a proper fix to this issue as a whole. From what I understand, stylix.fonts.packages is intended to be an option which is only really used internally, but it is not the only way in which Stylix accesses the packages of the fonts. From what I have found, font packages are individually accessed in the following places:
- https://github.com/nix-community/stylix/blob/5b257989a8337dddc22aa04a70d3665d0384abef/stylix/droid/fonts.nix#L13
- https://github.com/nix-community/stylix/blob/5b257989a8337dddc22aa04a70d3665d0384abef/modules/gtk/hm.nix#L52
- https://github.com/nix-community/stylix/blob/5b257989a8337dddc22aa04a70d3665d0384abef/modules/regreet/nixos.nix#L52
- https://github.com/nix-community/stylix/blob/5b257989a8337dddc22aa04a70d3665d0384abef/modules/grub/nixos.nix#L18
- https://github.com/nix-community/stylix/blob/5b257989a8337dddc22aa04a70d3665d0384abef/modules/kitty/hm.nix#L22
As you said, for your headless server, it's likely that most or all of these targets are already not enabled, and thus your solution would work for your specific situation. I will open a PR implementing your change and I'll talk more with the maintainers about technical details over there, but I wonder: would this be fixed by making the stylix.fonts option nullable as a whole, or do you still set font names?
It would still work for me since I can track the packages that are included and I don't enable those packages (the system is headless).
I want to skip installing font packages for a headless system (server).
The best solution is to wait for https://github.com/nix-community/stylix/issues/929 to be resolved, which requires completing our ongoing mkTarget migration. Note that https://github.com/nix-community/stylix/pull/1597 acts somewhat as a tracker.
Since this issue is a subset of https://github.com/nix-community/stylix/issues/929, I will close this issue as duplicate.
Here's the workaround I use ATM:
stylix.fonts = lib.flip lib.mapAttrs config.fonts.fontconfig.defaultFonts (
family: _: {
name = family; # use fontconfig to pick the right font
package = pkgs.emptyDirectory;
}
);