Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nix-shell breaks if bash is in scope #29960

Open
bgamari opened this issue Sep 30, 2017 · 8 comments
Open

nix-shell breaks if bash is in scope #29960

bgamari opened this issue Sep 30, 2017 · 8 comments
Labels
2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md

Comments

@bgamari
Copy link
Contributor

bgamari commented Sep 30, 2017

Issue description

Terminal handling within nix-shell appears to break if the bash derivation is in scope.

Steps to reproduce

First verify that nix-shell works if bash isn't in scope,

[ben@nixos-unstable:~]$ nix-env -e bash
uninstalling ‘bash-4.4-p12’
[ben@nixos-unstable:~]$ nix-shell '<nixpkgs>' -p rr

[nix-shell:~]$ 

Try pressing up arrow to go back in shell history, note that it works as expected. Send mouse event to TTY (e.g. click in a mouse-capable terminal emulator), note that nothing happens.

Now try bringing bash into scope,

[ben@nixos-unstable:~]$ nix-env -i bash
installing ‘bash-4.4-p12’
[ben@nixos-unstable:~]$ nix-shell '<nixpkgs>' -p rr

\[\][nix-shell:~]$\[\] 

Note how prompt is mangled, pressing up arrow key results in ^[[A being echoed to terminal instead of moving within shell history. Things are generally broken.

Technical details

  • System: 18.03pre116572.9824ca6975 (Impala), also confirmed on 17.03.
  • Nix version: nix-env (Nix) 1.11.15
  • Nixpkgs version: "18.03pre116572.9824ca6975"
  • Sandboxing enabled: build-use-sandbox = false
  • nix-shell version: nix-shell (Nix) 1.11.15
@bgamari
Copy link
Contributor Author

bgamari commented Sep 30, 2017

@cleverca22 points out on #nixos that bash lacks interactive support. I should really be using bash-interactive.

@danbst
Copy link
Contributor

danbst commented Oct 2, 2017

I observe same "picture" when run nix-shell inside nix-shell, btw

[danbst@LX:~]$ nix-shell -p stdenv

[nix-shell:~]$ nix-shell -p stdenv

\[\][nix-shell:~]$\[\] 

EDIT: oh nice, the trick from @cleverca22 fixes my issue too!

@lukateras
Copy link
Member

This is a Nix issue.

@lukateras
Copy link
Member

And I can't reproduce it with nixUnstable:

[chronos@yegatool:/tmp]$ nix-env -iA nixos.nixUnstable
installing ‘nix-unstable-1.12pre5732_fd10f6f2’
building path(s) ‘/nix/store/wkbfp2anpzcv6b16mr7h97vmr7nqjvs5-user-environment’
created 7 symlinks in user environment

[chronos@yegatool:/tmp]$ nix-shell --version
nix-shell (Nix) 1.12pre5732_fd10f6f2

[chronos@yegatool:/tmp]$ nix-env -i bash
installing 'bash-4.4-p12'

[chronos@yegatool:/tmp]$ nix-shell '<nixpkgs> -p rr
>
[chronos@yegatool:/tmp]$ nix-env -iA nixos.nixUnstable
installing ‘nix-unstable-1.12pre5732_fd10f6f2’
building path(s) ‘/nix/store/wkbfp2anpzcv6b16mr7h97vmr7nqjvs5-user-environment’
created 7 symlinks in user environment

[chronos@yegatool:/tmp]$ which nix-shell
/home/chronos/.nix-profile/bin/nix-shell

[chronos@yegatool:/tmp]$ nix-shell --version
nix-shell (Nix) 1.12pre5732_fd10f6f2

[chronos@yegatool:/tmp]$ nix-shell -p stdenv

[nix-shell:/tmp]$ nix-shell -p stdenv

[nix-shell:/tmp]$ nix-shell -p stdenv

[nix-shell:/tmp]$ 

@danbst
Copy link
Contributor

danbst commented Nov 12, 2017

Yeah, looks like NixOS/nix@c94f3d5 fixed it

@danbst
Copy link
Contributor

danbst commented Nov 12, 2017

Actually, this is quite a duplicate
#27126
NixOS/nix#756
NixOS/nix#730

And pending fix for 1.11.x
NixOS/nix#1483

@jcrben
Copy link
Contributor

jcrben commented May 6, 2018

The PR pointed to above NixOS/nix#1483 says that it's a backport...

On Darwin, I still get a broken shell if I run a pure shell (arrow buttons do not work):
image

Passing -p bashInteractive fixes the shell, but best if it's unbroken by default:
image

But on my NixOS 18.03 Thinkpad, not having the same problem. nevermind, arrow keys are also broken on NixOS

@stale
Copy link

stale bot commented Jun 4, 2020

Thank you for your contributions.

This has been automatically marked as stale because it has had no activity for 180 days.

If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity.

Here are suggestions that might help resolve this more quickly:

  1. Search for maintainers and people that previously touched the related code and @ mention them in a comment.
  2. Ask on the NixOS Discourse.
  3. Ask on the #nixos channel on irc.freenode.net.

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 4, 2020
terramagnabot pushed a commit to terramagna/nixpkgs that referenced this issue Jan 30, 2023
Apparently, `nix develop` is setting `SHELL` with a non-interactive Bash, which
causes issues such as those described here:

- NixOS/nixpkgs#29960
- NixOS/nix#2034

This commit also fallbacks to using the `bashInteractive` shell if the user
executes `nix develop` without the impure flag (which makes `builtins.getEnv`
return an empty string).

`bashInteractive` was also added as a package since, by default, `nix develop`
ships with a non-interactive bash, which would cause issues if the user, for
some reason, happens to invoke `bash` manually.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md
Projects
None yet
Development

No branches or pull requests

4 participants