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'
mkDerivation attributes are exposed as envvars. Like this:
$ nix-shell -p mercurial git --run 'echo $buildInputs'
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'"
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.