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 · 27 comments
Closed

How to completely remove Nix from OS X #458

chamini2 opened this issue Jan 24, 2015 · 27 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 notifications@github.com
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."

@mpstaton
Copy link

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

Right? I followed instructions to uninstall line by line and ended up with this nonsense:

image

@mpstaton
Copy link

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

Sure, but I mean the whole point of Nix is to make it easy to replicate environments -- actually, that's not the point at all. The reason to spend front-loaded time to make it easy to replicate environments is precisely so that I don't spend a full weekend reading forums, copypasta from Stack Overflow, praying and leaving my wife feeling neglected.

So, these comments are only "not helpful" if the many people behind Nix just naively feels like adding steroids to what is clearly the most useful offering on the market...

@hraban
Copy link
Member

hraban commented Nov 24, 2024

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

Right? I followed instructions to uninstall line by line and ended up with this nonsense:
image

That looks like the installer from Determinate Systems which is a 3rd party installer unaffiliated with this repository. Not sure if that was on purpose, maybe I'm misunderstanding your screenshot here, but if it's the detsys installer this is the wrong issue tracker.

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

Sure, but I mean the whole point of Nix is to make it easy to replicate environments -- actually, that's not the point at all. The reason to spend front-loaded time to make it easy to replicate environments is precisely so that I don't spend a full weekend reading forums, copypasta from Stack Overflow, praying and leaving my wife feeling neglected.

So, these comments are only "not helpful" if the many people behind Nix just naively feels like adding steroids to what is clearly the most useful offering on the market...

But you left out my first sentence which is the point of my comment :/ "everyone knows". We all agree here. Nix is mostly developed by volunteers so people work on what interests them. Not many people are interested in writing uninstallers, apparently. That's how open source software works, y'all. I wish it weren't so! If you paid money for Nix this comment would be more useful.

From the perspective of people developing this, here's how these things sound:

  • Entitled and demoralizing: "Lacking an uninstaller is annoying!"
  • Supportive and energizing: "Here's a PR with an uninstaller"
  • Supportive and energizing: "Here's a $1k bounty for anyone who adds an uninstaller"

@hraban
Copy link
Member

hraban commented Nov 24, 2024

Speaking of which, maybe something to that end can be arranged with "https://opencollective.com/nix-macos". If anyone wants to reach out to the necessary people and get that a bounty locked in for an uninstaller that would be 👌

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