# Using \`nix develop\` opens \`bash\` instead of \`zsh\`

**URL:** https://discourse.nixos.org/t/using-nix-develop-opens-bash-instead-of-zsh/25075
**Category:** Help
**Created:** [January 30, 2023, 8:45am UTC](https://discourse.nixos.org/t/using-nix-develop-opens-bash-instead-of-zsh/25075 "2023-01-30T08:45:18Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![eureka-cpu](https://discourse.nixos.org/user_avatar/discourse.nixos.org/eureka-cpu/32/32567_2.png) [@eureka-cpu](https://discourse.nixos.org/u/eureka-cpu)
#### Post date: [January 30, 2023, 8:45am UTC](https://discourse.nixos.org/t/using-nix-develop-opens-bash-instead-of-zsh/25075/1 "2023-01-30T08:45:18Z")

</div>

So I’m using this [flake](https://github.com/FuelLabs/fuel.nix) specifically the command `nix develop github:fuellabs/fuel.nix#sway-dev` and when it opens up a new shell it chooses `bash` when I have `zsh` specified for my user in my `configuration.nix`. I see on the [wiki](https://nixos.wiki/wiki/Development_environment_with_nix-shell) that it does say a `bash` shell will open. Is there any way I can configure this?

EDIT: I wrote this wrapper for `nix shell`/`nix develop`/`nix-shell` for anyone who wants a unix-like command alternative that handles user shell as idiomatically as possible: [GitHub - eureka-cpu/ns: A unified interface for nix shell. · GitHub](https://github.com/eureka-cpu/ns)

---

<div class="post-metadata">

### Author: ![eureka-cpu](https://discourse.nixos.org/user_avatar/discourse.nixos.org/eureka-cpu/32/32567_2.png) [@eureka-cpu](https://discourse.nixos.org/u/eureka-cpu)
#### Post date: [January 30, 2023, 9:11am UTC](https://discourse.nixos.org/t/using-nix-develop-opens-bash-instead-of-zsh/25075/2 "2023-01-30T09:11:39Z")

</div>

I’ve found this very long [thread](https://ianthehenry.com/posts/how-to-learn-nix/nix-zshell/) that seems reasonable. And from reading the portion in the [reference manual](https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-develop.html#name) it seems this was developed only with the intention of supplying the user with a `bash` shell.

---

<div class="post-metadata">

### Author: ![eureka-cpu](https://discourse.nixos.org/user_avatar/discourse.nixos.org/eureka-cpu/32/32567_2.png) [@eureka-cpu](https://discourse.nixos.org/u/eureka-cpu)
#### Post date: [January 30, 2023, 9:12am UTC](https://discourse.nixos.org/t/using-nix-develop-opens-bash-instead-of-zsh/25075/3 "2023-01-30T09:12:18Z")

</div>

Still if anyone has any shorter or more direct route I’m all ears!

---

<div class="post-metadata">

### Author: ![iFreilicht](https://discourse.nixos.org/user_avatar/discourse.nixos.org/ifreilicht/32/9702_2.png) [@iFreilicht](https://discourse.nixos.org/u/iFreilicht)
#### Post date: [January 30, 2023, 9:31am UTC](https://discourse.nixos.org/t/using-nix-develop-opens-bash-instead-of-zsh/25075/4 "2023-01-30T09:31:09Z")

</div>

When you run that `nix develop` command, nix downloads [this file](https://github.com/FuelLabs/fuel.nix/blob/fe731c4c8bdad8c24b1bcee8eb3b235d7db59013/flake.nix) and builds the `sway-dev` output, which is defined using the `pkgs.mkShell` function.

In the [mkShell docs](https://ryantm.github.io/nixpkgs/builders/special/mkshell/), a parameter `shellHook` is mentioned. In that hook you should be able to start zsh if it’s installed into the environment.

So you have to create your own flake.nix file and basically override that argument.

You could just download the flake I linked above, modify `sway-dev` to launch into zsh and then run `nix develop .#sway-dev`. This should work with your locally installed zsh, but ideally you would use `${pkgs.zsh}` in the hook and add that to the `packages` argument as well.

Maybe something to try first: can you manually start zsh inside the nix shell?

---

<div class="post-metadata">

### Author: ![nurelin](https://discourse.nixos.org/user_avatar/discourse.nixos.org/nurelin/32/5276_2.png) [@nurelin](https://discourse.nixos.org/u/nurelin)
#### Post date: [January 30, 2023, 12:03pm UTC](https://discourse.nixos.org/t/using-nix-develop-opens-bash-instead-of-zsh/25075/5 "2023-01-30T12:03:39Z")

</div>

You can also try `nix develop github:fuellabs/fuel.nix#sway-dev -c $SHELL` to launch your shell.

---

<div class="post-metadata">

### Author: ![jonringer](https://discourse.nixos.org/user_avatar/discourse.nixos.org/jonringer/32/1348_2.png) [@jonringer](https://discourse.nixos.org/u/jonringer)
#### Post date: [January 30, 2023, 4:03pm UTC](https://discourse.nixos.org/t/using-nix-develop-opens-bash-instead-of-zsh/25075/6 "2023-01-30T16:03:51Z")

</div>

or more generically:

```auto
nix develop -c $SHELL

```

or you can use [direnv](https://direnv.net/) which doesn’t change your shell after creating a cache.

---

<div class="post-metadata">

### Author: ![eureka-cpu](https://discourse.nixos.org/user_avatar/discourse.nixos.org/eureka-cpu/32/32567_2.png) [@eureka-cpu](https://discourse.nixos.org/u/eureka-cpu)
#### Post date: [January 30, 2023, 9:49pm UTC](https://discourse.nixos.org/t/using-nix-develop-opens-bash-instead-of-zsh/25075/7 "2023-01-30T21:49:11Z")

</div>

I ended up going with this solution and just set it under the alias `swaydev`

---

<div class="post-metadata">

### Author: ![eureka-cpu](https://discourse.nixos.org/user_avatar/discourse.nixos.org/eureka-cpu/32/32567_2.png) [@eureka-cpu](https://discourse.nixos.org/u/eureka-cpu)
#### Post date: [October 7, 2023, 4:42am UTC](https://discourse.nixos.org/t/using-nix-develop-opens-bash-instead-of-zsh/25075/8 "2023-10-07T04:42:50Z")

</div>

`nix-shell --help` actually has a section which is helpful and exporting this in your `configuration.nix` or your shell config file will use whatever shell you specify.

```sh
Environment variables
       • NIX_BUILD_SHELL
         Shell used to start the interactive environment. Defaults to the bash found in <nixpkgs>, falling back to the
         bash found in PATH if not found.

```

---

<div class="post-metadata">

### Author: ![eureka-cpu](https://discourse.nixos.org/user_avatar/discourse.nixos.org/eureka-cpu/32/32567_2.png) [@eureka-cpu](https://discourse.nixos.org/u/eureka-cpu)
#### Post date: [October 12, 2023, 6:47am UTC](https://discourse.nixos.org/t/using-nix-develop-opens-bash-instead-of-zsh/25075/9 "2023-10-12T06:47:27Z")

</div>

Coming back here to say that Nix for some reason expects a bash derivative for `NIX_BUILD_SHELL` so `zsh` doesn’t actually work there. There is a package [GitHub - chisui/zsh-nix-shell: zsh plugin that lets you use zsh in nix-shell shells.](https://github.com/chisui/zsh-nix-shell) that helps to some degree. If an alias isn’t out of the question that also works in some instances but not with `nix-shell` directly. Adding `-c <shell>` to a `nix develop` command works, and also just `zsh` after `nix-shell` works. Unfortunately no clean way of just using the user’s default shell as of now.

---

<div class="post-metadata">

### Author: ![eureka-cpu](https://discourse.nixos.org/user_avatar/discourse.nixos.org/eureka-cpu/32/32567_2.png) [@eureka-cpu](https://discourse.nixos.org/u/eureka-cpu)
#### Post date: [October 12, 2023, 7:06am UTC](https://discourse.nixos.org/t/using-nix-develop-opens-bash-instead-of-zsh/25075/10 "2023-10-12T07:06:44Z")

</div>

Hey iFreilicht, before you had said I should be able to start zsh if it’s installed into the environment. Is there a way I could open any user’s shell in the shell hook?

---

<div class="post-metadata">

### Author: ![iFreilicht](https://discourse.nixos.org/user_avatar/discourse.nixos.org/ifreilicht/32/9702_2.png) [@iFreilicht](https://discourse.nixos.org/u/iFreilicht)
#### Post date: [October 12, 2023, 12:10pm UTC](https://discourse.nixos.org/t/using-nix-develop-opens-bash-instead-of-zsh/25075/11 "2023-10-12T12:10:10Z")

</div>

Jup, seems like it. I just tested with this flake.nix:

```auto
{
  outputs = { self, nixpkgs }:
    let
      system = "aarch64-darwin";
      pkgs = nixpkgs.legacyPackages.${system};
    in {
      devShells.${system}.default = pkgs.mkShell {
        shellHook = ''
          $SHELL
        '';
      };
    };
}

```

and that works perfectly fine. There is the small issue that you have to Ctrl+D twice to go back out, and you _could_ fix that by adding `exit` underneath `$SHELL` in the shellHook, but I think this caused some unexpected issues in the past for me, can’t remember what it was, though.

Interestingly, when replacing `$SHELL` with `echo "$SHELL"`, I get `/bin/zsh`, even when running `nix develop --ignore-environment`.

---

<div class="post-metadata">

### Author: ![cyberjar09](https://discourse.nixos.org/user_avatar/discourse.nixos.org/cyberjar09/32/12228_2.png) [@cyberjar09](https://discourse.nixos.org/u/cyberjar09)
#### Post date: [December 16, 2023, 2:10pm UTC](https://discourse.nixos.org/t/using-nix-develop-opens-bash-instead-of-zsh/25075/12 "2023-12-16T14:10:55Z")

</div>

I needed to start a `pipenv shell` and also switch to `zsh` as a “developer env”

- had issues with nested shells when I add `zsh` and `pipenv shell` to `shellHook`
- depending on the order, either the pipenv shell will trigger and not enter zsh or vice versa

I have had decent success with:

- not adding anything to `shellHook`
- starting my dev shell using `nix develop --command $SHELL -c "pipenv shell"`

p.s. I use a `Taskfile.yaml` and just made it a standard command like `task dev`

hope it helps 🙂

---

<div class="post-metadata">

### Author: ![augu5te](https://discourse.nixos.org/user_avatar/discourse.nixos.org/augu5te/32/5238_2.png) [@augu5te](https://discourse.nixos.org/u/augu5te)
#### Post date: [December 31, 2023, 9:06am UTC](https://discourse.nixos.org/t/using-nix-develop-opens-bash-instead-of-zsh/25075/13 "2023-12-31T09:06:37Z")

</div>

Other way to address “Ctrl+D twice” issue add `exec` built-in command before `$SHELL`. It seems preferable since exec replaces the current shell process with a new one and _could_ be more reliable.

---

<div class="post-metadata">

### Author: ![bobvanderlinden](https://discourse.nixos.org/user_avatar/discourse.nixos.org/bobvanderlinden/32/59_2.png) [@bobvanderlinden](https://discourse.nixos.org/u/bobvanderlinden)
#### Post date: [December 31, 2023, 9:39am UTC](https://discourse.nixos.org/t/using-nix-develop-opens-bash-instead-of-zsh/25075/14 "2023-12-31T09:39:13Z")

</div>

> [@iFreilicht](#):
>
> Interestingly, when replacing `$SHELL` with `echo "$SHELL"`, I get `/bin/zsh`, even when running `nix develop --ignore-environment`.

This is indeed confusing, maybe even a bug. Related issue: [`nix develop` does not set `SHELL` correctly · Issue #7971 · NixOS/nix · GitHub](https://github.com/NixOS/nix/issues/7971)

---

<div class="post-metadata">

### Author: ![mboyea](https://discourse.nixos.org/user_avatar/discourse.nixos.org/mboyea/32/28639_2.png) [@mboyea](https://discourse.nixos.org/u/mboyea)
#### Post date: [December 14, 2024, 8:44am UTC](https://discourse.nixos.org/t/using-nix-develop-opens-bash-instead-of-zsh/25075/15 "2024-12-14T08:44:52Z")

</div>

Hello!  
A good solution is to set the following alias for `nix-shell` and `nix develop` in your shell rc file.

```bash
alias nix-shell='nix-shell --run $SHELL'
nix() {
  if [[$1 == "develop"]]; then
    shift
    command nix develop -c $SHELL "$@"
  else
    command nix "$@"
  fi
}

```

For zsh, I added this to my `zshrc` file.

Now when I type `nix-shell` or `nix develop`, it opens zsh instead of bash.  
Hope this helps!

---

<div class="post-metadata">

### Author: ![malikwirin](https://discourse.nixos.org/user_avatar/discourse.nixos.org/malikwirin/32/31033_2.png) [@malikwirin](https://discourse.nixos.org/u/malikwirin)
#### Post date: [December 14, 2024, 2:29pm UTC](https://discourse.nixos.org/t/using-nix-develop-opens-bash-instead-of-zsh/25075/16 "2024-12-14T14:29:02Z")

</div>

Shouldn’t this be the default?

---

<div class="post-metadata">

### Author: ![waffle8946](https://discourse.nixos.org/user_avatar/discourse.nixos.org/waffle8946/32/27221_2.png) [@waffle8946](https://discourse.nixos.org/u/waffle8946)
#### Post date: [January 7, 2025, 9:53pm UTC](https://discourse.nixos.org/t/using-nix-develop-opens-bash-instead-of-zsh/25075/17 "2025-01-07T21:53:47Z")

</div>

I use (via `use flake`) `direnv` to keep my shell.

---

<div class="post-metadata">

### Author: ![Adda](https://discourse.nixos.org/user_avatar/discourse.nixos.org/adda/32/10099_2.png) [@Adda](https://discourse.nixos.org/u/Adda)
#### Post date: [January 8, 2025, 5:51am UTC](https://discourse.nixos.org/t/using-nix-develop-opens-bash-instead-of-zsh/25075/18 "2025-01-08T05:51:14Z")

</div>

_For reference:_  
I use

> **[GitHub - MercuryTechnologies/nix-your-shell: A \`nix\` and \`nix-shell\` wrapper for shells other...](https://github.com/MercuryTechnologies/nix-your-shell)**
>
> A \`nix\` and \`nix-shell\` wrapper for shells other than \`bash\`

from

> [@Shell prompt for 'nix develop'](https://discourse.nixos.org/t/shell-prompt-for-nix-develop/40980/6):
>
> I use [GitHub - MercuryTechnologies/nix-your-shell: A `nix` and `nix-shell` wrapper for shells other than `bash`](https://github.com/MercuryTechnologies/nix-your-shell) for this

which works perfectly for me. And there is no need to use direnv all the time, either.

Then there is also

> **[GitHub - haslersn/any-nix-shell: fish and zsh support for the nix run and nix-shell...](https://github.com/haslersn/any-nix-shell)**
>
> fish and zsh support for the nix run and nix-shell environments of the Nix package manager

---

<div class="post-metadata">

### Author: ![musjj](https://discourse.nixos.org/user_avatar/discourse.nixos.org/musjj/32/10261_2.png) [@musjj](https://discourse.nixos.org/u/musjj)
#### Post date: [December 28, 2025, 2:00pm UTC](https://discourse.nixos.org/t/using-nix-develop-opens-bash-instead-of-zsh/25075/19 "2025-12-28T14:00:59Z")

</div>

This trick doesn’t seem to work anymore. `$SHELL` always returns `bash` for me.

---

<div class="post-metadata">

### Author: ![NobbZ](https://discourse.nixos.org/user_avatar/discourse.nixos.org/nobbz/32/7022_2.png) [@NobbZ](https://discourse.nixos.org/u/NobbZ)
#### Post date: [December 28, 2025, 2:05pm UTC](https://discourse.nixos.org/t/using-nix-develop-opens-bash-instead-of-zsh/25075/20 "2025-12-28T14:05:25Z")

</div>

Within the shellhook, that’s expected.

Either use (`nix-`)`direnv` to remain in your shell or use `nix develop -c $SHELL`.

Also, the shellhook should _never_ start interactive programs, as the actual shell would only be entered _after_ the shellhook finished executing.

[Next page](https://discourse.nixos.org/t/using-nix-develop-opens-bash-instead-of-zsh/25075.md?page=2)
