devenv icon indicating copy to clipboard operation
devenv copied to clipboard

zsh support

Open kubukoz opened this issue 2 years ago • 12 comments

Especially when used with direnv - it'd be nice to keep a similar UX to what plain Nix with flakes does.

devenv:

image

direnv with flakes:

image

kubukoz avatar Nov 13 '22 16:11 kubukoz

Here's where we set $PS1: https://github.com/cachix/devenv/blob/main/src/modules/top-level.nix#L81

How should it be adapted for zsh?

domenkozar avatar Nov 13 '22 16:11 domenkozar

hmm, I think I got confused here. I thought since the prompt says bash, we're actually in bash - but this would suggest otherwise:

image

kubukoz avatar Nov 13 '22 17:11 kubukoz

I guess with devenv your actual shell is bash and not your configured one. I guess the SHELL env gets not overwritten and is from the parent shell

shyim avatar Nov 13 '22 18:11 shyim

@domenkozar , I think the author wanted devenv to launch zsh rather than bash. It's not about PS1.

We can't really compare to direnv, it's a different beast, a more fair would be a comparison to nix-shell. It too launches bash no matter what.

There's a 7-year old issue about supporting shells other than bash in nix-shell. It's still open :see_no_evil: https://github.com/NixOS/nix/pull/545

@kubukoz , one way to check your shell from within is

echo $0

koiuo avatar Dec 08 '22 21:12 koiuo

Yeah, this is the main thing keeping me from using direnv+devenv over direnv+mkShell... forcing people into using bash isn't an option for me.

manveru avatar Dec 20 '22 17:12 manveru

@manveru I'd really like to fix this but I'm not sure how to reproduce the issue.

domenkozar avatar Dec 20 '22 19:12 domenkozar

I have this in .envrc:

watch_file devenv.nix
watch_file devenv.yaml
watch_file devenv.lock
if [[ ! "$DIRENV_ACTIVE" =~ (^|:)"$PWD"(:|$) ]]; then
  devenv shell
fi

and it starts a new bash instead of exporting the environment to zsh.

manveru avatar Dec 20 '22 19:12 manveru

And this otherwise works with nix develop? If I understand correctly, nix always launches bash.

domenkozar avatar Dec 20 '22 20:12 domenkozar

Yeah, I don't use nix develop when direnv+use flake is possible if i want to run more than one or two commands. I'd rather not spend time customizing bash to become approximately as usable as my zsh setup. TBH I'm not sure there's a way to achieve this, and for the time being I'm adopting a combination of flake-parts+mkShell+direnv+use flake, which works nicely but obviously requires quite a bit more boilerplate and lacks the immediate support for all those language environments out of the box.

manveru avatar Jan 02 '23 15:01 manveru

https://ianthehenry.com/posts/how-to-learn-nix/nix-zshell/ shows just how painful it is to support zsh. I'm going to work on #240 to fix this.

domenkozar avatar Jan 30 '23 09:01 domenkozar

any-nix-shell manages to make nix-shell -p cowsay launch a zsh shell for me with only ~2 lines of config in my home-manager setup. It'd be great if launching devenv shell did the same! I opened an issue there to discuss: https://github.com/haslersn/any-nix-shell/issues/33

jasonprado avatar Apr 24 '24 01:04 jasonprado

The following is sufficient for me:

  enterShell = ''
    exec fish
  '';

I also have this for my prompt (fish) specifically for nix-shell but it worked also for devenv shell:

  if test -n "$IN_NIX_SHELL"
    set_color cyan; printf "[nix-shell] "; set_color normal
  end

rolfschr avatar Apr 24 '24 08:04 rolfschr