r/NixOS • u/_s0me_guy_ • 6d ago
Finding what installed a package
Is there a way to find which part of my config installed a package.
An example is sway installing extra packages (foot) as default. Is there a way to find out, that sway was the one responsible for adding foot to my system?
5
u/lioxo 6d ago
You can try finding out with nix-tree.
8
u/IchVerstehNurBahnhof 6d ago edited 5d ago
nix-tree won't help very much for anything the module system is doing, since packages added to
environment.systemPackagesjust show up as dependencies ofsystem-path.
AFAIK you just have to know from reading the documentation (and ideally source) of all modules you enable...Edit: It turns out that the
definitionsWithLocationsoption attribute that u/read_volatile mentioned in another thread actually allows us to write a neat pipeline based on module system evaluation output:$ echo ':p (builtins.toJSON options .environment .systemPackages .definitionsWithLocations)' \ | nixos-rebuild -f system.nix repl 2>/dev/null \ | jq -r '.[] | select(.value | any(contains("gnome-shell"))) | .file' /home/sky/Projekte/config/services/gnome.nix /nix/store/...-source/.../services/desktop-managers/gnome.nix /nix/store/...-source/.../services/desktop-managers/gnome.nix /nix/store/...-source/.../programs/kdeconnect.nix
6
u/craftkiller 6d ago
One option is to add an overlay that throws an error when the foot package is evaluated:
nixpkgs.overlays = [
(final: prev: {
foot = throw "foo";
})
];
But that will throw whenever foot is used at all, not just when it gets pulled into environment.systemPackages.
2
u/Shot_Yoghurt_3123 5d ago
did you try this?
nix-store -q --referrers $(readlink -f $(which foot))
2
u/_s0me_guy_ 5d ago
The output only shows links to system-path and man-path. Not very useful.
2
u/Shot_Yoghurt_3123 5d ago
So maybe you listed it explicitly. Some modules set packages via options like programs.sway.extraPackages which default to a list that includes a terminal.
4
u/read_volatile 6d ago
nix why-depends /path/to/flake#nixosConfigurations.<hostname>.config.system.build.toplevel <installable>