lix/src/nix/shell.md
thenbe 5473e10249
fix: nix shell multiple commands example (#8950)
The `-c` flag belongs to `sh` not `nix shell`. As it stands, the command errors with:

```
$ nix shell nixpkgs#gnumake --command sh --command "cd src && make"
sh: --command: invalid option
```

https://github.com/NixOS/nix/pull/8276 was good for readability, but it missed this since that PR used a find/replace script.
2023-09-07 22:25:32 +00:00

55 lines
1.2 KiB
Markdown

R""(
# Examples
* Start a shell providing `youtube-dl` from the `nixpkgs` flake:
```console
# nix shell nixpkgs#youtube-dl
# youtube-dl --version
2020.11.01.1
```
* Start a shell providing GNU Hello from NixOS 20.03:
```console
# nix shell nixpkgs/nixos-20.03#hello
```
* Run GNU Hello:
```console
# nix shell nixpkgs#hello --command hello --greeting 'Hi everybody!'
Hi everybody!
```
* Run multiple commands in a shell environment:
```console
# nix shell nixpkgs#gnumake --command sh -c "cd src && make"
```
* Run GNU Hello in a chroot store:
```console
# nix shell --store ~/my-nix nixpkgs#hello --command hello
```
* Start a shell providing GNU Hello in a chroot store:
```console
# nix shell --store ~/my-nix nixpkgs#hello nixpkgs#bashInteractive --command bash
```
Note that it's necessary to specify `bash` explicitly because your
default shell (e.g. `/bin/bash`) generally will not exist in the
chroot.
# Description
`nix shell` runs a command in an environment in which the `$PATH` variable
provides the specified [*installables*](./nix.md#installable). If no command is specified, it starts the
default shell of your user account specified by `$SHELL`.
)""