Uninstalling Nix
Single User
If you have a single-user installation of Nix, uninstall it by running:
$ rm -rf /nix
Multi User
Removing a multi-user installation of Nix is more involved, and depends on the operating system.
Linux
If you are on Linux with systemd:
-
Remove the Nix daemon service:
sudo systemctl stop nix-daemon.service sudo systemctl disable nix-daemon.socket nix-daemon.service sudo systemctl daemon-reload
Remove files created by Nix:
sudo rm -rf /etc/nix /etc/profile.d/nix.sh /etc/tmpfiles.d/nix-daemon.conf /nix ~root/.nix-channels ~root/.nix-defexpr ~root/.nix-profile
Remove build users and their group:
for i in $(seq 1 32); do
sudo userdel nixbld$i
done
sudo groupdel nixbld
There may also be references to Nix in
/etc/bash.bashrc/etc/bashrc/etc/profile/etc/zsh/zshrc/etc/zshrc
which you may remove.
macOS
-
Edit
/etc/zshrc,/etc/bashrc, and/etc/bash.bashrcto remove the lines sourcingnix-daemon.sh, which should look like this:# 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 NixIf these files haven't been altered since installing Nix you can simply put the backups back in place:
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.bashrcThis will stop shells from sourcing the file and bringing everything you installed using Nix in scope.
-
Stop and remove the Nix daemon services:
sudo launchctl unload /Library/LaunchDaemons/org.nixos.nix-daemon.plist sudo rm /Library/LaunchDaemons/org.nixos.nix-daemon.plist sudo launchctl unload /Library/LaunchDaemons/org.nixos.darwin-store.plist sudo rm /Library/LaunchDaemons/org.nixos.darwin-store.plistThis stops the Nix daemon and prevents it from being started next time you boot the system.
-
Remove the
nixbldgroup and the_nixbuildNusers:sudo dscl . -delete /Groups/nixbld for u in $(sudo dscl . -list /Users | grep _nixbld); do sudo dscl . -delete /Users/$u; doneThis will remove all the build users that no longer serve a purpose.
-
Edit fstab using
sudo vifsto remove the line mounting the Nix Store volume on/nix, which looks likeUUID=<uuid> /nix apfs rw,noauto,nobrowse,suid,ownersorLABEL=Nix\040Store /nix apfs rw,nobrowse. This will prevent automatic mounting of the Nix Store volume. -
Edit
/etc/synthetic.confto remove thenixline. 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/nixdirectory to provide a mountpoint for the Nix Store volume. -
Remove the files Nix added to your system:
sudo rm -rf /etc/nix /var/root/.nix-profile /var/root/.nix-defexpr /var/root/.nix-channels ~/.nix-profile ~/.nix-defexpr ~/.nix-channelsThis gets rid of any data Nix may have created except for the store which is removed next.
-
Remove the Nix Store volume:
sudo diskutil apfs deleteVolume /nixThis will remove the Nix Store volume and everything that was added to the store.
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. Look for a "Nix Store" volume in the output of the following command:
diskutil listIf you do see a "Nix Store" volume, delete it by re-running the diskutil deleteVolume command, but replace
/nixwith the store volume'sdiskXsYidentifier.
Note
After you complete the steps here, you will still have an empty
/nixdirectory. This is an expected sign of a successful uninstall. The empty/nixdirectory 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
/nixmountpoint.