Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to completely remove Nix from OS X #458

Closed
chamini2 opened this issue Jan 24, 2015 · 23 comments
Closed

How to completely remove Nix from OS X #458

chamini2 opened this issue Jan 24, 2015 · 23 comments

Comments

@chamini2
Copy link

Hi, I want to do a clean install of Nix on my computer, but I can't find how to uninstall it. In the manual, in chapter 4, it states the following:

Nix can be uninstalled using rpm -e nix or dpkg -r nix on RPM- and Dpkg-based systems, respectively. After this you should manually remove the Nix store and other auxiliary data, if desired:

$ rm -rf /nix

But I'm on OS X. What steps should I follow?

@wmertens
Copy link
Contributor

Rm -rf /nix

On Sat, Jan 24, 2015, 5:07 PM Matteo Ferrando [email protected]
wrote:

Hi, I want to do a clean install of Nix on my computer, but I can't
find how to uninstall it. In the manual, in chapter 4, it states the
following:

Nix can be uninstalled using rpm -e nix or dpkg -r nix on RPM- and
Dpkg-based systems, respectively. After this you should manually remove the
Nix store and other auxiliary data, if desired:

$ rm -rf /nix

But I'm on OS X. What steps should I follow?


Reply to this email directly or view it on GitHub
#458.

@caius
Copy link

caius commented Apr 2, 2015

Just an extra note for anyone finding this issue via google in future, to completely remove nix on OS X, I found I had to tidy up a couple of (now broken) symlinks in my home folder with rm -rf ~/.nix-* as well. (After doing sudo rm -rf /nix that is.)

@lingnand
Copy link

Also don't forget to remove that . $HOME/.nix-profile/etc/profile.d/nix.sh from .profile.

@Cireo
Copy link

Cireo commented Jan 3, 2017

