I just installed Libreoffice Writer, opened a document, and attempted to change the font. I was presented with hundreds of fonts, many for foreign languages like arabic and amharic, languages I will never use.
I understand that removing languages in other distros is done by removing language packs using the package manager. But how to do it in Nixos? What do I have to put in configuration.nix to remove the language packs I don’t want, don’t need, and will never use? And while I’m at it, I’d like to remove some English fonts I don’t want too. And BTW, whatever happened to Arial, Times New Roman, and everybody’s favourite, Comic Sans?
Two questions. 1. how do I override the attribute in configuration? I’m very new to Nixos and I’m not familiar with the configuration language (if that’s the correct term for it).
2. It’s my understanding that applications that include a text editor that offers multiple fonts derive the font lists from the language packs installed in the system. So ideally, what I’d really like to do is remove those language packs from the system so that all the apps that use them would only contain (for me) English. And only the few fonts that I like and use. Is that possible?
Many other distros work like this, but not NixOS. With a few exceptions, Nix derivations take hard dependencies on the other derivations that they use. Change the dependencies, you get a different derivation. We try to keep run-time references to external system state to a minimum, in order to make programs behave consistently from machine to machine (that’s the One Big Idea of Nix, after all!). The concept of ‘installed language pack’ would be one such bit of state.
Customizing your LibreOffice derivation is, unfortunately, a bit of an exercise. The first thing to know is that the libreoffice derivation you’ve probably added to your list of packages is actually a wrapper around the thing that @robsliwi linked to. So in order to change it, you have to override the wrapper and change the wrapped derivation. In short, changing the langs input ends up looking like this:
Get ready to wait for lots of rebuilding if you try this! Yes, you have to rebuild LibreOffice from source if you want to change the languages it ships with. Even then, no guarantee that it actually slims down your installation any; I see that the LibreOffice derivation depends unconditionally on a bunch of fonts in order to run tests, so you will certainly be downloading them as part of your rebuild, and I don’t know (because I haven’t done that rebuild) if a garbage collection will clean them up or if they remain retained by the built package.
Most of us on NixOS have gotten used to having not the slimmest system possible; it’s honestly not a very good distro for that unless you’re prepared to invest a lot of time customizing your derivations and rebuilding everything.
On the other hand, I just opened my LibreOffice and was not overwhelmed by a ton of fonts. So maybe it has nothing to do at all with your LibreOffice derivation and somehow you have a bunch of fonts on your system from something else.
If you can find the Nix store path of the font in question, you can figure out what package is bringing it into your system with nix why-depends, like so:
You didn’t say it would take hours! I’ve mowed the lawn, had a shower, had lunch and attempted to setup my mesh system with a new controller, and it still hasn’t finished. I hope it doesn’t have to do this every time I run nixos-rebuild, which I seem to do lot…
How would I go about identifying which package has the font(s) I’m trying to remove?
Not every time you make a change to a different part of your configuration, but yes every time you update Nixpkgs. NixOS ‘degrades’ to being a source-based distro like Gentoo if you do too much of this. (It fundamentally is one, but the caching is good enough to let you pretend otherwise if you’re only using off-the-shelf packages.)
You might do something clever with strace to see what font files are opened by LibreOffice… but me, I’d probably do the much dumber thing of scanning for fonts with approximately the right name and expected extension (.ttf, .otf) using find /nix/store -iname.
Here’s the environment.systemPackages stanza. I didn’t install the language package intentionally I can assure you. Not sure what module I’ve installed that could have done it.
environment.systemPackages = with pkgs; [
python314
efibootmgr
kcalc
brave
vivaldi
geany
libreoffice-unwrapped
(libreoffice.override {
unwrapped = libreoffice.unwrapped.override {
langs = [ "en-GB" ];
};
})
# vim # Do not forget to add an editor to edit configuration.nix! The Nano editor is also installed by default.
# wget
];
Edit: Don’t do this; see next post.
The noto-fonts package doesn’t look very customizable, so if you’re set on getting fonts you don’t need out of your system, my recommendation is to add in a post-fixup hook. This is a bit hacky but not terribly so. You’ll end up with something like this:
services.desktopManager.plasma6.notoPackage = pkgs.noto-fonts.overrideAttrs {
postFixup = ''
rm $out/share/X11/fonts/NotoSansThaiLooped-*.otf
# TODO: add any more you want to get rid of
'';
};
This one should only take a minute to build, at least!
Or, hmm, maybe I spoke too soon about the customizability. Is this what the variants argument is for? I’m not sure. Maybe you could figure it out from upstream.
Edit: Yeah, looks like variants is meant to be an array of entries in this folder. That’s much better; you can get away with this then: