@@ -17,34 +17,30 @@ color_reset="\e[0m";color_reset=""
17
17
18
18
# saftey/cleanup
19
19
# if trap exists
20
- if [ -n " $( command -v " trap" ) " ]
21
- then
20
+ if [ -n " $( command -v " trap" ) " ]; then
22
21
trap ' unset repo; unset branch; unset setup_or_copy; unset mixin_remote_name; return 0' INT TERM
23
22
fi
24
23
25
24
#
26
- # if nix doesnt exist
25
+ # if nix command doesnt exist
27
26
#
28
- if [ -z " $( command -v " nix" ) " ]
29
- then
27
+ if [ -z " $( command -v " nix" ) " ]; then
30
28
#
31
29
# try sourcing some files, then check avail if nix is available
32
30
#
33
- if [ -f " /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh" ]
34
- then
31
+ if [ -f " /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh" ]; then
35
32
. " /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh"
36
33
fi
37
- if [ -f " $HOME /.nix-profile/etc/profile.d/nix.sh" ]
38
- then
34
+ if [ -f " $HOME /.nix-profile/etc/profile.d/nix.sh" ]; then
39
35
. " $HOME /.nix-profile/etc/profile.d/nix.sh"
40
36
fi
41
37
export PATH=" $PATH :/nix/var/nix/profiles/default/bin/"
42
38
39
+
43
40
#
44
- # if nix STILL doesnt exist
41
+ # if nix store doesn't exist
45
42
#
46
- if [ -z " $( command -v " nix" ) " ]
47
- then
43
+ if ! [ -d " /nix/store" ]; then
48
44
echo " |------------------------------------------------------|" 1>&2
49
45
echo " | |" 1>&2
50
46
echo " | I'll try to install nix for you |" 1>&2
53
49
echo " |------------------------------------------------------|" 1>&2
54
50
echo " "
55
51
# check for root
56
- if [ " $( whoami) " = " root" ]
57
- then
52
+ if [ " $( whoami) " = " root" ]; then
58
53
echo " $light_yellow "
59
54
echo " looks like you're logged in as root"
60
55
echo " sadly nix can't install on the root user"
61
56
echo " please use a regular user, then re-run this script"
62
57
echo " $color_reset "
63
58
# if users exists
64
- if [ -n " $( command -v " getent" ) " ] && [ -n " $( command -v " cut" ) " ]
65
- then
59
+ if [ -n " $( command -v " getent" ) " ] && [ -n " $( command -v " cut" ) " ]; then
66
60
users=" $( getent passwd {1000..6000} | cut -d: -f1) "
67
- if [ -n " $users " ] && [ " $users " != " root" ]
68
- then
61
+ if [ -n " $users " ] && [ " $users " != " root" ]; then
69
62
echo " the available users are:"
70
63
echo " $users "
71
64
echo
74
67
else
75
68
echo " "
76
69
echo " it looks like this system doesn't have any regular users"
77
-
70
+
78
71
# if useradd exists
79
- if [ -n " $( command -v " useradd" ) " ]
80
- then
72
+ if [ -n " $( command -v " useradd" ) " ]; then
81
73
question=" do you want me to make a regular user for you? [y/n]" ; answer=' '
82
74
while true ; do
83
75
echo " $question " ; read response
87
79
* ) echo " Please answer yes or no." ;;
88
80
esac
89
81
done
90
-
82
+
91
83
if [ " $answer " = ' yes' ]; then
92
84
echo " ${light_purple} Enter a username:${color_reset} "
93
85
read username
94
- if sudo useradd --create-home " $username " --password " password" --groups sudo
95
- then
86
+ if sudo useradd --create-home " $username " --password " password" --groups sudo; then
96
87
echo " "
97
88
echo " user created successfully"
98
89
echo " run:"
@@ -107,76 +98,75 @@ then
107
98
echo " Okay"
108
99
fi
109
100
fi
110
-
101
+
111
102
fi
112
103
echo " "
113
104
echo " login as the non-root user (${cyan} su USERNAME${color_reset} )"
114
105
echo " then re-run this command"
115
106
exit
116
107
fi
117
108
fi
109
+
118
110
#
119
111
# MacOS
120
112
#
121
- if [ " $( uname) " = " Darwin" ]
122
- then
113
+ if [ " $( uname) " = " Darwin" ]; then
123
114
debugging_info=" $debugging_info$newline " " I think you have a Mac because " ' "$OSTYPE" = "darwin"*' " came back true"
124
115
full_version=" $( sw_vers -productVersion) "
125
- major_version=" $( echo " $full_version " | sed -E ' s/([0-9]+)\.[0-9]+\.[0-9]+/\1/g' ) "
126
- minor_version=" $( echo " $full_version " | sed -E ' s/[0-9]+\.([0-9]+)\.[0-9]+/\1/g' ) "
116
+ major_version=" $( echo " $full_version " | sed -E ' s/([0-9]+)\.[0-9]+( \.[0-9]+)? /\1/g' ) "
117
+ minor_version=" $( echo " $full_version " | sed -E ' s/[0-9]+\.([0-9]+)( \.[0-9]+)? /\1/g' ) "
127
118
#
128
119
# Big Sur or Newer
129
120
#
130
- if [ " $major_version " = " 11" ]; then
131
- sh <( curl -Lk https://releases.nixos.org/nix/nix-2.3.7/install) --darwin-use-unencrypted-nix-store-volume
121
+ if [ " $major_version " = " 11" ] || \
122
+ [ " $major_version " = " 12" ] || \
123
+ [ " $major_version " = " 13" ] || \
124
+ [ " $major_version " = " 14" ] || \
125
+ [ " $major_version " = " 15" ]; then
126
+ yes | bash <( curl -Lk https://releases.nixos.org/nix/nix-2.9.2/install) --darwin-use-unencrypted-nix-store-volume || sh <( curl -L https://nixos.org/nix/install) --daemon
132
127
#
133
128
# Older than Big Sur (Catalina, Mojave, High Siera, Siera, etc)
134
129
#
135
- elif [ " $major_version " -eq " 10" ]; then
130
+ elif [ " $major_version " = " 10" ]; then
136
131
# Catalina
137
132
if [ " $minor_version " = " 15" ]; then
138
- sh <( curl -Lk https://releases.nixos.org/nix/nix-2.3.7 /install) --darwin-use-unencrypted-nix-store-volume
133
+ sh <( curl -Lk https://releases.nixos.org/nix/nix-2.9.2 /install) --darwin-use-unencrypted-nix-store-volume
139
134
# Mojave, High Siera, Siera, and might work on even older versions (Yosemite, Mavericks)
140
135
else
141
136
# the single-user install seems to have fewer install issues
142
- curl -Lk https://releases.nixos.org/nix/nix-2.3.7 /install | sh -s
143
- # curl -Lk https://releases.nixos.org/nix/nix-2.3.7 /install | sh -s -- --daemon
137
+ curl -Lk https://releases.nixos.org/nix/nix-2.9.2 /install | sh -s
138
+ # curl -Lk https://releases.nixos.org/nix/nix-2.9.2 /install | sh -s -- --daemon
144
139
fi
145
140
else
146
141
echo ' We tried to get you MacOS version by running `sw_vers -productVersion`'
147
142
echo ' (which returns ' " $full_version " ' )'
148
143
echo " Either 1. that value is empty 2. You're on an insanely old version 3. You're on a version way way in the future from when this script was made"
149
144
fi
150
- # assuming Linux/POSIX if not on MacOS
151
- else
145
+ else # assuming Linux/POSIX if not on MacOS
152
146
# if curl doesnt exist, try to make it exist
153
- if [ -z " $( command -v " curl" ) " ]
154
- then
147
+ if [ -z " $( command -v " curl" ) " ]; then
155
148
# if apt-get exists
156
- if [ -n " $( command -v " apt-get" ) " ]
157
- then
149
+ if [ -n " $( command -v " apt-get" ) " ]; then
158
150
sudo apt-get update && sudo apt-get install curl
159
151
else
160
152
echo " it looks like you don't have curl, please install curl then re-run this script" 1>&2
161
- echo " alternatively, to get nix, manually run the commands inside https://releases.nixos.org/nix/nix-2.3.7 /install" 1>&2
153
+ echo " alternatively, to get nix, manually run the commands inside https://releases.nixos.org/nix/nix-2.9.2 /install" 1>&2
162
154
fi
163
155
fi
164
-
156
+
165
157
# if now curl exists
166
- if [ -n " $( command -v " curl" ) " ]
167
- then
158
+ if [ -n " $( command -v " curl" ) " ]; then
168
159
# check if systemd exists
169
- if pidof systemd
170
- then
160
+ if pidof systemd; then
171
161
# the single-user install seems to have fewer install issues
172
- curl -Lk https://releases.nixos.org/nix/nix-2.3.7 /install | sh -s
162
+ curl -Lk https://releases.nixos.org/nix/nix-2.9.2 /install | sh -s
173
163
# # multi-user install if systemd exists
174
- # curl -Lk https://releases.nixos.org/nix/nix-2.3.7 /install | sh -s -- --daemon
164
+ # curl -Lk https://releases.nixos.org/nix/nix-2.9.2 /install | sh -s -- --daemon
175
165
else
176
166
# single-user install if systemd does not exist
177
- curl -Lk https://releases.nixos.org/nix/nix-2.3.7 /install | sh -s
167
+ curl -Lk https://releases.nixos.org/nix/nix-2.9.2 /install | sh -s
178
168
fi
179
169
fi
180
- fi
170
+ fi
181
171
fi
182
172
fi
0 commit comments