Always run my shell in `nix-shell`, `nix develop`, et al.?

I use zsh as my shell, but bash seems to be very much ingrained in the Nix ecosystem. All that being said, is there a way to configure tools like nix-shell, nix run, and nix develop to drop me into a zsh instead of bash?

Currently, I have defined an alias nixs='nix-shell --command zsh'. Though this works, it has always felt ugly, like I am throwing away the ability to use --command for its true purpose, while also training my muscle memory to use a non-standard command to obtain a development shell.

Otherwise, I use the “correct” command and then manually invoke zsh, but this feels wrong as well.

Now that I am trying to learn to use Flakes and the experimental nix command, this problem has come to a head: I’d like to stop using hacky solutions to this and figure out if there’s one true way to accomplish what I’m after.

Thanks!

4 Likes

There is the project GitHub - chisui/zsh-nix-shell: zsh plugin that lets you use zsh in nix-shell shells..

Personally, I use direnv which auto-loads nix-shell, and has a nice side-effect of simply editing your current shell’s environment instead of loading a new shell, leaving me in my zsh shell. Combine this with GitHub - nix-community/nix-direnv: A fast, persistent use_nix/use_flake implementation for direnv [maintainer=@Mic92 / @bbenne10] for shell caching and flake support and it seems ideal to me, but may not work for you depending on how you use it.

3 Likes

Related Nix issue "Lighter" and "cleaner" shell for `nix develop` and `nix shell` · Issue #4609 · NixOS/nix · GitHub

4 Likes

@gh0st, thanks for those suggestions. I have been meaning to try direnv or lorri for a while now; this may be the final kick I need to actually do it.

@FRidh, I was not aware of that issue, so thanks for pointing it out. Do you know if there is some way for me to help move that effort forward?

Thanks!

2 Likes

Also try GitHub - MercuryTechnologies/nix-your-shell: A `nix` and `nix-shell` wrapper for shells other than `bash` · GitHub or older GitHub - haslersn/any-nix-shell: fish and zsh support for the nix run and nix-shell environments of the Nix package manager · GitHub

In my experience, all those tools caused some kind of problems.

If you want your shell, use -c $SHELL, or the v2 equivalent.

This is the most reliable way, and in case of trouble, it is easy to just omit the -c.

No nasty debugging what is interfering with the shell.

nix shell has --command "$SHELL" by default.
And nix-shell will always set your $SHELL to bash (whilenix shell won’t) in the new shell, so nesting nix-shell will still be bash.