Uninstalling Multi-User Nix
I am setting up a new computer running Arch Linux, and installing Nix was quite frustrating. The Install Nix page recommends installing the multi-user installation (by downloading and running a script). I have avoided multi-user installation in the past because I do not need multi-user functionality and prefer to minimize the running daemons/services on my computer. I decided to give it a try, however, since I have a lot of friction with Nix and the recommended practices might make it work a bit better for me. It did not work, however, so I uninstalled it.
The installation script prints great log information, but it unfortunately prints so much that it exceeded my terminal buffer, so that I can only see the end of it. I wish it would write the same information to a log file.
The installation script ran without issue, but the command that the script recommends running in a new shell to confirm installation fails.
$ nix-shell -p nix-info --run "nix-info -m"
error: could not set permissions on '/nix/var/nix/profiles/per-user' to 755: Operation not permitted
The command that the Install Nix page recommends running in a new shell to confirm installation also fails.
$ nix-env --version
error: could not set permissions on '/nix/var/nix/profiles/per-user' to 755: Operation not permitted
Searching online, it seems that this error is shown when the Nix daemon is not running. The output of the installation script indicates that the daemon is both enabled and started. Querying the system, however, I found that the service is inactive/dead.
$ sudo systemctl status nix-daemon.service
○ nix-daemon.service - Nix Daemon
Loaded: loaded (/etc/systemd/system/nix-daemon.service; linked; vendor preset: disabled)
Active: inactive (dead)
TriggeredBy: ○ nix-daemon.socket
Condition: start condition failed at Wed 2022-01-05 13:03:42 JST; 37min ago
└─ ConditionPathIsReadWrite=/nix/var/nix/daemon-socket was not met
Jan 05 13:03:42 exponential systemd[1]: Nix Daemon was skipped because of a
failed condition check (ConditionPathIsReadWrite=/nix/var/nix/daemon-socket).
This log indicates that the service failed to start because of a
permissions issue with /nix/var/nix/daemon-socket
. This
path does not exist on my system.
Since I do not really want to run the service anyway, I decided to abort the multi-user installation. There are some instructions for uninstallation in the Multi User Installation section of the manual, but they are incomplete and incorrect! (Aside: The new manual seems much slower than the old one.)
I uninstalled the multi-user installation of Nix in the following two steps. First, I removed the (non-working) service configuration and shell configuration.
$ sudo systemctl disable nix-daemon.socket
$ sudo systemctl disable nix-daemon.service
$ sudo systemctl daemon-reload
$ rm -rf ~/.nix-*
$ sudo bash -c 'rm -rf /root/.nix-*'
$ sudo mv /etc/bash.bashrc.backup-before-nix /etc/bash.bashrc
$ sudo rm /etc/bashrc /etc/zshrc
$ sudo rm /etc/profile.d/nix.sh
Second, I logged out and logged back in again to remove the Nix environment variables from my shell environment and then removed the Nix files, users, and group.
$ sudo rm -rf /nix /etc/nix
$ sudo userdel nixbld1
$ sudo userdel nixbld2
$ sudo userdel nixbld3
$ sudo userdel nixbld4
$ sudo userdel nixbld5
$ sudo userdel nixbld6
$ sudo userdel nixbld7
$ sudo userdel nixbld8
$ sudo userdel nixbld9
$ sudo userdel nixbld10
$ sudo userdel nixbld11
$ sudo userdel nixbld12
$ sudo userdel nixbld13
$ sudo userdel nixbld14
$ sudo userdel nixbld15
$ sudo userdel nixbld16
$ sudo userdel nixbld17
$ sudo userdel nixbld18
$ sudo userdel nixbld19
$ sudo userdel nixbld20
$ sudo userdel nixbld21
$ sudo userdel nixbld22
$ sudo userdel nixbld23
$ sudo userdel nixbld24
$ sudo userdel nixbld25
$ sudo userdel nixbld26
$ sudo userdel nixbld27
$ sudo userdel nixbld28
$ sudo userdel nixbld29
$ sudo userdel nixbld30
$ sudo userdel nixbld31
$ sudo userdel nixbld32
$ sudo groupdel nixbld