How to set desired $SHELL with nix-darwin

Hello!

I am struggling to set the correct default shell using nix-darwin. When I open the terminal and run echo $SHELL it points to the system-wide shell at /run/current-system/sw/bin/bash, however I want my default shell to point to the user-specific instance at /etc/profiles/per-user/holdenc/bin/bash. Interestingly which bash gives /etc/profiles/per-user/holdenc/bin/bash, which is the shell that I want.

The relevant parts of my Darwin-managed configuration.nix are here:

programs.bash.enable = true;
users.users.holdenc.shell = pkgs.bash;
environment.shells = [ pkgs.bash ];

I’m not that clear on the implementation specifics of these commands. I would have thought that users.users.holdenc.shell = pkgs.bash; would set a user-specific shell, but it appears not to.

I have temporarily fixed this by adding /etc/profiles/per-user/holdenc/bin/bash to my available shells in /etc/shells and running chsh -s /etc/profiles/per-user/holdenc/bin/bash, but it’s not a very nix-y solution!

Many thanks for any help / discussion.

Why don’t you just configure your terminal to open that shell at startup?

Unfortunately, nix-darwin does not manage your default shell, so one has to use chsh.

3 Likes

Thanks, that’s really useful to know. I’ll stop banging my head against a brick wall.

I use Alacrity and tried to configure this behaviour with:

{ shell = { program = "{pkgs.bash}/bin/bash"; }; };

However my shell was bugged on opening, and threw an error about missing features. I have actually since resolved this by using bashInteractive.

1 Like