Command Shell: Difference between revisions
imported>Liassica →Enable: Specify when to enable the shell and example line |
imported>Liassica →Changing the default shell: Expand on how to change the default shell |
||
Line 12: | Line 12: | ||
== Changing the default shell == | == Changing the default shell == | ||
=== For all users === | |||
[https://search.nixos.org/options?query= | To set a command shell as the default for all users, use the [https://search.nixos.org/options?query=defaultUserShell <code>defaultUserShell</code>] option. | ||
For example, to set Zsh as the default user shell for all users: | |||
[https://search.nixos.org/options?query=<name>.shell <code><name>.shell</code> | {{file|/etc/nixos/configuration.nix|nix|<nowiki> | ||
users.defaultUserShell = pkgs.zsh; | |||
</nowiki>}} | |||
=== For a specific user === | |||
To set a command shell as the default for a particular user, use the [https://search.nixos.org/options?query=<name>.shell <code><name>.shell</code>] option. | |||
For example, to set user "myuser"'s shell to [[fish]]: | |||
{{file|/etc/nixos/configuration.nix|nix|<nowiki> | |||
users.users.myuser.shell = pkgs.fish; | |||
</nowiki>}} | |||
You can also choose whether or not a user should use the default shell: | |||
{{file|/etc/nixos/configuration.nix|nix|<nowiki> | |||
users.users.myuser.useDefaultShell = true; | |||
</nowiki>}} | |||
== Changing /bin/sh == | == Changing /bin/sh == |
Revision as of 01:22, 11 November 2023
A shell is a program that translates text commands (like ls
, vim
, reboot
etc) into instructions for your computer. The default shell on NixOS is bash, but it can be easily changed.
Enable
When adding a new shell, always enable the shell system-wide, even if it's already enabled in your Home Manager configuration, otherwise it won't source the necessary files.
For example, for Zsh:
/etc/nixos/configuration.nix
programs.zsh.enable = true;
Changing the default shell
For all users
To set a command shell as the default for all users, use the defaultUserShell
option.
For example, to set Zsh as the default user shell for all users:
/etc/nixos/configuration.nix
users.defaultUserShell = pkgs.zsh;
For a specific user
To set a command shell as the default for a particular user, use the <name>.shell <name>.shell
option.
For example, to set user "myuser"'s shell to fish:
/etc/nixos/configuration.nix
users.users.myuser.shell = pkgs.fish;
You can also choose whether or not a user should use the default shell:
/etc/nixos/configuration.nix
users.users.myuser.useDefaultShell = true;
Changing /bin/sh
/bin/sh
is a symlink to your default POSIX-compliant shell. It's used when writing shell scripts, so that the script works on all machines independently of which shell the user is using. /bin/sh doesn't have to be the same as your interactive shell (i.e. the one you use in your terminal). For example, some people set their interactive shells to zsh/fish but set /bin/sh to dash, because it's fast and scripts don't need any of those fancy zsh/fish features.
To change your default POSIX shell on NixOS, use
# Dash is just an example, you can use whatever you want
environment.binsh = "${pkgs.dash}/bin/dash";