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!

2 Likes

There is the project https://github.com/chisui/zsh-nix-shell.

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 https://github.com/nix-community/nix-direnv for shell caching and flake support and it seems ideal to me, but may not work for you depending on how you use it.

2 Likes

Related Nix issue https://github.com/NixOS/nix/issues/4609

3 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!

1 Like