How to find all reverse transitive dependencies of a package?

How do I get the list of all reverse transitive dependencies of a package? In other words, the set of all packages Y that in some way depend on package X.

1 Like

I think the answer to this question depends on if you have already built all the reverse transitive dependencies in your nix store. If you have, I believe there is a way to query the store to get your answer.

If you haven’t, then you need to do what OfBorg does (also what nixpkgs-update/r-ryantm does), which is compute the outpaths for (almost) all possible nixpkgs derivations, before and after editing the package, and diff them.

The code for computing the outpaths is at ofborg/outpaths.nix at db5293a4fb219d69f5734d87af573e1940396587 · NixOS/ofborg · GitHub


Huh that’s much trickier than I thought. In this case I don’t have all reverse transitive dependencies built due to the huge number of them. I’ll try the outpaths solution!

That sounds tricky…

Is this what nix-review does as well? Or how does it know what needs to be rebuilt?


Indeed. You can tell by the nix-env process it spawns that consumes gigabytes worth of memory :wink:

Including build dependencies?:

$ nix build nixpkgs#bash --dry-run --json
$ nix-store --query --requisites /nix/store/w5lqp055w04k3z4x7zk6570bx267w3h3-bash-5.1-p12.drv

@bartsch reverse dependencies, not dependencies. The equivalent command would be nix-store --query --referrers-closure /nix/store/w5lqp055w04k3z4x7zk6570bx267w3h3-bash-5.1-p12.drv, but this would only find packages that you have instantiated on your system, not everything in a given checkout of nixpkgs (i.e. more inclusive since it includes things outside a given checkout of nixpkgs, but also less inclusive since it doesn’t include anything in nixpkgs that you haven’t instantiated into .drv form on your system)