1
+ #! /usr/bin/env bash
2
+
3
+ echo " "
4
+ echo " If you've still got a problem after this"
5
+ if [ " $( uname) " = " Darwin" ]
6
+ then
7
+ echo " take a look here: https://nixos.org/manual/nix/stable/installation/installing-binary.html#macos"
8
+ else
9
+ echo " take a look here: https://nixos.org/manual/nix/stable/installation/installing-binary.html#linux"
10
+ fi
11
+ echo " Okay?"
12
+ read
13
+
14
+ if [ -z " $NIX_ROOT " ]
15
+ then
16
+ export NIX_ROOT=" /nix"
17
+ fi
18
+
19
+
20
+
21
+ if [ " $( uname) " = " Darwin" ]
22
+ then
23
+ # TODO: make sure this fully removes LaunchDaemon: org.nixos.darwin-store
24
+ sudo launchctl bootout system/org.nixos.darwin-store
25
+
26
+ # check if file exists
27
+ if [ -f " /Library/LaunchDaemon/org.nixos.nix-daemon.plist" ]
28
+ then
29
+ echo " removing LaunchDaemon1"
30
+ sudo launchctl unload /Library/LaunchDaemon/org.nixos.nix-daemon.plist
31
+ sudo rm /Library/LaunchDaemons/org.nixos.nix-daemon.plist
32
+ fi
33
+
34
+
35
+ # check if file exists
36
+ if [ -f " /Library/LaunchDaemons/org.nixos.activate-system.plist" ]
37
+ then
38
+ echo " removing LaunchDaemon2"
39
+ sudo launchctl unload /Library/LaunchDaemons/org.nixos.activate-system.plist
40
+ sudo rm /Library/LaunchDaemons/org.nixos.activate-system.plist
41
+ fi
42
+
43
+ # if it was mounted
44
+ if sudo diskutil list | grep ' Nix Store' & > /dev/null
45
+ then
46
+ echo " removing nix volume"
47
+ # it was removed successfully
48
+ if sudo diskutil apfs deleteVolume /nix
49
+ then
50
+ sudo diskutil apfs deleteVolume /nix && sudo rm -rf /nix/
51
+ fi
52
+ echo " may need to reboot for full effect"
53
+ fi
54
+
55
+ # check if file exists
56
+ mount_filepath=" /etc/synthetic.conf"
57
+ if [ -f " $mount_filepath " ]
58
+ then
59
+ echo " removing $mount_filepath "
60
+ # if file contains "nix"
61
+ if cat " $mount_filepath " | grep ' nix' & > /dev/null
62
+ then
63
+ # remove nix from the file
64
+ sudo mount_filepath=" $mount_filepath " -- bash -c '
65
+ sudo cat "$mount_filepath" | sed -E ' " '" ' s/nix\n?$//g' " '" ' > "$mount_filepath"
66
+ '
67
+ fi
68
+ fi
69
+
70
+ # check if file exists
71
+ if [ -f " /etc/fstab" ]; then
72
+ write_to_fstab () {
73
+ new_fstab_lines=" $0 "
74
+ # vifs must be used to edit fstab
75
+ # to make that work we create a patch using "diff"
76
+ # then tell vifs to use "patch" as an editor and apply the patch
77
+ /usr/bin/diff /etc/fstab <( /usr/bin/printf " %s" " $new_fstab_lines " ) | EDITOR=" /usr/bin/patch" sudo vifs
78
+ }
79
+ # if name_of_command doesnt exist
80
+ if /usr/bin/grep " $NIX_ROOT apfs rw" /etc/fstab; then
81
+ echo " Patching fstab"
82
+ fstab_without_nix=" $( /usr/bin/grep -v " $NIX_ROOT apfs rw" /etc/fstab) "
83
+ write_to_fstab " $fstab_without_nix "
84
+ fi
85
+ fi
86
+ fi
87
+
88
+
1
89
delete_user () {
2
90
user=" $1 "
3
91
# logs them out by locking the account
@@ -18,21 +106,27 @@ delete_user () {
18
106
19
107
remove_service () {
20
108
service=" $1 "
21
- sudo systemctl stop "$service"
22
- sudo systemctl disable "$service"
23
- sudo rm -f /etc/systemd/system/"$service"
24
- sudo rm -f /etc/systemd/system/"$service" # and symlinks that might be related
25
- sudo rm -f /usr/lib/systemd/system/"$service"
26
- sudo rm -f /usr/lib/systemd/system/"$service" # and symlinks that might be related
27
- sudo systemctl daemon-reload
28
- sudo systemctl reset-failed
109
+ # if systemctl exists
110
+ if [ -n " $( command -v " systemctl" ) " ]
111
+ then
112
+ sudo systemctl stop " $service "
113
+ sudo systemctl disable " $service "
114
+ sudo rm -f /etc/systemd/system/" $service "
115
+ sudo rm -f /etc/systemd/system/" $service " # and symlinks that might be related
116
+ sudo rm -f /usr/lib/systemd/system/" $service "
117
+ sudo rm -f /usr/lib/systemd/system/" $service " # and symlinks that might be related
118
+ sudo systemctl daemon-reload
119
+ sudo systemctl reset-failed
120
+ fi
29
121
}
30
122
31
123
# stop the daemon
124
+ echo " removing service"
32
125
remove_service nix-daemon.service
33
126
remove_service nix-daemon.socket
34
127
35
128
# remove the users
129
+ echo " removing users"
36
130
delete_user nixbld1
37
131
delete_user nixbld2
38
132
delete_user nixbld3
@@ -67,12 +161,15 @@ delete_user nixbld31
67
161
delete_user nixbld32
68
162
69
163
# remove the group
164
+ echo " removing group"
70
165
sudo groupdel nixbld 2> /dev/null
71
166
72
167
# remove all the files
73
- sudo rm -rf /etc/nix /nix /var/root/.nix-profile /var/root/.nix-defexpr /var/root/.nix-channels "$HOME"/.nix-profile "$HOME"/.nix-defexpr "$HOME"/.nix-channels
168
+ echo " removing all nixpkgs files"
169
+ sudo rm -rf /etc/nix /nix /var/root/.nix-profile /var/root/.nix-defexpr /var/root/.nix-channels " $HOME " /.nix-profile " $HOME " /.nix-defexpr " $HOME " /.nix-channels 2> /dev/null
74
170
75
171
# restore the shell files
172
+ echo " restoring any shell files"
76
173
if [ -f " /etc/bashrc.backup-before-nix" ]
77
174
then
78
175
sudo mv /etc/bashrc.backup-before-nix /etc/bashrc
88
185
if [ -f " /etc/bash.bashrc.backup-before-nix" ]
89
186
then
90
187
sudo mv /etc/bash.bashrc.backup-before-nix /etc/bash.bashrc
188
+ fi
189
+
190
+ echo " final check"
191
+ if [ -e " $NIX_ROOT " ]
192
+ then
193
+ sudo rm -rf " $NIX_ROOT " & > /dev/null
194
+ sudo rm -f " $NIX_ROOT " & > /dev/null
195
+ if [ -e " $NIX_ROOT " ]
196
+ then
197
+ echo
198
+ echo
199
+ echo
200
+ echo " Because your system mounted /nix during boot"
201
+ echo " I believe you'll need to restart for changes to take affect"
202
+ fi
91
203
fi
0 commit comments