Default shell keeps reverting to BASH

Hi I know this is probably a super noob question, but I have trawled the web and the forums with no luck… and its super annoying hah. Anyways, I am trying to set my default shell to ZSH, when I login to a new session initially it starts with ZSH but then if I close and open any subsequent terminals following this it will revert to BASH. I have set my default shell (according to the I have set up my configuration.nix file with the below:

  users.users.jarcha98 = {
    isNormalUser = true;
    initialPassword = "XXXXXXXXXXXX";
    description = "jarcha98";
    extraGroups = [ "networkmanager" "wheel" "docker" ];
    packages = with pkgs; [
    shell = pkgs.zsh;

and of course enabled ZSH with

programs.zsh.enable = true;

Would be really appreciative if someone can assist in ascertaining the cause. Thanks.

Any chance you have some zsh code starting bash?

That’s a good point, I have just had a look through and there is no mention of bash in my home-manager config, system configuration file. Is there somewhere that it might be getting set by default? At this point in time my set up is pretty vanilla as I am just getting familiar with NixOS so apart from my flake file pulling it all together those two files are pretty much all I have.

What happens when you are in a new terminal and just run zsh? Does it launch zsh correctly in that case? Or does it switch to bash? In the latter case, I would assume there might be a stray .zshrc file sitting in your home directory.

Also, just as a sanity-check, what does the following command return?

cat /etc/passwd | grep $USER

This should return a line similar to this:

1 Like

Hi When I run zsh from bash it runs zsh fine with my oh-my-zsh theme correctly,

Interesting it shows current shell is bash, ok this is weird, shouldn’t be the case aye? :thinking:

cat /etc/passwd | grep $USER


Aha! Yes, that shouldn’t be the case. shell = pkgs.zsh should change this to zsh. This part of your configuration looks ok, so I assume it’s not applied properly for some reason.

How are you invoking nixos-rebuild? Please post the full command you run.

I’m using a command that invokes a flake:

pushd ~/.dotfiles
sudo nixos-rebuild switch --flake '.#nixos'

and that in turn invokes this snippet from the actual flake…

     nixosConfigurations = {
        nixos = nixpkgs.lib.nixosSystem {
          inherit system;
          specialArgs = { inherit hyprland; };
          modules = [

and this then pulls in configuration.nix which has the code I posted above.

Hmmm, that looks 100% fine. No overlays either, so nothing that could change the value of pkgs.zsh. And you’re not getting any errors, only building the system configuration..., right?

Ok, so to bisect this further, let’s ensure the activation script is working properly. Run the following commands:

$ nix shell nixpkgs#jq 
$ nix-store -q --tree /run/current-system | grep -oe '/nix/store/.*users-groups.json' | read -E groupJson
$ jq '.users | .[] | if .name == "jarcha98" then . else empty end | .shell' $groupJson

This is the output on my machine (if I replace jarcha98 with my username), but on yours it is probably /run/current-system/sw/bin/bash. Can you confirm that?

Thanks all for your suggestions, I really appreciate the help. Looks like I might have managed to figure out the issue inadvertently whilst looking at a different issue, long story short… looks like it was something to do with a block of code I had sitting in configuration.nix:

  environment.sessionVariables = {
    #XDG_CONFIG_HOME = "$HOME/etc";
    XDG_CONFIG_HOME = "$HOME/.config";
    XDG_DATA_HOME   = "$HOME/var/lib";
    XDG_CACHE_HOME  = "$HOME/var/cache";

when the first line xdg_config_home is set to $HOME/etc, it was throwing everything off including zsh. Anyways, so when I set back to .config its picking up all my configs properly now :sweat_smile:

Awesome, glad to hear it! Please mark your own reply as the solution then, so other people know this post doesn’t require any more attention from them :slight_smile: