Open kubukoz opened 1 year ago
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?
hmm, I think I got confused here. I thought since the prompt says bash
, we're actually in bash - but this would suggest otherwise:
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
@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
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 I'd really like to fix this but I'm not sure how to reproduce the issue.
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.
And this otherwise works with nix develop
? If I understand correctly, nix always launches bash.
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.
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.
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
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
Especially when used with direnv - it'd be nice to keep a similar UX to what plain Nix with flakes does.
devenv:
direnv with flakes: