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

Uninstall directions do not work #3900

Open
raxod502-plaid opened this issue Aug 5, 2020 · 21 comments
Open

Uninstall directions do not work #3900

raxod502-plaid opened this issue Aug 5, 2020 · 21 comments
Labels

Comments

@raxod502-plaid
Copy link

Describe the bug

The instructions at this issue comment to uninstall Nix do not work.

Steps To Reproduce

$ sudo rm -rf /nix
rm: /nix/.Spotlight-V100: Operation not permitted
rm: /nix/.Trashes: Operation not permitted
rm: /nix: Resource busy

Expected behavior

The directory should have been deleted. Apparently, some additional step is required. As suggested later in the linked issue thread, I already tried mounting, unmounting, rebooting, but to no avail.

nix-env --version output

Not available since I am trying to uninstall and already deleted the binaries.

Additional context

macOS Catalina, 10.15.6

@abathur
Copy link
Member

abathur commented Aug 8, 2020

@raxod502-plaid It looks like (probably new in Catalina), macOS is requiring the Full Disk Access permission in order to modify these files.

Workaround (for anyone needing to remove these files to finish uninstalling Nix):

  1. add the permission:
    • Run open -n "x-apple.systempreferences:com.apple.preference.security?Privacy_AllFiles" or manually open System Preferences > Security & Privacy > Full Disk Access

    • Unlock to make changes.

    • Add an exemption for either your terminal app or shell. I suspect the right program will already be in the list (unchecked--IIRC accessing protected files with a program should add it to the list), in which case you can just tick it's checkbox. If not, you'll need to click "+" and find it.

      I keep the exemption enabled myself, but you may want to remove it after you're done. It's intended to keep programs (whether legitimate, or malware) from accessing some sensitive files without your permission.

  2. Re-run the uninstall command that failed (exact command differs between single-/multi-user installs).

Fixing this in the installer

The closest we can probably get to a real fix is either :

  1. keeping macOS from creating these/proactively beating macOS to the punch
  2. nudging all macOS users towards creating the exemption they'll need to uninstall during the installation process

I don't think the latter is worth exploring unless the former fails for some reason... mixed thoughts:

  • It sounds like some people successfully block creation of .Trashes/ with something like touch /nix/.Trashes. Worth testing.
  • We already add nobrowse to the mount settings in /etc/fstab, which does appear to disable spotlight indexing (can check this with mdutil -s /nix).
  • For some reason nobrowse may both disable indexing but not suffice for keeping it from creating the .Spotlight-V100 directory. I'm not certain why, but I do have the spotlight directory on one of my test systems, but not on my main.
    • At one point I think we had something like sudo mdutil -i off /nix either in the install script, or in the documented recommendations. IIRC we removed it because it reports an error to the user that we couldn't figure out, and it seemed nobrowse was sufficient. Running this command might have some additional effect, even if there's an error. I may have installed my main system when this was still the recommended approach.
    • Back in April I identified another approach that we haven't tried (since nobrowse seemed sufficient), which is touch /nix/.metadata_never_index. It's worth confirming whether this keeps macOS from creating the file. Not sure if we need to fiddle file permissions?

@raxod502-plaid
Copy link
Author

Thank you for the response! I really appreciate it. Unfortunately, while enabling the Full Disk Access permission fixes the Operation not permitted errors, it does not fix the Resource busy error:

$ sudo rm -rf /nix
rm: /nix: Resource busy

Does that require an additional step? Unmounting and re-mounting the Nix volume does not seem to affect this.

While investigating this, I discovered that I could delete the Nix volume via Disk Utility, which seemed prudent to follow as an uninstall step. However, I now receive this error message instead:

$ sudo rmdir /nix
rmdir: /nix: Read-only file system

@abathur
Copy link
Member

abathur commented Aug 11, 2020

The Catalina-specific install prints a set of Catalina-specific uninstall instructions; I think they are the gap here:

echo " ------------------------------------------------------------------ "
echo " | This installer will create a volume for the nix store and |"
echo " | configure it to mount at /nix. Follow these steps to uninstall. |"
echo " ------------------------------------------------------------------ "
echo ""
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"

