Uninstall

Updated: September 28, 2024

How to uninstall Nix from Linux and MacOS

Multi-user installations of nix is more involved so we have to go deeper into the uninstallation process. It does add a partition to the system and needs to be removed.


Linux

if using systemd

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 && groups

for i in $(seq 1 32); do
  sudo userdel -r nixbld$i
done
sudo groupdel nixbld


MacOS

remove the nix-daemon lines from zshrc stop and remove nix-daemon.service

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.plist

remove nixbld group && _nixbuildN users

sudo dscl . -delete /Groups/nixbld
for u in $(sudo dscl . -list /Users | grep _nixbld); do sudo dscl . -delete /Users/$u; done

remove mount from fstab with sudo vifs

# the lines to delete should look like:
UUID=<uuid> /nix apfs rw,noauto,nobrowse,suid,owners
LABEL=Nix\040Store /nix apfs rw,nobrowse

further prevent recreation of /nix mount point

# remove nix line from /etc/synthetic.conf if only line remove file
sudo rm /etc/synthetic.conf

remove files nix created

sudo rm -rf /etc/nix /var/root/.nix-profile /var/root/.nix-defexpr /var/root/.nix-channels ~/.nix-profile ~/.nix-defexpr ~/.nix-channels

remove nix store partition

sudo diskutil apfs deleteVolume /nix

# check if worked
diskutil list

# if still there because it was unmounted then run
sudo diskutil apfs deleteVolume diskYsY

If all went well you will have an empty /nix directory.
It will dissapear when you reboot.