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
/nix/store/2rkf9d0lc6f5cjfsznki5hs4pjn4gi9f-xterm-375
/nix/store/ci07973sm48pvk1k402h6lcs6f64chgy-system-path
/nix/store/hpnbrli2rqga7i3p357q47g3fpqy45mf-system-path
/nix/store/isnnp0kyn6n7ah0w1j0cxcsqpb2b1njf-system-path
/nix/store/ly9klxx5nc89cmsz74ilsmcby8158lzp-system-path
/nix/store/nr049757k47ys6bniwrbdzz97rhy946p-system-path
/nix/store/prr16z555a78p4nmm8p3aigywjm18bfs-system-path
/nix/store/xkd0aqbjqmy14pgx7d9xa78mavzvnc98-system-path

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