NixOS / nix

Nix, the purely functional package manager
https://nixos.org/
GNU Lesser General Public License v2.1
12.64k stars 1.51k forks source link

`nix develop` overwrites SHELL with stdenv runtime shell #5131

Open jonringer opened 3 years ago

jonringer commented 3 years ago

Describe the bug

nix develop is meant to be a replacment for nix-shell, and provide users with packages that are the dependencies of a given derivation. However, it doesn't retain $SHELL, so people get the non-interactive bash provided by stdenv.

$ echo $SHELL
/run/current-system/sw/bin/bash
$ nix develop
$ echo $SHELL
/nix/store/kxj6cblcsd1qcbbxlmbswwrn89zcmgd6-bash-4.4-p23/bin/bash
$ nix eval .#runtimeShell
"/nix/store/kxj6cblcsd1qcbbxlmbswwrn89zcmgd6-bash-4.4-p23/bin/bash"

Steps To Reproduce

Create a flake w/ devShell, run commands from above.

Expected behavior

Be able to use existing shell

nix-env --version output

$ nix --version
nix (Nix) 2.4pre20210707_02dd6bb
xaverdh commented 3 years ago

Not sure about

provide users with packages that are the dependencies of a given derivation

The man page says "run a bash shell that provides the build environment of a derivation", so I think the current behaviour is accurate? I think this is precisely the distinction between the two use cases of "nix develop" that was pointed out here: https://github.com/NixOS/nix/issues/4609#issuecomment-898425927

jonringer commented 3 years ago

Yea, but this is different from the existing nix-shell -A behavior, which still sourced the original SHELL

[07:33:26] jon@jon-desktop /home/jon/projects/nixpkgs (master)
$ echo $SHELL
/run/current-system/sw/bin/bash
[07:33:31] jon@jon-desktop /home/jon/projects/nixpkgs (master)
$ nix-shell -A hello
this path will be fetched (0.69 MiB download, 0.69 MiB unpacked):
  /nix/store/3x7dwzq014bblazs7kq20p9hyzz0qh8g-hello-2.10.tar.gz
copying path '/nix/store/3x7dwzq014bblazs7kq20p9hyzz0qh8g-hello-2.10.tar.gz' from 'https://cache.nixos.org'...

[nix-shell:/home/jon/projects/nixpkgs]$ echo $SHELL
/nix/store/39k586qrghljxiyqvv72ni5fk89vshib-bash-interactive-4.4-p23/bin/bash

[nix-shell:/home/jon/projects/nixpkgs]$ realpath /run/current-system/sw/bin/bash
/nix/store/39k586qrghljxiyqvv72ni5fk89vshib-bash-interactive-4.4-p23/bin/bash
nixos-discourse commented 3 years ago

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/confusion-about-bash-completions-flake-related/14579/7

stale[bot] commented 2 years ago

I marked this as stale due to inactivity. → More info

jonringer commented 2 years ago

This issue can be mitigated by using tools like https://github.com/numtide/devshell which avoid using stdenv which will bring in a shell.

ncfavier commented 2 years ago

I don't understand what the issue is here precisely. nix develop does give me an interactive shell:

$ nix develop
$ readlink /proc/$$/exe
/nix/store/pa9416c0x5qa4r2z3zq701qg8gyr0c73-bash-interactive-5.1-p16/bin/bash
$ echo $SHELL
/nix/store/0d3wgx8x6dxdb2cpnq105z23hah07z7l-bash-5.1-p16/bin/bash

What is SHELL used for? I don't think the completion problems have anything to do with it, but I may be wrong.

jonringer commented 2 years ago

Well, $SHELL might be a false positive, but others were having issues with zsh being replaced with a non-interactive bash.

The original issues is almost a year old, and may have been fixed by now

TethysSvensson commented 2 years ago

Another meaning difference between the two shells, is that nix develop will put a non-interactive version of bash into $PATH.

I have been using this fix from the discourse to work around it.

jessestricker commented 2 years ago

fixed-by: #7010

ink-splatters commented 1 year ago

fixed-by: #7010

Great! Btw, is there specific reason for this issue to stay open?

nixos-discourse commented 9 months ago

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/nix-shell-pure-nix-command-equivalent/23058/12