You may also have persistent information in /etc/nix/nix.conf (http://nixos.org/nix/manual/#ch-files) that might taint a new install.

@copumpkin
Copy link
Member

These tidbits should be added to the manual. Anyone want to submit a PR?

@JamesMcMahon
Copy link

On multi user systems you may want to check out the additional instructions at #1402.

Instead of the manual it would be great to have an uninstall script that took care of everything.

@toraritte
Copy link
Contributor

toraritte commented May 30, 2018

A probably naïve idea: what if the install script would generate an uninstall script and (try to) restore all that has been touched?

As far as I can tell, https://nixos.org/nix/install is generated from the https://github.com/NixOS/nix/blob/master/scripts/install.in template (populated via https://github.com/NixOS/nix/blob/master/release.nix#L285).

EDIT (2018/05/30 1457)
This may be already in place or at least in part? I accidentally tried to install nix from under another account and it failed with a lot of helpful error messages, with the last section titled "Uninstalling nix:". Also found the *.backup-before-nix files, but removing users/groups were not mentioned.
(commit 2921165)

@tscholak
Copy link

tscholak commented Nov 11, 2018

From the multiuser installation script:

Uninstalling nix:
1. Delete the files Nix added to your system:

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

and that is it.

there may also be references to nix in ~/.profile, ~/.bashrc, ~/.zshrc, etc. that you may want to get rid of. The multiuser installation script tells you exactly what to do.

@expelledboy
Copy link

I had a crack at writing an uninstall script for OSx. Hope someone finds this helpful!

@PaulRBerg
Copy link

PaulRBerg commented Jun 6, 2020

Hey @expelledboy, your script contains the following code:

if [ -L $HOME/Applications ]; then
  rm $HOME/Applications
fi

I might be wrong, but that doesn't look safe to me.

@expelledboy
Copy link

I might be wrong, but that doesn't look safe to me.

I am simply removing the link. Perhaps I could change it to use something like [ readlink $HOME/Applications ~= nix ] but readlink seems to not work sometimes.

@PaulRBerg
Copy link

PaulRBerg commented Jun 9, 2020

It just looks scary to run a script written by someone on the Internet that has a line that contains both "rm" and "$HOME/Applications".

I'm sure that a seasoned programmer would immediately figure out if that's a malicious line or not, but noobs like me can't do it.

Maybe worth it to add an explanatory comment above that code block.

@joehenry087
Copy link

Also don't forget to delete relevant files in ~/.cache. I don't know if other programs use ~/.cache but all I had in there was nix related items.

@joehenry087
Copy link

Also don't forget to delete a ~/.config/nix if you have one.

@runeksvendsen
Copy link
Contributor

runeksvendsen commented Dec 28, 2021

Rm -rf /nix

I did this and I ended up with an empty /nix folder, which caused the Nix installer to think I already have Nix installed and therefore it refused to reinstall Nix.

Running sudo rm -rf /nix to remove this empty folder gave me the error:

rm: /nix: Read-only file system

I tried disabling System Integrity Protection (SIP) and the above error remained.

It took me a bit of research, but the solution is to edit the file /etc/synthetic.conf and remove the line saying nix. This will cause /nix to no longer be mounted at boot which allows Nix to be reinstalled.

EDIT: During reinstallation I noticed the below steps are printed, which is exactly what is required (some of which I forgot to mention):

| This installer will create a volume for the nix store and |
| configure it to mount at /nix. Follow these steps to uninstall. |
------------------------------------------------------------------

  1. Remove the entry from fstab using 'sudo vifs'
  2. Destroy the data volume using 'diskutil apfs deleteVolume'
  3. Remove the 'nix' line from /etc/synthetic.conf or the file

@Silic0nS0ldier
Copy link

Silic0nS0ldier commented Jan 24, 2022

Found a few more places where traces are left behind (docs helped here). I've rolled in bits and pieces from earlier comments as well.

  1. Remove Nix from launchd (see /Library/LaunchDaemons and ~/Library/LaunchDaemons)
  2. Remove nix from /etc/synthetic.conf
  3. Remove nix from /etc/fstab (use vifs)
  4. Remove Nix from shell (e.g. ~/.zshrc)
  5. (good time to reboot)
  6. Remove Nix APFS volume (not sure how to do this in shell, but the Disk Utility app should do the trick)
  7. Remove Nix user group (once again not sure how to with shell, can System Preferences > Users & Groups covers this)
    Users can be removed with dscl (e.g. sudo dscl . delete /Users/_nixbld1)
  8. Remove any nix traces in ~/Applications (none in my case)
  9. Remove .nix* files in ~/, ~/.config and ~/.cache
  10. Remove /etc/nix
  11. Remove .nix* files in /var/root/ and /var/root/.cache
  12. Cleanup /etc/bash.bashrc, /etc/bashrc
  13. Cleanup /etc/zshrc

This can probably be streamlined and (to a large extent) automated. There are probably still bits of Nix hiding away but this is the cleanest I've managed to get the system prior to reinstall so far.

Side note for Nix maintainers, this removal has been performed in an attempt to fix nix-shell hanging indefinitely. It appears some bad derivation builds corrupted something important. Or issues from the initial problematic install reared their head. Or a combination of both.

@benkeil
Copy link

benkeil commented Jan 26, 2022

To remove the "Nix Store" volume on Mac, you need to use the Disk Utility.

I can't point out, how disappointed I am with nix...

@nevir
Copy link

nevir commented May 5, 2022

In addition to @Silic0nS0ldier's notes, there's also config at /etc/zshrc

@gingerbeardman
Copy link

gingerbeardman commented May 24, 2022

I used this guide: https://iohk.zendesk.com/hc/en-us/articles/4415830650265-Uninstall-nix-on-MacOS

It's almost unbelievable that there is no provided uninstaller.

@hraban
Copy link
Member

hraban commented Oct 3, 2022

I used this guide: https://iohk.zendesk.com/hc/en-us/articles/4415830650265-Uninstall-nix-on-MacOS

This worked except for the last step, deleting the /nix volume. I got this error:

The volume "Nix Store" on disk1s7 couldn't be unmounted because it is in use by process 0 (kernel)

I had to reboot the machine, after which it was mounted as /Volumes/Nix Store instead of /nix, at which point I could remove it using

sudo diskutil apfs deleteVolume /Volumes/Nix\ Store

(intel mac running Monterey.)

@timmyjose
Copy link

This is. the best example of why I (and other people) hate such programs that provide only installation scripts, and no uninstallation ones. Primitive? Yes. Intentional? Maybe. Irritating? Definitely.

@expelledboy
Copy link

I already posted this on my gist.

Anyone that comes here, just a heads up there are now official docs for uninstalling nix

@hraban
Copy link
Member

hraban commented Jan 23, 2024

This is. the best example of why I (and other people) hate such programs that provide only installation scripts, and no uninstallation ones. Primitive? Yes. Intentional? Maybe. Irritating? Definitely.

Everyone knows this. It's a matter of priorities, not lack of awareness.

Comments like this are understandable, but ultimately without much value beyond catharsis for the author. Ironically this comment applies to itself: "Primitive? Yes. Intentional? Maybe. Irritating? Definitely."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests