2020-07-22 23:17:48 +02:00
|
|
|
|
# Installing a Binary Distribution
|
|
|
|
|
|
2020-11-27 23:42:15 +01:00
|
|
|
|
The easiest way to install Nix is to run the following command:
|
2020-07-22 23:17:48 +02:00
|
|
|
|
|
2020-07-31 15:43:25 +02:00
|
|
|
|
```console
|
2023-02-07 23:32:27 +01:00
|
|
|
|
$ curl -L https://nixos.org/nix/install | sh
|
2020-07-22 23:17:48 +02:00
|
|
|
|
```
|
|
|
|
|
|
2020-11-27 23:42:15 +01:00
|
|
|
|
This will run the installer interactively (causing it to explain what
|
|
|
|
|
it is doing more explicitly), and perform the default "type" of install
|
|
|
|
|
for your platform:
|
|
|
|
|
- single-user on Linux
|
|
|
|
|
- multi-user on macOS
|
2020-07-22 23:17:48 +02:00
|
|
|
|
|
2020-11-27 23:42:15 +01:00
|
|
|
|
> **Notes on read-only filesystem root in macOS 10.15 Catalina +**
|
2022-08-08 22:01:59 +02:00
|
|
|
|
>
|
2020-11-27 23:42:15 +01:00
|
|
|
|
> - It took some time to support this cleanly. You may see posts,
|
|
|
|
|
> examples, and tutorials using obsolete workarounds.
|
|
|
|
|
> - Supporting it cleanly made macOS installs too complex to qualify
|
|
|
|
|
> as single-user, so this type is no longer supported on macOS.
|
|
|
|
|
|
|
|
|
|
We recommend the multi-user install if it supports your platform and
|
|
|
|
|
you can authenticate with `sudo`.
|
2020-07-22 23:17:48 +02:00
|
|
|
|
|
|
|
|
|
# Single User Installation
|
|
|
|
|
|
|
|
|
|
To explicitly select a single-user installation on your system:
|
|
|
|
|
|
2020-07-31 15:43:25 +02:00
|
|
|
|
```console
|
2023-02-07 23:32:27 +01:00
|
|
|
|
$ curl -L https://nixos.org/nix/install | sh -s -- --no-daemon
|
2020-07-22 23:17:48 +02:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
This will perform a single-user installation of Nix, meaning that `/nix`
|
2022-08-08 21:46:17 +02:00
|
|
|
|
is owned by the invoking user. You can run this under your usual user
|
|
|
|
|
account or root. The script will invoke `sudo` to create `/nix`
|
2020-07-22 23:17:48 +02:00
|
|
|
|
if it doesn’t already exist. If you don’t have `sudo`, you should
|
|
|
|
|
manually create `/nix` first as root, e.g.:
|
|
|
|
|
|
2020-07-31 15:43:25 +02:00
|
|
|
|
```console
|
|
|
|
|
$ mkdir /nix
|
|
|
|
|
$ chown alice /nix
|
|
|
|
|
```
|
2020-07-22 23:17:48 +02:00
|
|
|
|
|
|
|
|
|
The install script will modify the first writable file from amongst
|
|
|
|
|
`.bash_profile`, `.bash_login` and `.profile` to source
|
|
|
|
|
`~/.nix-profile/etc/profile.d/nix.sh`. You can set the
|
2020-07-23 10:44:54 +02:00
|
|
|
|
`NIX_INSTALLER_NO_MODIFY_PROFILE` environment variable before executing
|
|
|
|
|
the install script to disable this behaviour.
|
2020-07-22 23:17:48 +02:00
|
|
|
|
|
|
|
|
|
You can uninstall Nix simply by running:
|
|
|
|
|
|
2020-07-31 15:43:25 +02:00
|
|
|
|
```console
|
|
|
|
|
$ rm -rf /nix
|
|
|
|
|
```
|
2020-07-22 23:17:48 +02:00
|
|
|
|
|
|
|
|
|
# Multi User Installation
|
|
|
|
|
|
|
|
|
|
The multi-user Nix installation creates system users, and a system
|
|
|
|
|
service for the Nix daemon.
|
|
|
|
|
|
2020-11-27 23:42:15 +01:00
|
|
|
|
**Supported Systems**
|
|
|
|
|
- Linux running systemd, with SELinux disabled
|
|
|
|
|
- macOS
|
2020-07-22 23:17:48 +02:00
|
|
|
|
|
|
|
|
|
You can instruct the installer to perform a multi-user installation on
|
|
|
|
|
your system:
|
|
|
|
|
|
2020-07-31 15:43:25 +02:00
|
|
|
|
```console
|
2023-02-07 23:32:27 +01:00
|
|
|
|
$ curl -L https://nixos.org/nix/install | sh -s -- --daemon
|
2020-07-31 15:43:25 +02:00
|
|
|
|
```
|
2020-07-22 23:17:48 +02:00
|
|
|
|
|
|
|
|
|
The multi-user installation of Nix will create build users between the
|
|
|
|
|
user IDs 30001 and 30032, and a group with the group ID 30000. You
|
2022-08-08 21:46:17 +02:00
|
|
|
|
can run this under your usual user account or root. The script
|
2020-07-22 23:17:48 +02:00
|
|
|
|
will invoke `sudo` as needed.
|
|
|
|
|
|
|
|
|
|
> **Note**
|
2022-08-08 22:01:59 +02:00
|
|
|
|
>
|
2020-07-22 23:17:48 +02:00
|
|
|
|
> If you need Nix to use a different group ID or user ID set, you will
|
|
|
|
|
> have to download the tarball manually and [edit the install
|
2020-07-24 15:46:16 +02:00
|
|
|
|
> script](#installing-from-a-binary-tarball).
|
2020-07-22 23:17:48 +02:00
|
|
|
|
|
|
|
|
|
The installer will modify `/etc/bashrc`, and `/etc/zshrc` if they exist.
|
|
|
|
|
The installer will first back up these files with a `.backup-before-nix`
|
|
|
|
|
extension. The installer will also create `/etc/profile.d/nix.sh`.
|
|
|
|
|
|
2022-02-22 16:28:24 +01:00
|
|
|
|
## Uninstalling
|
|
|
|
|
|
|
|
|
|
### Linux
|
2020-07-22 23:17:48 +02:00
|
|
|
|
|
2022-11-26 15:01:51 +01:00
|
|
|
|
If you are on Linux with systemd:
|
2022-11-20 13:04:22 +01:00
|
|
|
|
|
2022-11-26 15:01:51 +01:00
|
|
|
|
1. Remove the Nix daemon service:
|
2022-11-20 13:04:22 +01:00
|
|
|
|
|
2022-11-26 15:01:51 +01:00
|
|
|
|
```console
|
|
|
|
|
sudo systemctl stop nix-daemon.service
|
|
|
|
|
sudo systemctl disable nix-daemon.socket nix-daemon.service
|
|
|
|
|
sudo systemctl daemon-reload
|
|
|
|
|
```
|
2022-11-20 13:04:22 +01:00
|
|
|
|
|
2022-11-26 15:01:51 +01:00
|
|
|
|
1. Remove systemd service files:
|
2022-11-20 13:04:22 +01:00
|
|
|
|
|
2022-11-26 15:01:51 +01:00
|
|
|
|
```console
|
|
|
|
|
sudo rm /etc/systemd/system/nix-daemon.service /etc/systemd/system/nix-daemon.socket
|
|
|
|
|
```
|
2022-11-20 13:04:22 +01:00
|
|
|
|
|
2022-11-26 15:01:51 +01:00
|
|
|
|
1. The installer script uses systemd-tmpfiles to create the socket directory.
|
|
|
|
|
You may also want to remove the configuration for that:
|
|
|
|
|
|
|
|
|
|
```console
|
|
|
|
|
sudo rm /etc/tmpfiles.d/nix-daemon.conf
|
|
|
|
|
```
|
2022-11-20 13:04:22 +01:00
|
|
|
|
|
2022-11-09 01:11:47 +01:00
|
|
|
|
Remove files created by Nix:
|
|
|
|
|
|
|
|
|
|
```console
|
|
|
|
|
sudo rm -rf /nix /etc/nix /etc/profile/nix.sh ~root/.nix-profile ~root/.nix-defexpr ~root/.nix-channels ~/.nix-profile ~/.nix-defexpr ~/.nix-channels
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Remove build users and their group:
|
|
|
|
|
|
2020-07-31 15:43:25 +02:00
|
|
|
|
```console
|
2022-12-23 09:36:51 +01:00
|
|
|
|
for i in $(seq 1 32); do
|
|
|
|
|
sudo userdel nixbld$i
|
2022-11-09 01:11:47 +01:00
|
|
|
|
done
|
2022-12-23 09:36:51 +01:00
|
|
|
|
sudo groupdel nixbld
|
2022-11-09 01:11:47 +01:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
There may also be references to Nix in
|
|
|
|
|
|
|
|
|
|
- `/etc/profile`
|
2022-11-11 14:01:13 +01:00
|
|
|
|
- `/etc/bashrc`
|
2022-11-09 01:11:47 +01:00
|
|
|
|
- `/etc/zshrc`
|
|
|
|
|
|
|
|
|
|
which you may remove.
|
2020-07-22 23:17:48 +02:00
|
|
|
|
|
2022-02-22 16:28:24 +01:00
|
|
|
|
### macOS
|
|
|
|
|
|
2023-04-18 12:18:30 +02:00
|
|
|
|
1. Edit `/etc/zshrc`, `/etc/bashrc`, and `/etc/bash.bashrc` to remove the lines sourcing
|
2022-02-22 16:28:24 +01:00
|
|
|
|
`nix-daemon.sh`, which should look like this:
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
# Nix
|
|
|
|
|
if [ -e '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' ]; then
|
|
|
|
|
. '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh'
|
|
|
|
|
fi
|
|
|
|
|
# End Nix
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
If these files haven't been altered since installing Nix you can simply put
|
|
|
|
|
the backups back in place:
|
|
|
|
|
|
|
|
|
|
```console
|
|
|
|
|
sudo mv /etc/zshrc.backup-before-nix /etc/zshrc
|
|
|
|
|
sudo mv /etc/bashrc.backup-before-nix /etc/bashrc
|
2023-04-18 12:18:30 +02:00
|
|
|
|
sudo mv /etc/bash.bashrc.backup-before-nix /etc/bash.bashrc
|
2022-02-22 16:28:24 +01:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
This will stop shells from sourcing the file and bringing everything you
|
|
|
|
|
installed using Nix in scope.
|
|
|
|
|
|
|
|
|
|
2. Stop and remove the Nix daemon services:
|
|
|
|
|
|
|
|
|
|
```console
|
|
|
|
|
sudo launchctl unload /Library/LaunchDaemons/org.nixos.nix-daemon.plist
|
|
|
|
|
sudo rm /Library/LaunchDaemons/org.nixos.nix-daemon.plist
|
2022-02-26 14:16:35 +01:00
|
|
|
|
sudo launchctl unload /Library/LaunchDaemons/org.nixos.darwin-store.plist
|
|
|
|
|
sudo rm /Library/LaunchDaemons/org.nixos.darwin-store.plist
|
2022-02-22 16:28:24 +01:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
This stops the Nix daemon and prevents it from being started next time you
|
|
|
|
|
boot the system.
|
|
|
|
|
|
|
|
|
|
3. Remove the `nixbld` group and the `_nixbuildN` users:
|
|
|
|
|
|
|
|
|
|
```console
|
|
|
|
|
sudo dscl . -delete /Groups/nixbld
|
|
|
|
|
for u in $(sudo dscl . -list /Users | grep _nixbld); do sudo dscl . -delete /Users/$u; done
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
This will remove all the build users that no longer serve a purpose.
|
|
|
|
|
|
|
|
|
|
4. Edit fstab using `sudo vifs` to remove the line mounting the Nix Store
|
2022-06-16 16:37:52 +02:00
|
|
|
|
volume on `/nix`, which looks like
|
2022-08-04 13:23:36 +02:00
|
|
|
|
`UUID=<uuid> /nix apfs rw,noauto,nobrowse,suid,owners` or
|
2022-02-22 16:28:24 +01:00
|
|
|
|
`LABEL=Nix\040Store /nix apfs rw,nobrowse`. This will prevent automatic
|
|
|
|
|
mounting of the Nix Store volume.
|
|
|
|
|
|
|
|
|
|
5. Edit `/etc/synthetic.conf` to remove the `nix` line. If this is the only
|
|
|
|
|
line in the file you can remove it entirely, `sudo rm /etc/synthetic.conf`.
|
|
|
|
|
This will prevent the creation of the empty `/nix` directory to provide a
|
|
|
|
|
mountpoint for the Nix Store volume.
|
|
|
|
|
|
|
|
|
|
6. Remove the files Nix added to your system:
|
|
|
|
|
|
|
|
|
|
```console
|
|
|
|
|
sudo rm -rf /etc/nix /var/root/.nix-profile /var/root/.nix-defexpr /var/root/.nix-channels ~/.nix-profile ~/.nix-defexpr ~/.nix-channels
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
This gets rid of any data Nix may have created except for the store which is
|
|
|
|
|
removed next.
|
|
|
|
|
|
|
|
|
|
7. Remove the Nix Store volume:
|
2022-08-08 22:01:59 +02:00
|
|
|
|
|
2022-02-22 16:28:24 +01:00
|
|
|
|
```console
|
|
|
|
|
sudo diskutil apfs deleteVolume /nix
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
This will remove the Nix Store volume and everything that was added to the
|
|
|
|
|
store.
|
|
|
|
|
|
2022-08-04 13:23:45 +02:00
|
|
|
|
If the output indicates that the command couldn't remove the volume, you should
|
2022-06-16 16:47:15 +02:00
|
|
|
|
make sure you don't have an _unmounted_ Nix Store volume. Look for a
|
|
|
|
|
"Nix Store" volume in the output of the following command:
|
2022-06-16 16:37:52 +02:00
|
|
|
|
|
|
|
|
|
```console
|
|
|
|
|
diskutil list
|
|
|
|
|
```
|
|
|
|
|
|
2022-06-16 16:47:15 +02:00
|
|
|
|
If you _do_ see a "Nix Store" volume, delete it by re-running the diskutil
|
|
|
|
|
deleteVolume command, but replace `/nix` with the store volume's `diskXsY`
|
|
|
|
|
identifier.
|
2022-06-16 16:37:52 +02:00
|
|
|
|
|
2022-02-25 10:32:45 +01:00
|
|
|
|
> **Note**
|
2022-08-08 22:01:59 +02:00
|
|
|
|
>
|
2022-02-25 10:32:45 +01:00
|
|
|
|
> After you complete the steps here, you will still have an empty `/nix`
|
|
|
|
|
> directory. This is an expected sign of a successful uninstall. The empty
|
|
|
|
|
> `/nix` directory will disappear the next time you reboot.
|
|
|
|
|
>
|
|
|
|
|
> You do not have to reboot to finish uninstalling Nix. The uninstall is
|
|
|
|
|
> complete. macOS (Catalina+) directly controls root directories and its
|
|
|
|
|
> read-only root will prevent you from manually deleting the empty `/nix`
|
|
|
|
|
> mountpoint.
|
2022-02-22 16:28:24 +01:00
|
|
|
|
|
2022-05-25 13:53:07 +02:00
|
|
|
|
# macOS Installation
|
|
|
|
|
[]{#sect-macos-installation-change-store-prefix}[]{#sect-macos-installation-encrypted-volume}[]{#sect-macos-installation-symlink}[]{#sect-macos-installation-recommended-notes}
|
2020-11-27 23:42:15 +01:00
|
|
|
|
<!-- Note: anchors above to catch permalinks to old explanations -->
|
|
|
|
|
|
|
|
|
|
We believe we have ironed out how to cleanly support the read-only root
|
2022-06-16 16:47:15 +02:00
|
|
|
|
on modern macOS. New installs will do this automatically.
|
2020-11-27 23:42:15 +01:00
|
|
|
|
|
|
|
|
|
This section previously detailed the situation, options, and trade-offs,
|
|
|
|
|
but it now only outlines what the installer does. You don't need to know
|
|
|
|
|
this to run the installer, but it may help if you run into trouble:
|
|
|
|
|
|
|
|
|
|
- create a new APFS volume for your Nix store
|
|
|
|
|
- update `/etc/synthetic.conf` to direct macOS to create a "synthetic"
|
|
|
|
|
empty root directory to mount your volume
|
|
|
|
|
- specify mount options for the volume in `/etc/fstab`
|
2021-12-05 06:07:17 +01:00
|
|
|
|
- `rw`: read-write
|
|
|
|
|
- `noauto`: prevent the system from auto-mounting the volume (so the
|
|
|
|
|
LaunchDaemon mentioned below can control mounting it, and to avoid
|
|
|
|
|
masking problems with that mounting service).
|
|
|
|
|
- `nobrowse`: prevent the Nix Store volume from showing up on your
|
|
|
|
|
desktop; also keeps Spotlight from spending resources to index
|
|
|
|
|
this volume
|
|
|
|
|
<!-- TODO:
|
|
|
|
|
- `suid`: honor setuid? surely not? ...
|
|
|
|
|
- `owners`: honor file ownership on the volume
|
|
|
|
|
|
|
|
|
|
For now I'll avoid pretending to understand suid/owners more
|
|
|
|
|
than I do. There've been some vague reports of file-ownership
|
|
|
|
|
and permission issues, particularly in cloud/VM/headless setups.
|
|
|
|
|
My pet theory is that this has something to do with these setups
|
|
|
|
|
not having a token that gets delegated to initial/admin accounts
|
|
|
|
|
on macOS. See scripts/create-darwin-volume.sh for a little more.
|
|
|
|
|
|
|
|
|
|
In any case, by Dec 4 2021, it _seems_ like some combination of
|
|
|
|
|
suid, owners, and calling diskutil enableOwnership have stopped
|
|
|
|
|
new reports from coming in. But I hesitate to celebrate because we
|
|
|
|
|
haven't really named and catalogued the behavior, understood what
|
|
|
|
|
we're fixing, and validated that all 3 components are essential.
|
|
|
|
|
-->
|
2020-11-27 23:42:15 +01:00
|
|
|
|
- if you have FileVault enabled
|
|
|
|
|
- generate an encryption password
|
|
|
|
|
- put it in your system Keychain
|
|
|
|
|
- use it to encrypt the volume
|
|
|
|
|
- create a system LaunchDaemon to mount this volume early enough in the
|
|
|
|
|
boot process to avoid problems loading or restoring any programs that
|
|
|
|
|
need access to your Nix store
|
2020-07-22 23:17:48 +02:00
|
|
|
|
|
|
|
|
|
# Installing a pinned Nix version from a URL
|
|
|
|
|
|
|
|
|
|
NixOS.org hosts version-specific installation URLs for all Nix versions
|
|
|
|
|
since 1.11.16, at `https://releases.nixos.org/nix/nix-version/install`.
|
|
|
|
|
|
|
|
|
|
These install scripts can be used the same as the main NixOS.org
|
|
|
|
|
installation script:
|
|
|
|
|
|
2020-07-31 15:43:25 +02:00
|
|
|
|
```console
|
2023-02-07 23:32:27 +01:00
|
|
|
|
$ curl -L https://nixos.org/nix/install | sh
|
2020-07-22 23:17:48 +02:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
In the same directory of the install script are sha256 sums, and gpg
|
|
|
|
|
signature files.
|
|
|
|
|
|
|
|
|
|
# Installing from a binary tarball
|
|
|
|
|
|
|
|
|
|
You can also download a binary tarball that contains Nix and all its
|
|
|
|
|
dependencies. (This is what the install script at
|
|
|
|
|
<https://nixos.org/nix/install> does automatically.) You should unpack
|
|
|
|
|
it somewhere (e.g. in `/tmp`), and then run the script named `install`
|
|
|
|
|
inside the binary tarball:
|
|
|
|
|
|
2020-07-31 15:43:25 +02:00
|
|
|
|
```console
|
2020-11-02 16:32:05 +01:00
|
|
|
|
$ cd /tmp
|
|
|
|
|
$ tar xfj nix-1.8-x86_64-darwin.tar.bz2
|
|
|
|
|
$ cd nix-1.8-x86_64-darwin
|
|
|
|
|
$ ./install
|
2020-07-31 15:43:25 +02:00
|
|
|
|
```
|
2020-07-22 23:17:48 +02:00
|
|
|
|
|
|
|
|
|
If you need to edit the multi-user installation script to use different
|
|
|
|
|
group ID or a different user ID range, modify the variables set in the
|
|
|
|
|
file named `install-multi-user`.
|