This is probably not important and just for curiosity, I was playing around with nix-shell and for some reason I called nix-shell when the terminal was already in a nix-shell, I thought that since I was already inside a nix-shell the command would do nothing but it seems that it just opened another nix-shell, it was necessary to type “exit” two times to go back. I was wondering why this behaviour, is this important for some applications?
This is quite useful if you want to quickly add another program to the environment: Ad hoc shell environments — nix.dev documentation
I’d also argue that it would be more surprising/less ergonomic if the command just did nothing. You asked nix to enter another shell, why should it just refuse to do that? It’s not destructive, in the worst case you just
exit and you have your original shell again.
I end up in this situation a lot, it’s not uncommon to realize you needed another package, and if you’ve done any other environment setup with
export or such you really don’t want to first have to exit the shell with all your settings again to add that package.