Given the following shell.nix
with import <nixpkgs> {};
pkgs.mkShell {
pname = "just-testing";
shellHook = ''
echo AAAAAAAAAAAAAAAAAAA
alias doit='echo DOING IT'
echo BBBBBBBBBBBBBBBBBBB
doit
echo CCCCCCCCCCCCCCCCCCC
'';
}
nix-shell --run 'echo ZZZZZZZZZZZZZ'
gives
AAAAAAAAAAAAAAAAAAA
BBBBBBBBBBBBBBBBBBB
/nix/store/n4qv0ad1rg8rafppb4dh59n080m94bxy-stdenv-linux/setup: line 84: doit: command not found
CCCCCCCCCCCCCCCCCCC
ZZZZZZZZZZZZZ
while nix-shell --command 'echo ZZZZZZZZZZZZZ'
gives
AAAAAAAAAAAAAAAAAAA
BBBBBBBBBBBBBBBBBBB
DOING IT
CCCCCCCCCCCCCCCCCCC
ZZZZZZZZZZZZZ
In other words, changing from --command
to --run
makes the alias defined in the shellHook
disappear, (even though the echo
s indicate that the shellHook
was executed).
What is the reason for this?