How to find derivations that have already been built by various nix commands?

When initially building something with nix via some command…

E.g. say nix develop or nix flake check

…nix helpfully prints which derivations it’s evaluated to and about to build.

$ nix flake check
building '/nix/store/9flh3qfkggjjj5r5xs3yn3qwplbaynsj-python3.9-pytorch-1.11.0-rc2.drv'...
building '/nix/store/mvzmpm7y017v5ycb5mrm3rrkihywwgj8-aws-sdk-cpp-1.9.150.drv'...

However, once you’ve run it once this information is no longer shown the second time around.

Is there an easy flag to get nix commands like nix develop, nix flake check etc to spit out which derivations they’ve evaluated to after they’ve already been built?

(My main motivation is to figure out why e.g. nix develop builds different things to nix flake check)


Basically if I can get something like

nix eval --raw nixpkgs.hello

but for nix develop and friends, it would make my day.


(P.S. I’d prefer not to garbage-collect and build from scratch, these drvs take ages to build)

To answer my own question, it looks like nix --debug develop prints the top-level derivation (e.g. /nix/store/ylgp67gq5mjpjrfkxsnqrp3yxvaan1sy-nix-shell-env.drv)

However the output is quite noisy, if anyone has simpler flag I’d appreciate hearing it

Ok, I’ve nearly got it

Via eval:

For nix flake check:

nix eval --raw

For nix develop:

nix eval --raw .#devShell.x86_64-linux

Using show-derivation also works:

nix show-derivation .#devShell.x86_64-linux

Slight hiccup though:

$ ls $(nix eval --raw .#devShell.x86_64-linux)
ls: cannot access '/nix/store/bfw041cr7cv0w49wa4wvhn7fgzr3bxmk-nix-shell': No such file or directory

So I guess nix eval --raw .#devShell.x86_64-linux must not evaluate exactly like nix develop

(Is this a bug?)

1 Like

nix eval doesn’t build. So the latter is kind of expected, on top comes the fact that “devShells” usually aren’t buildable at all.

Also iirc nix eval nixpkgs#hello will tell you the output path of hello, while nix eval nixpkgs#hello.drvPath will tell you the path of the derivation.

Ah drvPath, thank you very much. It didn’t come to mind for some reason. devShell not being build-able also sounds familiar to me now, thanks!

For posterity nix path-info --derivation also seems to do the trick

I ended up with

diff \
  --side-by-side --color --width 320 --left-column \
  <(nix path-info --derivation -rsSh | sort) \
  <(nix path-info --derivation -rsSh .#devShell.x86_64-linux | sort)