Hello,
I recently upgraded nix to the 2.4 release and tried to use the new experimental nix commands after modifying nix.conf.
However, I have been unable to make nix shell work properly. The command succeeds and opens a new shell, however that shell is almost identical to the one I started on. In particular, it does not contain the packages I requested…
I tried running the examples shown in the nix shell help page: opening a new shell does not seem to work, but executing a command in a single line does.
For example
nix shell nixpkgs#hello
hello
breaks, while
nix shell nixpkgs#hello -c hello
works properly.
Is this intended? Am I misunderstanding something?
(by the way, before the upgrade nix run behaved in the same way, only with it being called nix run I was more confident that it was intended…)
First form worked fine for me. There’s probably something in one of your shell rc/profile files (perhaps hard-setting the path too late, or returning early).
My bash profile only has the line added by the nix installer, my bashrc contains direnv and a few aliases, I suppose it may be something in the profile defaults from the distro (which are sourced at the start of bashrc).
Any idea on how to debug this?
When is too late for the path, anyway? Understandably the distro sets the path, but that is the first line executed in the bashrc…
Does the nix code for preparing the shell execute before or after the shell rc/profiles?
nix develop nixpkgs#hello gives me a shell with gcc, patchelf, tar, make and other stuff inside the PATH, which matches my expectations of the build environment
The difference, if I understand the nix code, is that nix shell sets the environment with setenv and then expects the PATH to propagate to the shell/command, while nix develop sets the environment by creating a temporary rc file which contains the global bashrc + the custom nix environment.
nix shell is meant to “enhance” or “augment” the current environment, while nix develop is meant to recreate an environment that comes close to the actual build environment.