How to avoid embedded nix-shell to re-use parent nix-shell's `shellHook`?

I imagine the problem here is that shellHook is also just a shell variable added to the environment like any other attr in the derivation (but one that’s a little special in that the shell initialization stuff spit out by nix-shell will eval it).

I guess you could anticipate this and unset it at the end of your shellHook.

$ shellHook='echo NO NO' nix-shell -p jq
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
NO NO

$ declare -p shellHook
declare -x shellHook="echo NO NO"

$ nix-shell -p pup
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
this path will be fetched (1.76 MiB download, 3.61 MiB unpacked):
  /nix/store/ynzdvy1lrzbfw5jn4m43zjbmk8x9lxbw-pup-unstable-2019-09-19
copying path '/nix/store/ynzdvy1lrzbfw5jn4m43zjbmk8x9lxbw-pup-unstable-2019-09-19' from 'https://cache.nixos.org'...
NO NO

$ exit
exit

$ exit
exit

$ shellHook='echo NO NO; unset shellHook' nix-shell -p jq
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
NO NO

$ declare -p shellHook
bash: declare: shellHook: not found

$ nix-shell -p pup
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
1 Like