Nix command that works like dnf --whatrequires

Hi all,

On Fedora I can run dnf repoquery --installed --whatrequires package to find out why for example git-man is installed (required by git). Is there something similar on NixOS Unstable? I know that I can’t compare traditional package manager with Nix / NixOS but it would be interesting to know for example why I have bind installed (my suspicion is openresolv but who knows…).

Thank you.

If you have enabled the experimental feature nix-commands you can use nix why-depends to some extend:

$ nix why-depends /run/current-system /nix/store/cm19z2nqg2k97ck9qvmsz3b8pjyrp8wc-restic-rest-server-0.12.0
/nix/store/p5hrnqmakzp7dz4j4l0z3fpnphw6wkbc-nixos-system-mimas-23.05.20230516.963006a
└───/nix/store/j7rh968r29fy9jkk96nix7lcmaj0pky2-etc
    └───/nix/store/bv6r5a7p2n3l31i4651hx7qqz2cxkpam-system-units
        └───/nix/store/mj9i87667vx9wi7di3dybps1irqz1q0y-unit-restic-rest-server.service
            └───/nix/store/cm19z2nqg2k97ck9qvmsz3b8pjyrp8wc-restic-rest-server-0.12.0
$ nix why-depends /run/current-system $(which steam)
/nix/store/p5hrnqmakzp7dz4j4l0z3fpnphw6wkbc-nixos-system-mimas-23.05.20230516.963006a
└───/nix/store/ifvc9dp29m822kd72h691kb2pdbqazbg-system-path
    └───/nix/store/hq2pa3m67dxivbsfgp31qdy5bp9zr17r-steam
$ nix why-depends /run/current-system $(which bat)
'/nix/store/p5hrnqmakzp7dz4j4l0z3fpnphw6wkbc-nixos-system-mimas-23.05.20230516.963006a' does not depend on '/nix/store/vrxzbjbib2zk5zf37kydmpy62d9y8nfm-home-manager-path'
$ nix why-depends ~/.nix-profile $(which bat)
/nix/store/wjqgxjyp0sqy9s3b6ff5304ql38hikhk-user-environment
└───/nix/store/vrxzbjbib2zk5zf37kydmpy62d9y8nfm-home-manager-path

The annoying thing is, that you already need to know in advance the exact storepath you are looking for.

(bat is given as an example of something installed in the user environment)

2 Likes

Thank you very much.

I know the store path for bind but its /bin/ is not in my path so which won’t work.

I tried:

nix why-depends /run/current-system /nix/store/ywv0pi4c10ib0kmndr34fh86dhf4wax1-bind-9.18.14
'/nix/store/b3i3n63mdn1xyp7j9n7zxrl4lynyv077-nixos-system-n0-23.05.20230517.e6e3899' does not depend on '/nix/store/ywv0pi4c10ib0kmndr34fh86dhf4wax1-bind-9.18.14'

nix why-depends /run/current-system /nix/store/ywv0pi4c10ib0kmndr34fh86dhf4wax1-bind-9.18.14/bin/named
'/nix/store/b3i3n63mdn1xyp7j9n7zxrl4lynyv077-nixos-system-n0-23.05.20230517.e6e3899' does not depend on '/nix/store/ywv0pi4c10ib0kmndr34fh86dhf4wax1-bind-9.18.14'

Is it possible to figure this out in repl after loading flake?

Thank you

That path is not in your current system profile.

It might be part of another profile or of a shell, or an older generation or just some “garbage” that hasn’t been collected yet.

1 Like