MercuryTechnologies / nix-your-shell

A `nix` and `nix-shell` wrapper for shells other than `bash`
MIT License
85 stars 12 forks source link

`nix shell` works correctly but `nix-shell` still uses bash #53

Closed Samyak2 closed 3 months ago

Samyak2 commented 3 months ago

Firstly, thank you for this tool.


I have set up nix-your-shell for zsh in my home-manager. zsh is my default login shell too. I used the following configuration (paraphrased, not an exact snippet from my config):

programs.zsh.initExtra = ''
  ${pkgs.nix-your-shell}/bin/nix-your-shell zsh | source /dev/stdin
''

Now when I use nix shell, it works correctly and I'm dropped into zsh:

~
❯ which $SHELL
/run/current-system/sw/bin/zsh

~
❯ nix shell nixpkgs#ripgrep

~
❯ which $SHELL
/run/current-system/sw/bin/zsh

But with nix-shell, I'm dropped into bash:

~
❯ which $SHELL
/run/current-system/sw/bin/zsh

~
❯ nix-shell -p ripgrep

~ via ❄️  impure (shell)
❯ which $SHELL
/nix/store/032wiarm65zp3bh9ak3dz2sqcr3n8g70-bash-interactive-5.2p26/bin/bash

~ via ❄️  impure (shell)
❯

I don't have any other alias set up for nix-shell. Not sure where to start looking for the problem. I'm somewhat new to nix, so let me know if I got something wrong here.

9999years commented 3 months ago

Hmm. I can reproduce this. I think what's going on is it does actually launch you into zsh (echo "$0" shows zsh on my machine), but it doesn't update the $SHELL variable:

> echo $SHELL
/opt/homebrew/bin/fish
> bash
$ echo $SHELL
/opt/homebrew/bin/fish
$ exec zsh
% echo $SHELL
/opt/homebrew/bin/fish

I'm not sure how to fix this!

9999years commented 3 months ago

Apparently this is expected behavior:

SHELL always (well, if not set manually) expands to the login shell (defined in /etc/passwd) of the user, not necessarily the shell [the] user [is] currently using. — https://askubuntu.com/a/748523

I'm going to close this issue. Is this behavior causing you any issues? Is your zsh config available as expected in nix-shell? If you're having trouble, feel free to re-open this.

Samyak2 commented 3 months ago

You're right! It is zsh. I had given up after checking $SHELL and did not try to use the shell to verify that it is indeed zsh. I had starship enabled on both bash and zsh, so both the prompts looked the same either way.

TIL. Thank you!