nix-build --run-env sets up the environment by starting the shell in $SHELL and source'ing stdenv/generic/setup.sh there, which aborts on the shopt bash builtin in line 88.
As SHELL is assumed to be bash for nix-build. It should probably be hardcoded to be so.
minimal example:
SHELL=/var/run/current-system/sw/bin/zsh nix-build -A stdenv --run-env
fails, while
SHELL=/var/run/current-system/sw/bin/bash nix-build -A stdenv --run-env
works.