I imagine you may also need to reboot for all of that to take.

@raxod502-plaid
Copy link
Author

Yes, you are exactly right. Those steps successfully remove the /nix directory. Perhaps they can be added to the documentation? It certainly did not occur to me to save a copy of the installer output for reference later.

@sambacha
Copy link

Alternatively you can just use Disk Utilities

First ERASE
Second REMOVE
Third EMPTY TRASHBIN

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

@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/anyone-up-for-picking-at-some-nix-onboarding-improvements/13152/6

@stale
Copy link

stale bot commented Jan 8, 2022

I marked this as stale due to inactivity. → More info

@jeff-hykin
Copy link

Still a problem on Monterey, there is no fstab cause volumes are handled differently, sudo vifs is empty except for comments. Probably needs diskutil specific commands to undo the changes in a script.

Whenever I get around to updating my uninstall script, I'll add M1/Monterey and post it here.

@abathur
Copy link
Member

abathur commented Oct 3, 2022

on Monterey, there is no fstab cause volumes are handled differently

@jeff-hykin This isn't true.

This issue is also quite old, and there are updated official uninstall instructions at https://nixos.org/manual/nix/stable/installation/installing-binary.html#macos.

If you have a Nix Store volume but don't see it in /etc/fstab, I suspect the cause is that you've run the installer more than once without following the uninstall instructions linked above first. The installer isn't idempotent, so it may have removed the store volume here

fstab_uninstall_prompt() {
cat <<EOF
During install, I add '${NIX_ROOT}' to /etc/fstab so that macOS knows what
mount options to use for the Nix volume.
EOF
cp /etc/fstab "$SCRATCH/fstab.edit"
# technically doesn't need the _sudo path, but throwing away the
# output is probably better than mostly-duplicating the code...
delete_nix_vol_fstab_line patch "$SCRATCH/fstab.edit" &>/dev/null
# if the patch test edit, minus comment lines, is equal to empty (:)
if /usr/bin/diff -q <(:) <(/usr/bin/grep -v "^#" "$SCRATCH/fstab.edit") &>/dev/null; then
# this edit would leave it empty; propose deleting it
if confirm_rm "/etc/fstab"; then
return 0
else
echo "Remove nix from /etc/fstab (or remove the file)"
fi
else
echo "I might be able to help you make this edit. Here's the diff:"
if ! _diff "/etc/fstab" "$SCRATCH/fstab.edit" && ui_confirm "Does the change above look right?"; then
delete_nix_vol_fstab_line /usr/sbin/vifs
else
echo "Remove nix from /etc/fstab (or remove the file)"
fi
fi
}
and then fallen over before re-adding it later.

@jeff-hykin
Copy link

jeff-hykin commented Oct 5, 2022

on Monterey, there is no fstab cause volumes are handled differently

@jeff-hykin This isn't true.

Screen Shot 2022-10-05 at 6 43 28 AM

Screen Shot 2022-10-05 at 6 39 52 AM

@abathur so.. ? maybe there is some way to add an /etc/fstab but mine doesn't exist

@stale stale bot removed the stale label Oct 5, 2022
@jeff-hykin
Copy link

jeff-hykin commented Oct 5, 2022

Thanks for the updated instructions though. It contains the diskutil command I was going to try to find on my own:

sudo diskutil apfs deleteVolume /nix

The CLI installer still gives outdated instructions though (the original issue). But if the CLI installer mentions that URL, "Looks like you already have Nix installed. If you need to uninstall Nix see: https://nixos.org/manual/nix/stable/installation/installing-binary.html#macos" then I think this issue can be closed.

@abathur
Copy link
Member

abathur commented Oct 5, 2022

/etc/fstab is a file the user can create for specifying volume mounts, not something the system will ship with or create for you. See man fstab.

(And like I said before, running the installer a 2nd time might explain why yours is missing despite having nix installed. )

@jeff-hykin
Copy link

