Command Shell: Difference between revisions

From NixOS Wiki
imported>Artturin
Link to options search. Remove unnecessary note which is already warned about in nix code.
imported>Skylark
m Minor copyedit throughout
Line 1: Line 1:
A shell is a program that translates text commands (like {{ic|ls}}, {{ic|vim}}, {{ic|reboot}} etc) into instructions for your computer. The default shell on NixOS is [[bash]], but it can be easily changed.
A shell is a program that translates text commands (like {{ic|ls}}, {{ic|vim}}, {{ic|reboot}} etc) into instructions for your computer. The default shell on NixOS is [[bash]], but it can be easily changed.


{{note|[[Zsh]] is used here as an example. You can use other shells, eg {{ic|fish}} {{ic|nushell}}.}}
{{note|[[Zsh]] is used here as an example. You can use other shells, e.g. {{ic|fish}} or {{ic|nushell}}.}}
== Enable ==
== Enable ==
Always enable the shell system-wide, even if it's already enabled in your <code>home.nix</code>. Otherwise it wont source the necessary files.
Always enable the shell system-wide, even if it's already enabled in your <code>home.nix</code>. Otherwise it won't source the necessary files.
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
programs.zsh.enable = true;
programs.zsh.enable = true;
</nowiki>}}
</nowiki>}}


== Changing default shell ==
== Changing the default shell ==


[https://search.nixos.org/options?query=defaultUserShell <code>defaultUserShell</code> in the options search]
[https://search.nixos.org/options?query=defaultUserShell <code>defaultUserShell</code> in the options search]
Line 14: Line 14:
[https://search.nixos.org/options?query=useDefaultShell <code>useDefaultShell</code> in the options search]
[https://search.nixos.org/options?query=useDefaultShell <code>useDefaultShell</code> in the options search]


To only change the default shell for one of the users, See
To only change the default shell for one of the users, see


[https://search.nixos.org/options?query=<name>.shell <code><name>.shell</code> in the options search]
[https://search.nixos.org/options?query=<name>.shell <code><name>.shell</code> in the options search]


== Changing /bin/sh ==
== Changing /bin/sh ==
{{Warning|Please note that NixOS assumes all over the place that shell is Bash, so override the default setting only if you know exactly what you're doing.}}
{{Warning|Please note that NixOS assumes all over the place that the shell is bash, so override the default setting only if you know what you're doing.}}
{{ic|/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.
{{ic|/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
To change your default POSIX shell on NixOS, use
Line 29: Line 29:


== See also ==
== See also ==
* [[Zsh]]
* [[Fish]]
* [[Fish]]
* [[Nushell]]
* [[Nushell]]
* [[Zsh]]
[[Category:Configuration]]
[[Category:Configuration]]
[[Category:Software]]
[[Category:Software]]

Revision as of 17:15, 16 October 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.

Note: Zsh is used here as an example. You can use other shells, e.g. fish or nushell.

Enable

Always enable the shell system-wide, even if it's already enabled in your home.nix. Otherwise it won't source the necessary files.

/etc/nixos/configuration.nix
programs.zsh.enable = true;

Changing the default shell

defaultUserShell in the options search

useDefaultShell in the options search

To only change the default shell for one of the users, see

<name>.shell <name>.shell in the options search

Changing /bin/sh

Warning: Please note that NixOS assumes all over the place that the shell is bash, so override the default setting only if you know what you're doing.

/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";

See also