# Nix-shell does not use my user's shell (zsh)

**URL:** https://discourse.nixos.org/t/nix-shell-does-not-use-my-users-shell-zsh/5588
**Category:** Help
**Created:** [January 22, 2020, 12:31am UTC](https://discourse.nixos.org/t/nix-shell-does-not-use-my-users-shell-zsh/5588 "2020-01-22T00:31:49Z")
**Posts on this page:** 19
**Page:** 1

<div class="post-metadata">

### Author: ![trusktr](https://discourse.nixos.org/user_avatar/discourse.nixos.org/trusktr/32/1994_2.png) [@trusktr](https://discourse.nixos.org/u/trusktr)
#### Post date: [January 22, 2020, 12:31am UTC](https://discourse.nixos.org/t/nix-shell-does-not-use-my-users-shell-zsh/5588/1 "2020-01-22T00:31:49Z")

</div>

Why doesn’t nix-shell use my shell, zsh?

EDIT: Using [GitHub - chisui/zsh-nix-shell: zsh plugin that lets you use zsh in nix-shell shells.](https://github.com/chisui/zsh-nix-shell) was easy enough to solve the problem (but it only works with `nix-shell` and not `nix run`). Is there an official way to do it?

---

<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: [January 22, 2020, 8:55am UTC](https://discourse.nixos.org/t/nix-shell-does-not-use-my-users-shell-zsh/5588/2 "2020-01-22T08:55:40Z")

</div>

I’m pretty sure that is related to reproducibility.

If there is a zsh for you and bash for everyone else, then the environments aren’t the same anymore.

---

<div class="post-metadata">

### Author: ![trusktr](https://discourse.nixos.org/user_avatar/discourse.nixos.org/trusktr/32/1994_2.png) [@trusktr](https://discourse.nixos.org/u/trusktr)
#### Post date: [January 22, 2020, 8:12pm UTC](https://discourse.nixos.org/t/nix-shell-does-not-use-my-users-shell-zsh/5588/3 "2020-01-22T20:12:53Z")

</div>

I set zsh as the system shell for “everyone”. It’ll be only me using my personal laptop anyways, no one else.

---

<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: [January 22, 2020, 8:25pm UTC](https://discourse.nixos.org/t/nix-shell-does-not-use-my-users-shell-zsh/5588/4 "2020-01-22T20:25:50Z")

</div>

And all the other computers? That you do not own and control?

Bash is the “guaranteed” shell on nix. It has to be the default environment to run things in. If you need something else, you probably need to build your own `stdenv` which provides another shell.

---

<div class="post-metadata">

### Author: ![trusktr](https://discourse.nixos.org/user_avatar/discourse.nixos.org/trusktr/32/1994_2.png) [@trusktr](https://discourse.nixos.org/u/trusktr)
#### Post date: [January 22, 2020, 8:34pm UTC](https://discourse.nixos.org/t/nix-shell-does-not-use-my-users-shell-zsh/5588/5 "2020-01-22T20:34:11Z")

</div>

> [@NobbZ](#):
>
> And all the other computers? That you do not own and control?

Not sure what you mean. I’m not asking for zsh to be the default for NixOS, I’m just asking how to make zsh the default _just for me_.

> [@NobbZ](#):
>
> you probably need to build your own `stdenv`

That is too advanced for me right now (given the time constraints that I have and needing to get to work on some deliverables that I’ve put off while learning the awesome NixOS).

It’d be neat if nixpkgs had an official option. That’s something for later though.

I’ll use `chisui/zsh-nix-shell` for now. I’ve opened an issue in that repo asking about support for `nix run` too.

---

<div class="post-metadata">

### Author: ![jtojnar](https://discourse.nixos.org/user_avatar/discourse.nixos.org/jtojnar/32/70_2.png) [@jtojnar](https://discourse.nixos.org/u/jtojnar)
#### Post date: [January 22, 2020, 8:37pm UTC](https://discourse.nixos.org/t/nix-shell-does-not-use-my-users-shell-zsh/5588/6 "2020-01-22T20:37:56Z")

</div>

Well, the main issue is that generic builder is written in bash. `nix-shell`, among other things, is supposed to place you into the development environment where you can call the bash functions manually. For the other use cases it is not necessary and we have several issues open about that:

- [nix-build: support for non-bash shells with nix-build / nix-shell · Issue #498 · NixOS/nix · GitHub](https://github.com/NixOS/nix/issues/498)
- [nix-shell ignoring SHELL enviroment variable · Issue #419 · NixOS/nix · GitHub](https://github.com/NixOS/nix/issues/419)
- [Support non-bash shells in nix-shell. by gebner · Pull Request #545 · NixOS/nix · GitHub](https://github.com/NixOS/nix/pull/545)

Personally, I just run `nix-shell … --run fish` when I do not need to access builder functions.

---

<div class="post-metadata">

### Author: ![trusktr](https://discourse.nixos.org/user_avatar/discourse.nixos.org/trusktr/32/1994_2.png) [@trusktr](https://discourse.nixos.org/u/trusktr)
#### Post date: [January 23, 2020, 12:00am UTC](https://discourse.nixos.org/t/nix-shell-does-not-use-my-users-shell-zsh/5588/7 "2020-01-23T00:00:15Z")

</div>

> [@jtojnar](#):
>
> Personally, I just run `nix-shell … --run fish` when I do not need to access builder functions.

Yeah, basically I only been using `nix-shell` so that I can spin up a new shell with certain binaries present, but not needing the nixos-specific build commands. F.e. to make shells with different versions of `node` or `electron`.

---

<div class="post-metadata">

### Author: ![michaelpj](https://discourse.nixos.org/user_avatar/discourse.nixos.org/michaelpj/32/215_2.png) [@michaelpj](https://discourse.nixos.org/u/michaelpj)
#### Post date: [January 23, 2020, 4:25pm UTC](https://discourse.nixos.org/t/nix-shell-does-not-use-my-users-shell-zsh/5588/8 "2020-01-23T16:25:08Z")

</div>

If you’re using it for that, you may well be better off using [lorri](https://github.com/target/lorri).

---

<div class="post-metadata">

### Author: ![gilescope](https://discourse.nixos.org/user_avatar/discourse.nixos.org/gilescope/32/1909_2.png) [@gilescope](https://discourse.nixos.org/u/gilescope)
#### Post date: [July 29, 2021, 11:26am UTC](https://discourse.nixos.org/t/nix-shell-does-not-use-my-users-shell-zsh/5588/9 "2021-07-29T11:26:18Z")

</div>

nix-shell should honor $SHELL when in interactive mode. I don’t buy that you should be forced to drop into bash as a human. I’m happy to be in a zsh inside a bash, but it seems uncouth to disregard the system shell preference. We wouldn’t drop into nano if EDITOR=vi.

---

<div class="post-metadata">

### Author: ![luochen1990](https://discourse.nixos.org/user_avatar/discourse.nixos.org/luochen1990/32/3092_2.png) [@luochen1990](https://discourse.nixos.org/u/luochen1990)
#### Post date: [November 23, 2021, 9:38am UTC](https://discourse.nixos.org/t/nix-shell-does-not-use-my-users-shell-zsh/5588/10 "2021-11-23T09:38:01Z")

</div>

Thanks, that helps a lot.  
Maybe we should treat `nix-shell` as tool for package builder, not for package users. So maybe we need some other tools to provide virtural environment for package users?

---

<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: [November 23, 2021, 9:43am UTC](https://discourse.nixos.org/t/nix-shell-does-not-use-my-users-shell-zsh/5588/11 "2021-11-23T09:43:56Z")

</div>

`nix-shell` is indeed a tool for package developers.

The experimental commands provide `nix run` (2.3)/`nix shell` (2.4) which are meant to be used by package consumers.

There is no such tool in the stable commands. `nix-shell -p` comes closest, but still enforces `bash`.

---

<div class="post-metadata">

### Author: ![tobiasBora](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/t/9de0a6/32.png) [@tobiasBora](https://discourse.nixos.org/u/tobiasBora)
#### Post date: [September 6, 2022, 9:16pm UTC](https://discourse.nixos.org/t/nix-shell-does-not-use-my-users-shell-zsh/5588/12 "2022-09-06T21:16:46Z")

</div>

I’m not sure what’s the status of this now but I can confirm that any-nix-shell worked for me. There is also a more manual approach presented here [How to Learn Nix, Part 42: Running zsh in nix-shell](https://ianthehenry.com/posts/how-to-learn-nix/nix-zshell/)

Edit: or you can manually start zsh once you are in the shell ^^

---

<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:49am UTC](https://discourse.nixos.org/t/nix-shell-does-not-use-my-users-shell-zsh/5588/13 "2024-12-14T08:49:13Z")

</div>

Hello!  
I also had this problem. I found that `nix-shell --run $SHELL` and `nix develop -c $SHELL` would both open ZSH as I preferred, so my solution was to make a bash alias for these two functions.

Add the following to 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: ![supermarin](https://discourse.nixos.org/user_avatar/discourse.nixos.org/supermarin/32/9149_2.png) [@supermarin](https://discourse.nixos.org/u/supermarin)
#### Post date: [March 13, 2025, 12:25pm UTC](https://discourse.nixos.org/t/nix-shell-does-not-use-my-users-shell-zsh/5588/14 "2025-03-13T12:25:59Z")

</div>

Hm, I’m running into the same issue with fish.  
Set up fish as recommended per [nixos wiki](https://nixos.wiki/wiki/Fish) (bash as login shell, then execute fish if interactive).

> **code**
>
> ```auto
> programs.bash = {
> interactiveShellInit = ''
> if [[$(${pkgs.procps}/bin/ps --no-header --pid=$PPID --format=comm) != "fish" && -z ''${BASH_EXECUTION_STRING}]]
> then
> shopt -q login_shell && LOGIN_OPTION='--login' || LOGIN_OPTION=""
> exec ${pkgs.fish}/bin/fish $LOGIN_OPTION
> fi
> '';
> };
> 
> ```

Default nix shell uses bash, and this hits my snippet so I do end up in fish, but nix shell is not activated. Weirdly enough, getting into nix shell through direnv works. So only `nix shell` part is broken.

---

<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: [March 13, 2025, 12:28pm UTC](https://discourse.nixos.org/t/nix-shell-does-not-use-my-users-shell-zsh/5588/15 "2025-03-13T12:28:35Z")

</div>

Use the current wiki at [wiki.nixos.org](http://wiki.nixos.org), not the dead wiki.  
Also, `nix shell` already respects your current shell, the question is only for `nix-shell` (different command entirely).

---

<div class="post-metadata">

### Author: ![supermarin](https://discourse.nixos.org/user_avatar/discourse.nixos.org/supermarin/32/9149_2.png) [@supermarin](https://discourse.nixos.org/u/supermarin)
#### Post date: [March 13, 2025, 8:06pm UTC](https://discourse.nixos.org/t/nix-shell-does-not-use-my-users-shell-zsh/5588/16 "2025-03-13T20:06:52Z")

</div>

Sorry if I went offtopic, but the setup snippet is identical on both wikis, and I think the culprit is in the snippet itself.

> Also, `nix shell` already respects your current shell

Does it? From what I’m seeing, it’s calling `bash` (which is my login shell, not (_current_ shell). `echo $SHELL` still reports as bash with this setup.

EDIT: invoking `nix develop -c fish` works, just like reported above.

---

<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: [April 2, 2025, 3:04pm UTC](https://discourse.nixos.org/t/nix-shell-does-not-use-my-users-shell-zsh/5588/17 "2025-04-02T15:04:06Z")

</div>

Shouldn’t Nix better only depend on POSIX compliance to become more agnostic to those implementations

---

<div class="post-metadata">

### Author: ![bme](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@bme](https://discourse.nixos.org/u/bme)
#### Post date: [April 2, 2025, 3:47pm UTC](https://discourse.nixos.org/t/nix-shell-does-not-use-my-users-shell-zsh/5588/18 "2025-04-02T15:47:18Z")

</div>

The goal of nix is replicable environments, not posix compliance. If posix compliance aids in this goal, then sure, but it isn’t an aim in and of itself. Specialising to a particular tool often allows you access to a broader feature set than implentation agnosticism.

---

<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: [April 15, 2025, 3:18pm UTC](https://discourse.nixos.org/t/nix-shell-does-not-use-my-users-shell-zsh/5588/19 "2025-04-15T15:18:44Z")

</div>

I realized using `nix shell nixpkgs#packageName` instead of `nix-shell -p packageName` fixes that issue.

I even made a small script to simplify the usage especially if I want to add multiple packages at once:

```nix
get = pkgs.writeShellScriptBin "get" (builtins.readFile ./get.sh);

```

```sh
if [$# -eq 0]; then
      echo "Usage: get packet1 packet2 packet3 ..."
      return 1
  fi

  extension=""

  for pkg in "$@"; do
      extension="$extension nixpkgs#$pkg"
  done

  cmd="nix shell$extension"

  echo "Executing: $cmd"
  eval "$cmd"

```

Now I can just do the following

```sh
get cargo fish cowsay
Executing: nix shell nixpkgs#cargo nixpkgs#fish nixpkgs#cowsay

```
