NixOS / nix

Nix, the purely functional package manager
https://nixos.org/
GNU Lesser General Public License v2.1
12.77k stars 1.52k forks source link

How to remove nix #1402

Closed jarry9 closed 7 years ago

jarry9 commented 7 years ago

Hi,

I am using nix on Ubuntu 16. I installed nix by these commands:

bash <(curl https://nixos.org/nix/install) source ~/.nix-profile/etc/profile.d/nix.sh

I have not started nix-daemon. Or I did not use any extra command...

I will not remove the nix package manager now. But If I should remove it, what should I type on command line? Is there any ready script or something?

I found this topic: https://github.com/NixOS/nix/issues/458 But it is not completely clear about uninstallation. Because there is not only /nix folder. There are link files on HOME + nix has set some directories to PATH variable?

How can I make sure that I remove it completely?

Thank you

zimbatm commented 7 years ago

To uninstall nix you will need to do the following things:

jarry9 commented 7 years ago

Thank you

pynixwang commented 7 years ago

no offical uninstaller?

pynixwang commented 7 years ago

I find a new way, install again and installer will tell you how to remove it, all included but deleting user.

SimSez commented 6 years ago

Hi there,

I've completed the third step (sudo -fr/nix)

How does one go about these first two steps on OSX, is this from within the terminal? I can't seem to find the .profile or .bash_profile

To uninstall nix you will need to do the following things:

remove the . "$HOME/.nix-profile/etc/profile.d/nix.sh" line in your ~/.profile or ~/.bash_profile

rm -rf $HOME/{.nix-channels,.nix-defexpr,.nix-profile,.config/nixpkgs}

sudo rm -rf /nix

JamesMcMahon commented 6 years ago

I find a new way, install again and installer will tell you how to remove it, all included but deleting user.

@pynixwang This didn't work for me under macOS. What command did you run to see the uninstall options?

jbyler commented 6 years ago

I followed @zimbatm's instructions, with some tweaks:

But I found one important piece was missing, and which the nix installer did not detect upon reinstallation: there was a lingering /Library/LaunchDaemons/org.nixos.nix-daemon.plist pointing to the old version of nix. After reinstalling, I had to do something like this to get launchctl to pick up the changes in the new version:

sudo launchctl unload -w /Library/LaunchDaemons/org.nixos.nix-daemon.plist
sudo launchctl load -w /Library/LaunchDaemons/org.nixos.nix-daemon.plist

Perhaps better would have been to remove and unload the launchdaemon as part of uninstalling.

HaoZeke commented 5 years ago

As I'm sure people know, none of these instructions clean up the large set of users created..

allter commented 5 years ago

Yeah, the instructions of upgrading Nix tell just to repeat curl |sh. Then instructions in install script find earlier NIX installation remnants and ask you to delete /nix, profiles etc with only rm -rf

But those instructions don't mention:

  1. removing nix remnants in /usr/local (bin and conf)
  2. removing users with: for i in $(seq 1 10); do sudo userdel -f nixbld$i; done sudo groupdel nixbld
mbaltaks commented 5 years ago

Or for macOS:

for num in {1..32}; do sudo dscl . -delete /Users/nixbld$num; done
sudo dscl . -delete /Groups/nixbld
AurevoirXavier commented 5 years ago

@mbaltaks Also: for num in {1..32}; do sudo dscl . -delete /Groups/staff GroupMembership nixbld$num; done

expelledboy commented 5 years ago

I had a crack at writing a complete uninstall script for OSx. Hope someone finds this useful.

PaulRBerg commented 4 years ago

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.

PaulRBerg commented 4 years ago

@zimbatm's solution always worked for me, except for the sudo rm -rf /nix step. Getting this error:

rm: /nix: Resource busy

This is with nix@2.3.6.

Update: I unmounted the Nix Store disk with the Disk Utility app, but now I'm getting this other error:

rm: /nix: Read-only file system

An official uninstall script would've been super helpful.

Update 2: After mounting the Nix Store again and restarting my computer, sudo rm -rf /nix finally worked. Don't know why.

expelledboy commented 4 years ago

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.

Why? I am removing a link. Perhaps I could have checked if the link was generated by nix.

PaulRBerg commented 4 years ago

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 others (including me) didn't.

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

sambacha commented 4 years ago

Just to update this for people using Mac OS X

You still have to erase then remove your nix partition under Disk Utilities

Running $ sudo rm -rf ~/nix may yield a Resource is Busy message

$ ls -alh /nix will show that there are some mac os x specific files like:

.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns

edit: these files are why nix persists on the filesystem after trying to remove it using instructions above

Bring up Disk Utilities then go and remove

After deleting you can rm -rf ~/nix running $ lsof +D /nix will show nothing, meaning it has been removed

don't forget to empty your trashbin

lilyball commented 4 years ago

@sambacha Your instructions reference ~/nix, which isn't a path used by Nix. Assuming you meant /nix where you wrote ~/nix, there should never be any need to run rm -rf /nix on macOS since it's now a volume.

The uninstall instructions for macOS are printed during the install. Currently they are

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

though this will change slightly with #4181.

sambacha commented 4 years ago

My instructions reference ~/nix because of the contents listed in that directory that may persist depending on how nix is removed.

It could be any directory where the end user decided to install ~nix, I included it as a reference not as a definitive how to guide, just so that it may spare someone more time from searching for additional help perhaps.

Excited to see some updates for Nix , thanks for letting me know as well, cheers

joehenry087 commented 3 years ago

On Big Sur, M1 mac, I have tried removing the /nix directory and got an error. Thanks to your help @sambacha I was able to delete the volume. Now the rm command succeeds, however there is still a /nix directory in Finder and doing ls / shows it too.

Does anyone know how to remove this or proper nix uninstall directions for Catalina and after?

lilyball commented 3 years ago

On Big Sur, M1 mac, I have tried removing the /nix directory and got an error. Thanks to your help @sambacha I was able to delete the volume. Now the rm command succeeds, however there is still a /nix directory in Finder and doing ls / shows it too.

Does anyone know how to remove this or proper nix uninstall directions for Catalina and after?

You probably have to edit /etc/synthetic.conf to remove the line nix, and then reboot. The empty directory exists because it's a mount point defined by this file.

joehenry087 commented 3 years ago

Ah, thank you @lilyball. Same time you posted I just found this very helpful guide for post Mojave uinstalls: https://gist.github.com/chriselsner/3ebe962a4c4bd1f14d39897fc5619732

peter-mlabs commented 2 years ago

Would like to add that environment variables, on my system, were also set in /usr/lib/environment.d/nix-daemon.conf, including NIX_REMOTE which can cause issues if you're trying to move to a single-user install.

dhananjaylatkar commented 2 years ago

To remove nixbldX users from Linux -

grep nixbld /etc/passwd | awk -F ":" '{print $1}' > /tmp/nixusers
cat /tmp/nixusers | xargs -t -n 1 sudo userdel -r
commscheck commented 2 years ago

If you're coming here from Google, official documentation for uninstalling nix is available here: https://nixos.org/manual/nix/stable/installation/installing-binary.html#uninstalling

kha84 commented 2 years ago

The "official" uninstalling instructions are inaccurate. Like right now, they're suggesting to delete these ones:

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

... whereas on my system I found also /etc/profile.d/nix.sh

Also there's a whole bunch of **nixbld*** users were created during install:

 cat /etc/passwd | grep -i nix
nixbld1:x:30001:30000:Nix build user 1:/var/empty:/sbin/nologin
nixbld2:x:30002:30000:Nix build user 2:/var/empty:/sbin/nologin
nixbld3:x:30003:30000:Nix build user 3:/var/empty:/sbin/nologin
nixbld4:x:30004:30000:Nix build user 4:/var/empty:/sbin/nologin
nixbld5:x:30005:30000:Nix build user 5:/var/empty:/sbin/nologin
nixbld6:x:30006:30000:Nix build user 6:/var/empty:/sbin/nologin
nixbld7:x:30007:30000:Nix build user 7:/var/empty:/sbin/nologin
nixbld8:x:30008:30000:Nix build user 8:/var/empty:/sbin/nologin
nixbld9:x:30009:30000:Nix build user 9:/var/empty:/sbin/nologin
nixbld10:x:30010:30000:Nix build user 10:/var/empty:/sbin/nologin
nixbld11:x:30011:30000:Nix build user 11:/var/empty:/sbin/nologin
nixbld12:x:30012:30000:Nix build user 12:/var/empty:/sbin/nologin
nixbld13:x:30013:30000:Nix build user 13:/var/empty:/sbin/nologin
nixbld14:x:30014:30000:Nix build user 14:/var/empty:/sbin/nologin
nixbld15:x:30015:30000:Nix build user 15:/var/empty:/sbin/nologin
nixbld16:x:30016:30000:Nix build user 16:/var/empty:/sbin/nologin
nixbld17:x:30017:30000:Nix build user 17:/var/empty:/sbin/nologin
nixbld18:x:30018:30000:Nix build user 18:/var/empty:/sbin/nologin
nixbld19:x:30019:30000:Nix build user 19:/var/empty:/sbin/nologin
nixbld20:x:30020:30000:Nix build user 20:/var/empty:/sbin/nologin
nixbld21:x:30021:30000:Nix build user 21:/var/empty:/sbin/nologin
nixbld22:x:30022:30000:Nix build user 22:/var/empty:/sbin/nologin
nixbld23:x:30023:30000:Nix build user 23:/var/empty:/sbin/nologin
nixbld24:x:30024:30000:Nix build user 24:/var/empty:/sbin/nologin
nixbld25:x:30025:30000:Nix build user 25:/var/empty:/sbin/nologin
nixbld26:x:30026:30000:Nix build user 26:/var/empty:/sbin/nologin
nixbld27:x:30027:30000:Nix build user 27:/var/empty:/sbin/nologin
nixbld28:x:30028:30000:Nix build user 28:/var/empty:/sbin/nologin
nixbld29:x:30029:30000:Nix build user 29:/var/empty:/sbin/nologin
nixbld30:x:30030:30000:Nix build user 30:/var/empty:/sbin/nologin
nixbld31:x:30031:30000:Nix build user 31:/var/empty:/sbin/nologin
nixbld32:x:30032:30000:Nix build user 32:/var/empty:/sbin/nologin

and group:

$ cat /etc/group | grep nix
nixbld:x:30000:
Cyber-Dylan commented 10 months ago

I tried to delete /nix from my macbook but its telling me its read only and wont let me

Chiitoo commented 10 months ago

I tried to delete /nix from my macbook but its telling me its read only and wont let me

If you have not yet, see:

https://nixos.org/manual/nix/unstable/installation/uninstall.html

Cyber-Dylan commented 10 months ago

I tried to delete /nix from my macbook but its telling me its read only and wont let me

If you have not yet, see:

https://nixos.org/manual/nix/unstable/installation/uninstall.html

That worked for me, thanks for helping :)