streamline macOS uninstall instructions (#10589)

* move single-user uninstall to the end

this is not the default method of installation, and therefore irrelevant
for most users.

* move the backup restore instructions to the first step

for most users we can expect that the system-wide shell init files were
not ever touched, so we can as well tell them to do the most likely
thing.

from experience, while it's not necessarily safe to just mess with these
files, most people are simply confused by the complexity of
instructions.

* provide more detailed instructions for using `sudo vifs`

we can expect most beginners not to ever have used `vi`, and they will
probably need some hand-holding.

* express instructions as a script

Co-authored-by: wamirez <wamirez@protonmail.com>
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
This commit is contained in:
Valentin Gagarin 2024-04-24 17:04:49 +02:00 committed by GitHub
parent e3a4e40a35
commit 5747d244ed
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,17 +1,8 @@
# Uninstalling Nix # Uninstalling Nix
## Single User
If you have a [single-user installation](./installing-binary.md#single-user-installation) of Nix, uninstall it by running:
```console
$ rm -rf /nix ~/.nix-channels ~/.nix-defexpr ~/.nix-profile
```
You might also want to manually remove references to Nix from your `~/.profile`.
## Multi User ## Multi User
Removing a [multi-user installation](./installing-binary.md#multi-user-installation) of Nix is more involved, and depends on the operating system. Removing a [multi-user installation](./installing-binary.md#multi-user-installation) depends on the operating system.
### Linux ### Linux
@ -52,7 +43,15 @@ which you may remove.
### macOS ### macOS
1. Edit `/etc/zshrc`, `/etc/bashrc`, and `/etc/bash.bashrc` to remove the lines sourcing `nix-daemon.sh`, which should look like this: 1. If system-wide shell initialisation files haven't been altered since installing Nix, use the backups made by the installer:
```console
sudo mv /etc/zshrc.backup-before-nix /etc/zshrc
sudo mv /etc/bashrc.backup-before-nix /etc/bashrc
sudo mv /etc/bash.bashrc.backup-before-nix /etc/bash.bashrc
```
Otherwise, edit `/etc/zshrc`, `/etc/bashrc`, and `/etc/bash.bashrc` to remove the lines sourcing `nix-daemon.sh`, which should look like this:
```bash ```bash
# Nix # Nix
@ -62,18 +61,6 @@ which you may remove.
# End Nix # 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
sudo mv /etc/bash.bashrc.backup-before-nix /etc/bash.bashrc
```
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: 2. Stop and remove the Nix daemon services:
```console ```console
@ -83,8 +70,7 @@ which you may remove.
sudo rm /Library/LaunchDaemons/org.nixos.darwin-store.plist sudo rm /Library/LaunchDaemons/org.nixos.darwin-store.plist
``` ```
This stops the Nix daemon and prevents it from being started next time you This stops the Nix daemon and prevents it from being started next time you boot the system.
boot the system.
3. Remove the `nixbld` group and the `_nixbuildN` users: 3. Remove the `nixbld` group and the `_nixbuildN` users:
@ -95,25 +81,42 @@ which you may remove.
This will remove all the build users that no longer serve a purpose. 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 4. Edit fstab using `sudo vifs` to remove the line mounting the Nix Store volume on `/nix`, which looks like
volume on `/nix`, which looks like
`UUID=<uuid> /nix apfs rw,noauto,nobrowse,suid,owners` or
`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`. UUID=<uuid> /nix apfs rw,noauto,nobrowse,suid,owners
This will prevent the creation of the empty `/nix` directory to provide a ```
mountpoint for the Nix Store volume. or
6. Remove the files Nix added to your system: ```
LABEL=Nix\040Store /nix apfs rw,nobrowse
```
by setting the cursor on the respective line using the error keys, and pressing `dd`, and then `:wq` to save the file.
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:
```bash
if [ -f /etc/synthetic.conf ]; then
if [ "$(cat /etc/synthetic.conf)" = "nix" ]; then
sudo rm /etc/synthetic.conf
else
sudo vi /etc/synthetic.conf
fi
fi
```
This will prevent the creation of the empty `/nix` directory.
6. Remove the files Nix added to your system, except for the store:
```console ```console
sudo rm -rf /etc/nix /var/root/.nix-profile /var/root/.nix-defexpr /var/root/.nix-channels ~/.nix-profile ~/.nix-defexpr ~/.nix-channels 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: 7. Remove the Nix Store volume:
@ -121,29 +124,32 @@ which you may remove.
sudo diskutil apfs deleteVolume /nix sudo diskutil apfs deleteVolume /nix
``` ```
This will remove the Nix Store volume and everything that was added to the This will remove the Nix Store volume and everything that was added to the store.
store.
If the output indicates that the command couldn't remove the volume, you should If the output indicates that the command couldn't remove the volume, you should make sure you don't have an _unmounted_ Nix Store volume.
make sure you don't have an _unmounted_ Nix Store volume. Look for a Look for a "Nix Store" volume in the output of the following command:
"Nix Store" volume in the output of the following command:
```console ```console
diskutil list diskutil list
``` ```
If you _do_ see a "Nix Store" volume, delete it by re-running the diskutil If you _do_ find a "Nix Store" volume, delete it by running `diskutil deleteVolume` with the store volume's `diskXsY` identifier.
deleteVolume command, but replace `/nix` with the store volume's `diskXsY`
identifier.
> **Note** > **Note**
> >
> After you complete the steps here, you will still have an empty `/nix` > After you complete the steps here, you will still have an empty `/nix` directory.
> directory. This is an expected sign of a successful uninstall. The empty > This is an expected sign of a successful uninstall.
> `/nix` directory will disappear the next time you reboot. > The empty `/nix` directory will disappear the next time you reboot.
> >
> You do not have to reboot to finish uninstalling Nix. The uninstall is > You do not have to reboot to finish uninstalling Nix.
> complete. macOS (Catalina+) directly controls root directories and its > The uninstall is complete.
> read-only root will prevent you from manually deleting the empty `/nix` > macOS (Catalina+) directly controls root directories, and its read-only root will prevent you from manually deleting the empty `/nix` mountpoint.
> mountpoint.
## Single User
To remove a [single-user installation](./installing-binary.md#single-user-installation) of Nix, run:
```console
$ rm -rf /nix ~/.nix-channels ~/.nix-defexpr ~/.nix-profile
```
You might also want to manually remove references to Nix from your `~/.profile`.