Skip to content

Instantly share code, notes, and snippets.

@fmoliveira
Last active June 29, 2024 20:48
Show Gist options
  • Save fmoliveira/83c031f198e0581fb586932966cfe6c3 to your computer and use it in GitHub Desktop.
Save fmoliveira/83c031f198e0581fb586932966cfe6c3 to your computer and use it in GitHub Desktop.
Nix uninstaller for macOS

Nix uninstaller for macOS

WARNING: USE AT YOUR OWN RISK!!! THIS SCRIPT IS UNMAINTAINED, NOT CONSIDERED STABLE, AND CAN BREAK YOUR SYSTEM!!! YOU HAVE BEEN WARNED!!!

Installing Nix is easy peasy, run a single command and you're ready to go.

But uninstalling it? Good luck hahahahahah!!!! You can try running the install program again and it will tell you what to do, but it is not quite complete. The best effort so far seems to be the uninstallation guide documented at: https://nix.dev/manual/nix/2.22/installation/uninstall

This gist contains two bash scripts tested a couple of times on macOS Sonoma running on Apple Sillicon with Nix 2.23.0. They are both based in the official macOS guide linked above with the intention of creating a "one command uninstall" experience that you might expect.

However, this script is NOT MAINTAINED AND MAY BREAK IN FUTURE VERSIONS OF NIX!

If you are still interested in trying it, please make sure to read each line of the script carefully and examine what they will do in your system.

#!/bin/bash
source ./verify-nix.sh
log "UNINSTALLING NIX"
# remove shell
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
# remove 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.plist
# remove group and users
sudo dscl . -delete /Groups/nixbld
for u in $(sudo dscl . -list /Users | grep _nixbld); do sudo dscl . -delete /Users/$u; done
# remove partition
sudo sed -i '' -e '/ \/nix /d' /etc/fstab
# remove synthetic root directory
sudo sed -i '' -e '/nix/d' /etc/synthetic.conf
# remove folders
sudo rm -rf /etc/nix /var/root/.nix-profile /var/root/.nix-defexpr /var/root/.nix-channels ~/.nix-profile ~/.nix-defexpr ~/.nix-channels
# remove volume
sudo diskutil apfs deleteVolume /nix
# print results
log "uninstall finished! hopefully? 8===D"
./verify-nix.sh
#!/bin/bash
platform=$(uname -s | tr '[:upper:]' '[:lower:]')
if [[ "$platform" != 'darwin' ]]; then
echo "Platform '$platform' is not supported!"
echo "Follow the official uninstall guide at: https://nix.dev/manual/nix/2.22/installation/uninstall"
exit 1
fi
log() {
text="$@"
printf "\n## $text\n"
}
log "shells"
ls -l /etc/*.backup-before-nix
log "services"
ls -l /Library/LaunchDaemons/org.nixos.*.plist
log "group"
dscl . -list /Groups | grep nixbld
log "users"
dscl . -list /Users | grep _nixbld
log "partition"
cat /etc/fstab | grep 'nix'
log "synthetic root directory"
ls -l /etc/synthetic.conf | grep 'nix'
log "synthetic volume"
diskutil list /nix
log "user folders"
ls -l ~/.nix-profile ~/.nix-defexpr ~/.nix-channels
log "root folders"
sudo ls -l /etc/nix /var/root/.nix-profile /var/root/.nix-defexpr /var/root/.nix-channels
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment