# How to find all reverse transitive dependencies of a package?

**URL:** https://discourse.nixos.org/t/how-to-find-all-reverse-transitive-dependencies-of-a-package/18407
**Category:** Help
**Created:** [March 30, 2022, 2:55am UTC](https://discourse.nixos.org/t/how-to-find-all-reverse-transitive-dependencies-of-a-package/18407 "2022-03-30T02:55:14Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![samuela](https://discourse.nixos.org/user_avatar/discourse.nixos.org/samuela/32/2486_2.png) [@samuela](https://discourse.nixos.org/u/samuela)
#### Post date: [March 30, 2022, 2:55am UTC](https://discourse.nixos.org/t/how-to-find-all-reverse-transitive-dependencies-of-a-package/18407/1 "2022-03-30T02:55:14Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![ryantm](https://discourse.nixos.org/user_avatar/discourse.nixos.org/ryantm/32/900_2.png) [@ryantm](https://discourse.nixos.org/u/ryantm)
#### Post date: [March 30, 2022, 3:34am UTC](https://discourse.nixos.org/t/how-to-find-all-reverse-transitive-dependencies-of-a-package/18407/2 "2022-03-30T03:34:57Z")

</div>

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

---

<div class="post-metadata">

### Author: ![samuela](https://discourse.nixos.org/user_avatar/discourse.nixos.org/samuela/32/2486_2.png) [@samuela](https://discourse.nixos.org/u/samuela)
#### Post date: [March 30, 2022, 5:35am UTC](https://discourse.nixos.org/t/how-to-find-all-reverse-transitive-dependencies-of-a-package/18407/3 "2022-03-30T05:35:31Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![NobbZ](https://discourse.nixos.org/user_avatar/discourse.nixos.org/nobbz/32/7022_2.png) [@NobbZ](https://discourse.nixos.org/u/NobbZ)
#### Post date: [March 30, 2022, 6:56am UTC](https://discourse.nixos.org/t/how-to-find-all-reverse-transitive-dependencies-of-a-package/18407/4 "2022-03-30T06:56:50Z")

</div>

That sounds tricky…

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

---

<div class="post-metadata">

### Author: ![Atemu](https://discourse.nixos.org/user_avatar/discourse.nixos.org/atemu/32/10383_2.png) [@Atemu](https://discourse.nixos.org/u/Atemu)
#### Post date: [March 30, 2022, 7:04am UTC](https://discourse.nixos.org/t/how-to-find-all-reverse-transitive-dependencies-of-a-package/18407/5 "2022-03-30T07:04:12Z")

</div>

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

---

<div class="post-metadata">

### Author: ![bartsch](https://discourse.nixos.org/user_avatar/discourse.nixos.org/bartsch/32/5241_2.png) [@bartsch](https://discourse.nixos.org/u/bartsch)
#### Post date: [March 30, 2022, 7:56am UTC](https://discourse.nixos.org/t/how-to-find-all-reverse-transitive-dependencies-of-a-package/18407/6 "2022-03-30T07:56:15Z")

</div>

Including build dependencies?:

```auto
$ 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

```

---

<div class="post-metadata">

### Author: ![ElvishJerricco](https://discourse.nixos.org/user_avatar/discourse.nixos.org/elvishjerricco/32/984_2.png) [@ElvishJerricco](https://discourse.nixos.org/u/ElvishJerricco)
#### Post date: [March 30, 2022, 8:17am UTC](https://discourse.nixos.org/t/how-to-find-all-reverse-transitive-dependencies-of-a-package/18407/7 "2022-03-30T08:17:36Z")

</div>

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