How do I find out why a package is installed? (2)

I am aware there is already a topic with the same name, so Discourse forced me to add the 2 in the title, but the “answer” there is not an actual answer to the (general) question.

I often wonder things like “Why is xterm installed? There is no xterm in my systemPackages?” or “Why is nano installed? I use vim and would never install nano”.

Then I do:

$ nix-store -q --referrers /run/current-system/sw/bin/xterm

So obviously, my system configuration requires xterm to be installed. But how do I find out what option causes xterm to be installed?

1 Like

There is no one true way.

You know your configuration and check the implementation of some of the options you set.

There you will find that nano is basically installed always via environment.defaultPackages and that xterm gets installed by default when enabling X.

If you have the experimental cli enabled, you can use why-depends, which shows a nicer tree, which is helpful when something isn’t actually installed as a program in PATH, but instead just a transient dependency of the closure.

And even then it is a lot of guesswork based on names of store paths.

1 Like

In a nixpkgs clone, you can do rg xterm nixos/modules

Which luckily doesn’t return too many results and reveals that it gets added to systemPackages in services/x11/xserver.nix.
You can remove it by adding it to services.xserver.excludePackages.

1 Like