How to remove languages

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?

How do I achieve this with Nixos.

All advice gratefully received.

If you look at nixpkgs/pkgs/applications/office/libreoffice/default.nix at f9ebe33a928b5d529c895202263a5ce46bdf12f7 · NixOS/nixpkgs · GitHub you can see that the default for langs is a long list. You could override the attribute with your choice in your configuration.

Regarding the fonts you mentioned in the end: the corefonts package has those included.

@robsliwi thanks for the reply.

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?

Thanks, Ian

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:

systemPackages = [
  ...
  (libreoffice.override {
    unwrapped = libreoffice.unwrapped.override {
      langs = [ "en-US" ];
    };
  })
];

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.

3 Likes

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:

$ nix why-depends --all /run/current-system /nix/store/eeeeee...eee-some-package/share/fonts/wooble.ttf
3 Likes

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?

Thanks, Ian

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.

1 Like

Well, the nix-find command returned this:

I can’t see anything that looks like a user application, it all looks like system stuff to me… (demonstrating my ignorance…)

system-path is just a big pile of symlinks. What is the realpath of NotoSansThaiLooped-SemiCondensedExtraBold.otf?

Aahhh, how would I find that? Tried a find on directory / but it only returned nix packages. :-\

realpath is a command, just type realpath /nix/store/hnldidy...-system-path/share/X11/fonts/NotoSansThaiLooped-SemiCondensedExtraBold.otf.

That means it’s in environment.systemPackages. You either added it explicitly yourself or you’re using a module that does so.

(It could also be in fonts.packages.)

1 Like

This is the result. It looks like it’s in a nix package.

Okay, so it’s part of the noto-fonts package.

My guess is it’s being added in by the module associated with your desktop manager. Which desktop manager are you using—KDE, maybe?

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
  ];

Here’s my user definition;

  users.users.ian = {
    isNormalUser = true;
    description = "Ian";
    extraGroups = [ "networkmanager" "wheel" "dialout" ];
    packages = with pkgs; [
      kdePackages.kate
      kdePackages.kontact
      kdePackages.kontactinterface
      kdePackages.kmail-account-wizard
      kdePackages.kmines
      jetbrains.pycharm-community
      vscode
      thonny
      saleae-logic-2
      novelwriter
      freetube
      spotify
      thunderbird
      edgetx
    ];
  };

Kontact maybe?..

yes I am using KDE. :slight_smile:

The KDE module adds these fonts by default. You can customize it with the services.desktopManager.plasma6.notoPackage setting.

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:

services.desktopManager.plasma6.notoPackage = pkgs.noto-fonts.override {
  variants = [ "NotoSans" "NotoSerif" ];
};
2 Likes

That’s worked! So all I have to do is list all the fonts I want in that list? Brilliant!

Thanks so much for all your help today, much appreciated.

:wink:

4 Likes