Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zsh support #36

Open
kubukoz opened this issue Nov 13, 2022 · 14 comments
Open

zsh support #36

kubukoz opened this issue Nov 13, 2022 · 14 comments

Comments

@kubukoz
Copy link

kubukoz commented Nov 13, 2022

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

@domenkozar
Copy link
Member

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?

@kubukoz
Copy link
Author

kubukoz commented Nov 13, 2022

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

@shyim
Copy link
Contributor

shyim commented Nov 13, 2022

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

@koiuo
Copy link

koiuo commented Dec 8, 2022

@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 🙈
NixOS/nix#545

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

echo $0

@manveru
Copy link

manveru commented Dec 20, 2022

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.

@domenkozar
Copy link
Member

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

@manveru
Copy link

manveru commented Dec 20, 2022

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.

@domenkozar
Copy link
Member

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

@manveru
Copy link

manveru commented Jan 2, 2023

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.

@domenkozar
Copy link
Member

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 pushed a commit that referenced this issue Jun 1, 2023
@jasonprado
Copy link

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: haslersn/any-nix-shell#33

@rolfschr
Copy link

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

@agj
Copy link

agj commented Jan 29, 2025

Hello! Ran into this problem today. When using plain Nix flakes, I use nix develop -c $SHELL to start it in my own choice of shell. It's easy to put that command in a task runner and make it easy for the whole team. But there's no similar option with devenv shell that I could find. Any chance that this flag could be added?

@Shyrogan
Copy link

Shyrogan commented Feb 7, 2025

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

While this works, it kinda gets annoying when working with services, running devenv up will open a new fish shell instead of opening the terminal UI for services.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants