2021-12-10 09:48:34 -05:00
|
|
|
(install-nix)=
|
|
|
|
|
|
|
|
# Install Nix
|
|
|
|
|
2022-12-18 15:58:05 -05:00
|
|
|
:::::{tab-set}
|
|
|
|
|
|
|
|
::::{tab-item} Linux
|
2021-12-10 09:48:34 -05:00
|
|
|
|
2022-12-04 03:16:32 -05:00
|
|
|
Install Nix via the recommended [multi-user installation]:
|
2021-12-10 09:48:34 -05:00
|
|
|
|
2022-11-08 11:37:41 -05:00
|
|
|
```shell-session
|
2022-12-28 00:36:27 -05:00
|
|
|
$ curl -L https://nixos.org/nix/install | sh -s -- --daemon
|
2021-12-10 09:48:34 -05:00
|
|
|
```
|
|
|
|
|
2023-03-21 06:24:30 -04:00
|
|
|
On Arch Linux, you can alternatively [install Nix through `pacman`](https://wiki.archlinux.org/title/Nix#Installation).
|
|
|
|
|
2022-12-18 15:58:05 -05:00
|
|
|
::::
|
|
|
|
|
|
|
|
::::{tab-item} macOS
|
2021-12-10 09:48:34 -05:00
|
|
|
|
2022-12-04 03:16:32 -05:00
|
|
|
Install Nix via the recommended [multi-user installation]:
|
2021-12-10 09:48:34 -05:00
|
|
|
|
2022-11-08 11:37:41 -05:00
|
|
|
```shell-session
|
2022-12-28 00:36:27 -05:00
|
|
|
$ curl -L https://nixos.org/nix/install | sh
|
2021-12-10 09:48:34 -05:00
|
|
|
```
|
|
|
|
|
2022-12-18 15:58:05 -05:00
|
|
|
::::
|
|
|
|
|
|
|
|
::::{tab-item} Windows (WSL2)
|
2021-12-10 09:48:34 -05:00
|
|
|
|
2022-12-04 03:16:32 -05:00
|
|
|
Install Nix via the recommended [single-user installation]:
|
2021-12-10 09:48:34 -05:00
|
|
|
|
2022-11-08 11:37:41 -05:00
|
|
|
```shell-session
|
2022-12-28 00:36:27 -05:00
|
|
|
$ curl -L https://nixos.org/nix/install | sh -s -- --no-daemon
|
2021-12-10 09:48:34 -05:00
|
|
|
```
|
|
|
|
|
2022-12-04 03:16:32 -05:00
|
|
|
However, if you have [systemd support] enabled, install Nix via the recommended [multi-user installation]:
|
|
|
|
|
|
|
|
```shell-session
|
2022-12-28 00:36:27 -05:00
|
|
|
$ curl -L https://nixos.org/nix/install | sh -s -- --daemon
|
2022-12-04 03:16:32 -05:00
|
|
|
```
|
|
|
|
|
|
|
|
[systemd support]: https://learn.microsoft.com/en-us/windows/wsl/wsl-config#systemd-support
|
|
|
|
|
2022-12-18 15:58:05 -05:00
|
|
|
::::
|
|
|
|
|
|
|
|
::::{tab-item} Docker
|
2021-12-10 09:48:34 -05:00
|
|
|
|
|
|
|
Start a Docker shell with Nix:
|
|
|
|
|
2022-11-08 11:37:41 -05:00
|
|
|
```shell-session
|
2021-12-10 09:48:34 -05:00
|
|
|
$ docker run -it nixos/nix
|
|
|
|
```
|
|
|
|
|
|
|
|
Or start a Docker shell with Nix exposing a `workdir` directory:
|
|
|
|
|
2022-11-08 11:37:41 -05:00
|
|
|
```shell-session
|
2021-12-10 09:48:34 -05:00
|
|
|
$ mkdir workdir
|
|
|
|
$ docker run -it -v $(pwd)/workdir:/workdir nixos/nix
|
|
|
|
```
|
|
|
|
|
2022-09-26 07:19:18 -04:00
|
|
|
The `workdir` example from above can be also used to start hacking on Nixpkgs:
|
2021-12-10 09:48:34 -05:00
|
|
|
|
2022-11-08 11:37:41 -05:00
|
|
|
```shell-session
|
2021-12-10 09:48:34 -05:00
|
|
|
$ git clone git@github.com:NixOS/nixpkgs
|
|
|
|
$ docker run -it -v $(pwd)/nixpkgs:/nixpkgs nixos/nix
|
2022-11-08 11:37:41 -05:00
|
|
|
bash-5.1# nix-build -I nixpkgs=/nixpkgs -A hello
|
|
|
|
bash-5.1# find ./result # this symlink points to the build package
|
2021-12-10 09:48:34 -05:00
|
|
|
```
|
|
|
|
|
2022-12-18 15:58:05 -05:00
|
|
|
::::
|
|
|
|
|
|
|
|
:::::
|
|
|
|
|
2021-12-10 09:48:34 -05:00
|
|
|
## Verify installation
|
|
|
|
|
2022-09-26 07:19:18 -04:00
|
|
|
Check the installation by opening **a new terminal** and typing:
|
2021-12-10 09:48:34 -05:00
|
|
|
|
2022-11-08 11:37:41 -05:00
|
|
|
```shell-session
|
2022-09-01 03:52:46 -04:00
|
|
|
$ nix --version
|
|
|
|
nix (Nix) 2.11.0
|
2021-12-10 09:48:34 -05:00
|
|
|
```
|
|
|
|
|
2024-06-28 16:27:17 -04:00
|
|
|
[multi-user installation]: https://nix.dev/manual/nix/stable/installation/multi-user.html
|
|
|
|
[single-user installation]: https://nix.dev/manual/nix/stable/installation/single-user.html
|