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 https://github.com/NixOS/ofborg/blob/db5293a4fb219d69f5734d87af573e1940396587/ofborg/src/outpaths.nix

2 Likes

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?

2 Likes

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
[{"drvPath":"/nix/store/w5lqp055w04k3z4x7zk6570bx267w3h3-bash-5.1-p12.drv","outputs":{"out":"/nix/store/4nmqxajzaf60yjribkgvj5j54x9yvr1r-bash-5.1-p12"}}]
$ nix-store --query --requisites /nix/store/w5lqp055w04k3z4x7zk6570bx267w3h3-bash-5.1-p12.drv
/nix/store/001gp43bjqzx60cg345n2slzg7131za8-nix-nss-open-files.patch
/nix/store/01n3wxxw29wj2pkjqimmmjzv7pihzmd7-which-2.21.tar.gz.drv
/nix/store/03f77phmfdmsbfpcc6mspjfff3yc9fdj-setup-hook.sh
...
/nix/store/d0ivnqxcmjdg9ihdl4ww9a0c79pyl0nd-bootstrap-stage4-gcc-wrapper-10.3.0.drv
/nix/store/qw6w15ccnxib409xjpkkg9z6lkfh0121-bootstrap-stage4-stdenv-linux.drv
/nix/store/w5lqp055w04k3z4x7zk6570bx267w3h3-bash-5.1-p12.drv
1 Like

@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)

4 Likes