Command Shell: Difference between revisions
imported>Klaymore m Small wording fix |
imported>Pfeiferj |
||
| Line 18: | Line 18: | ||
{{file|/etc/nixos/configuration.nix|nix|<nowiki> | {{file|/etc/nixos/configuration.nix|nix|<nowiki> | ||
users.users.yourname.shell = pkgs.zsh; | users.users.yourname.shell = pkgs.zsh; | ||
</nowiki>}} | </nowiki>}} | ||
Many programs look at /etc/shells to determine if a user is a "normal" user and not a "system" user. Therefore it is recommended to add the user shells to this list. To add a shell to /etc/shells use the following line in your config: | |||
{{file|/etc/nixos/configuration.nix|nix|<nowiki> | |||
environment.shells = with pkgs; [ zsh ]; | |||
</nowiki>}} | |||
== Changing /bin/sh == | == Changing /bin/sh == | ||
Revision as of 16:47, 19 August 2022
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.
fish.Enable
Always enable the shell system-wide, even if it's already enabled in your home.nix. Otherwise it wont source the necessary files.
programs.zsh.enable = true;
Changing default shell
Shells can be changed system-wide and per-user. To change the shell system-wide, add the following line to your config:
users.defaultUserShell = pkgs.zsh;
then run nixos-rebuild switch and reboot your system.
To only change the default shell for one of the users, add
users.users.yourname.shell = pkgs.zsh;
Many programs look at /etc/shells to determine if a user is a "normal" user and not a "system" user. Therefore it is recommended to add the user shells to this list. To add a shell to /etc/shells use the following line in your config:
environment.shells = with pkgs; [ zsh ];
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 what shell the user is using. /bin/sh doesn't have to be the same as your interactive shell (e.g. the one you use in your terminal). In fact, a lot of 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";