Introspect nix-shell?

No. Derivation know nothing about expression it was generated from.

However, not all is lost. For example, many things are exposed as envvar!

$ # $version would work too if it had been defined 
$ nix-shell '<nixpkgs>' -A mercurial --run 'echo $name'
mercurial-4.7.1

mkDerivation attributes are exposed as envvars. Like this:

$ nix-shell -p mercurial git --run 'echo $buildInputs'
/nix/store/0x53zl7psb03352nhwlpyd8bqvqsd97b-mercurial-4.7.1 /nix/store/qcn9ck2zfk9bj5m3g1jv0lcc9yicjq2j-git-2.19.1

I’d wish realized derivation know it’s originating .drv file. In some cases it is possible to get this information from nix DB:

$ nix-shell -p sqlite

[nix-shell] $ sudo sqlite3 "/nix/var/nix/db/db.sqlite" \
      "select deriver from ValidPaths where path = '$buildInputs'"
/nix/store/x5g0bbjf00x8944mna1rwj1bpjk95rjv-sqlite-3.24.0.drv

And drv can be inspected:

$ nix-shell -p jq
$ nix show-derivation /nix/store/x5g0bbjf00x8944mna1rwj1bpjk95rjv-sqlite-3.24.0.drv \
  | jq ....

Unfortunately, nix DB doesn’t contain all backwards mappings store path → derivation, so this method isn’t reliable too.

2 Likes