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 remove nix #1402

Closed
jarry9 opened this issue Jun 10, 2017 · 29 comments
Closed

How to remove nix #1402

jarry9 opened this issue Jun 10, 2017 · 29 comments

Comments

@jarry9
Copy link

jarry9 commented Jun 10, 2017

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: #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
Copy link
Member

zimbatm commented Jul 2, 2017

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
    On a multi-user install, also remove all the nixbld[0-9] users

@jarry9 jarry9 closed this as completed Jul 6, 2017
@jarry9
Copy link
Author

jarry9 commented Jul 6, 2017

Thank you

@pynixwang
Copy link

no offical uninstaller?

@pynixwang
Copy link

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

@SimSez
Copy link

SimSez commented Nov 20, 2017

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
Copy link

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
Copy link

jbyler commented May 11, 2018

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

  • my personal dotfiles didn't have anything to load nix, but I did have to clean up /etc/{profile,bashrc,zshrc}
  • I didn't bother to remove the nixbld[0-9] users (oops?)

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
Copy link
Member

HaoZeke commented Jan 4, 2019

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

@allter
Copy link

allter commented Feb 2, 2019

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
Copy link

Or for macOS:

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

@AurevoirXavier
Copy link

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

@expelledboy
Copy link

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

@PaulRBerg
Copy link

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
Copy link

PaulRBerg commented Jun 6, 2020

@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
Copy link

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

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

@sambacha
Copy link

sambacha commented Oct 27, 2020

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
Copy link
Member

lilyball commented Nov 5, 2020

@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
Copy link

sambacha commented Nov 6, 2020

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
Copy link

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
Copy link
Member

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
Copy link

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
Copy link

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
Copy link

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
Copy link

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
Copy link

kha84 commented Aug 29, 2022

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
Copy link

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

@Chiitoo
Copy link

Chiitoo commented Dec 30, 2023

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
Copy link

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 :)

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