jeff-hykin commented Oct 11, 2022

running the installer a 2nd time might explain why yours is missing despite having nix installed

it does not. Which is why I was saying:

if the CLI installer mentions that URL, "Looks like you already have Nix installed. If you need to uninstall Nix see: https://nixos.org/manual/nix/stable/installation/installing-binary.html#macos" then I think this issue can be closed.

@abathur
Copy link
Member

abathur commented Oct 11, 2022

it does not... if the CLI installer mentions that URL

If re-running the installer does not explain what you reported (as opposed to your assertion that on Monterey "there is no fstab cause volumes are handled differently"), why would adding a message to the installer fix your problem?

Regardless of the cause in your case, I agree that CLI messaging around uninstall instructions should be better.

@jeff-hykin
Copy link

why would adding a message to the installer fix your problem?

This github issue ("Uninstall directions do not work"). I followed the uninstall directions, they result in errors, and I had to go hunting for the full install directions.

I agree that CLI messaging around uninstall instructions should be better

Then we're on the same page 👍 .
I don't know where the message is in the source code, but if someone links to it I'll make a PR that should close this

@abathur
Copy link
Member

abathur commented Oct 12, 2022

I followed the uninstall directions

Which ones?

I don't know where the message is in the source code

Which one?

You've never quoted a message or posted a log. The installer has changed somewhat since this old issue was opened. The message I quoted earlier in this thread is now only emitted if someone directly executes or sources scripts/create_darwin_volume.sh (i.e., it only prints in a legacy mode for people depending on directly running the old script; this is not how the normal installer does it). Aside from that message, the only other instructions mentioned in this issue are the OP's link to a 2017 comment on a different issue.

@jeff-hykin
Copy link

jeff-hykin commented Oct 13, 2022

The installer has changed somewhat
Which one?

Latest nix installer as far as I'm aware
bash <(curl -Lk https://releases.nixos.org/nix/nix-2.11.1/install)

Following these instructions results in errors:

Screen Shot 2022-10-12 at 7 21 13 PM

@abathur
Copy link
Member

abathur commented Oct 13, 2022

  • uninstall_directions() {
    subheader "Uninstalling nix:"
    local step=0
    if poly_service_installed_check; then
    step=$((step + 1))
    poly_service_uninstall_directions "$step"
    fi
    for profile_target in "${PROFILE_TARGETS[@]}"; do
    if [ -e "$profile_target" ] && [ -e "$profile_target$PROFILE_BACKUP_SUFFIX" ]; then
    step=$((step + 1))
    cat <<EOF
    $step. Restore $profile_target$PROFILE_BACKUP_SUFFIX back to $profile_target
    sudo mv $profile_target$PROFILE_BACKUP_SUFFIX $profile_target
    (after this one, you may need to re-open any terminals that were
    opened while it existed.)
    EOF
    fi
    done
    step=$((step + 1))
    cat <<EOF
    $step. Delete the files Nix added to your system:
    sudo rm -rf /etc/nix $NIX_ROOT $ROOT_HOME/.nix-profile $ROOT_HOME/.nix-defexpr $ROOT_HOME/.nix-channels $HOME/.nix-profile $HOME/.nix-defexpr $HOME/.nix-channels
    and that is it.
    EOF
    }
  • poly_service_uninstall_directions() {
    echo "$1. Remove macOS-specific components:"
    if should_create_volume && test_nix_volume_mountd_installed; then
    nix_volume_mountd_uninstall_directions
    fi
    if test_nix_daemon_installed; then
    nix_daemon_uninstall_directions
    fi
    }

@zimbatm
Copy link
Member

zimbatm commented Dec 11, 2022

@AlaiY95
Copy link

AlaiY95 commented Apr 22, 2023

Well I'll be damned, this worked! Never seen a pm so weird to uninstall. Thanks!

@LandonSchropp
Copy link

Here's the updated location of the macOS uninstallation instructions:

https://github.com/NixOS/nix/blob/master/doc/manual/src/installation/uninstall.md#macos

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

No branches or pull requests

8 participants