Nix-shell as interpreter cause different output

I’m currently developing a project and I wrote a shell.nix. I have a script to build the project. Now I found some inconsistent behavior with nix-shell. I use cmake to build all code. if I do

$ nix-shell
$ ./

it works fine. If I instead use this script:

#!/usr/bin/env nix-shell
#!nix-shell shell.nix
#!nix-shell -i "zsh"
# same content in ./

still works fine, but it will cause additional outputs(some -Wmaybe-uninitialized warnings)

I checked the env command and notice that the stdenv variable is different in the two cases. The shell.nix import a pinned nixpkgs but it’s currently the same with the global one. So what cause this? It’s not necessary an issue but it introduces some inconsistency (from my point-of-view).

I think that you mean to write is nix-shell -i zsh shell.nix rather than two invocations of nix-shell?

The two should be equivalent, nix-shell supports having multiple #!nix-shell lines and joins the arguments together.