TIL: how to check why a Nix package is in the Nix Store
Today I was updating my laptop that runs NixOS and I noticed I have flatpak
in my Nix Store. I don’t have it explicitly installed on my system, so why do I
have it?
To figure that out, there’s the nix why-depends command (currently
experimental) that shows the dependency tree between two derivations
(“packages”).
In my case, I want to know why my system depends on nixpkgs#flatpak. For
that, I need to know the Nix store path to nixpkgs#flatpak, which I can get
with nix eval:
$ nix eval --raw nixpkgs#flatpak
/nix/store/ydhmhp6z5ydpv4r8rhi1cr1sncyavnhk-flatpak-1.16.3
Now I can feed my current-system and that store path to nix why-depends:
$ nix why-depends /run/current-system /nix/store/ydhmhp6z5ydpv4r8rhi1cr1sncyavnhk-flatpak-1.16.3
/nix/store/52ki8ls9xagvqsmr6dx16pbc2d56w1ww-nixos-system-L14-26.05.20260306.aca4d95
└───/nix/store/5mff9137s20b1n91zzg439cabbxm9fqq-system-path
└───/nix/store/f755892i3b95r5yjmgwphxszbqaxp341-xdg-desktop-portal-1.20.3
└───/nix/store/ydhmhp6z5ydpv4r8rhi1cr1sncyavnhk-flatpak-1.16.3
Now I know that flatpak is a dependency of xdg-desktop-portal, which I have
in my configuration.
And, of course, these two commands can be combined into one, to avoid copying and pasting paths around:
$ nix why-depends /run/current-system $(nix eval --raw nixpkgs#flatpak)
/nix/store/52ki8ls9xagvqsmr6dx16pbc2d56w1ww-nixos-system-L14-26.05.20260306.aca4d95
└───/nix/store/5mff9137s20b1n91zzg439cabbxm9fqq-system-path
└───/nix/store/f755892i3b95r5yjmgwphxszbqaxp341-xdg-desktop-portal-1.20.3
└───/nix/store/ydhmhp6z5ydpv4r8rhi1cr1sncyavnhk-flatpak-1.16.3
Thanks for reading! Read more?