@@ -42,63 +42,62 @@ declare -A disk_encryption_keys
42
42
43
43
while [[ $# -gt 0 ]]; do
44
44
case " $1 " in
45
- -f | --flake)
46
- flake=$2
47
- shift
48
- ;;
49
- -L | --print-build-logs)
50
- print_build_logs=y
51
- ;;
52
- -s | --store-paths)
53
- disko_script=$( readlink -f " $2 " )
54
- nixos_system=$( readlink -f " $3 " )
55
- shift
56
- shift
57
- ;;
58
- --help)
45
+ -f | --flake)
46
+ flake=$2
47
+ shift
48
+ ;;
49
+ -L | --print-build-logs)
50
+ print_build_logs=y
51
+ ;;
52
+ -s | --store-paths)
53
+ disko_script=$( readlink -f " $2 " )
54
+ nixos_system=$( readlink -f " $3 " )
55
+ shift
56
+ shift
57
+ ;;
58
+ --help)
59
+ showUsage
60
+ exit 0
61
+ ;;
62
+ --kexec)
63
+ kexec_url=$2
64
+ shift
65
+ ;;
66
+ --no-ssh-copy-id)
67
+ no_ssh_copy=y
68
+ ;;
69
+ --debug)
70
+ enable_debug=" -x"
71
+ print_build_logs=y
72
+ set -x
73
+ ;;
74
+ --extra-files)
75
+ extra_files=$2
76
+ shift
77
+ ;;
78
+ --disk-encryption-keys)
79
+ disk_encryption_keys[" $2 " ]=" $3 "
80
+ shift
81
+ shift
82
+ ;;
83
+ --stop-after-disko)
84
+ stop_after_disko=y
85
+ ;;
86
+ --no-reboot)
87
+ maybereboot=" "
88
+ ;;
89
+ * )
90
+ if [[ -z ${ssh_connection:- } ]]; then
91
+ ssh_connection=" $1 "
92
+ else
59
93
showUsage
60
- exit 0
61
- ;;
62
- --kexec)
63
- kexec_url=$2
64
- shift
65
- ;;
66
- --no-ssh-copy-id)
67
- no_ssh_copy=y
68
- ;;
69
- --debug)
70
- enable_debug=" -x"
71
- print_build_logs=y
72
- set -x
73
- ;;
74
- --extra-files)
75
- extra_files=$2
76
- shift
77
- ;;
78
- --disk-encryption-keys)
79
- disk_encryption_keys[" $2 " ]=" $3 "
80
- shift
81
- shift
82
- ;;
83
- --stop-after-disko)
84
- stop_after_disko=y
85
- ;;
86
- --no-reboot)
87
- maybereboot=" "
88
- ;;
89
- * )
90
- if [[ -z ${ssh_connection:- } ]]; then
91
- ssh_connection=" $1 "
92
- else
93
- showUsage
94
- exit 1
95
- fi
96
- ;;
94
+ exit 1
95
+ fi
96
+ ;;
97
97
esac
98
98
shift
99
99
done
100
100
101
-
102
101
# ssh wrapper
103
102
timeout_ssh_ () {
104
103
timeout 10 ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no " $ssh_connection " " $@ "
@@ -134,20 +133,20 @@ if [[ -z ${ssh_connection:-} ]]; then
134
133
fi
135
134
136
135
# parse flake nixos-install style syntax, get the system attr
137
- if [[ -n " ${flake:- } " ]]; then
136
+ if [[ -n ${flake:- } ]]; then
138
137
if [[ $flake =~ ^(.* )\# ([^\#\" ]* )$ ]]; then
139
- flake=" ${BASH_REMATCH[1]} "
140
- flakeAttr=" ${BASH_REMATCH[2]} "
138
+ flake=" ${BASH_REMATCH[1]} "
139
+ flakeAttr=" ${BASH_REMATCH[2]} "
141
140
fi
142
- if [[ -z " ${flakeAttr:- } " ]]; then
141
+ if [[ -z ${flakeAttr:- } ]]; then
143
142
echo " Please specify the name of the NixOS configuration to be installed, as a URI fragment in the flake-uri."
144
- echo " For example, to use the output nixosConfigurations.foo from the flake.nix, append \ " #foo\ " to the flake-uri."
143
+ echo ' For example, to use the output nixosConfigurations.foo from the flake.nix, append "#foo" to the flake-uri.'
145
144
exit 1
146
145
fi
147
146
disko_script=$( nix_build " ${flake} #nixosConfigurations.${flakeAttr} .config.system.build.disko" )
148
147
nixos_system=$( nix_build " ${flake} #nixosConfigurations.${flakeAttr} .config.system.build.toplevel" )
149
- elif [[ -n " ${disko_script:- } " ]] && [[ -n " ${nixos_system:- } " ]]; then
150
- if [[ ! -e " ${disko_script} " ]] || [[ ! -e " ${nixos_system} " ]]; then
148
+ elif [[ -n ${disko_script:- } ]] && [[ -n ${nixos_system:- } ]]; then
149
+ if [[ ! -e ${disko_script} ]] || [[ ! -e ${nixos_system} ]]; then
151
150
echo " ${disko_script} and ${nixos_system} must be existing store-paths"
152
151
exit 1
153
152
fi
160
159
# TODO we probably need an architecture detection here
161
160
# TODO if we have specified a user here but we are already booted into the
162
161
# installer, than the user might not work anymore
163
- until facts=$( ssh_ -o ConnectTimeout=10 -- << SSH
162
+ until facts=$(
163
+ ssh_ -o ConnectTimeout=10 -- << SSH
164
164
set -efu ${enable_debug}
165
165
has(){
166
166
command -v tar >/dev/null && echo "y" || echo "n"
@@ -198,14 +198,14 @@ if [[ ${is_kexec-n} != "y" ]] && [[ ${no_ssh_copy-n} != "y" ]]; then
198
198
fi
199
199
200
200
if [[ ${is_kexec-n} == " n" ]]; then
201
- ssh_ << SSH
201
+ ssh_ << SSH
202
202
set -efu ${enable_debug}
203
203
"${maybesudo} " rm -rf /root/kexec
204
204
"${maybesudo} " mkdir -p /root/kexec
205
205
SSH
206
206
207
- if [[ -f " $kexec_url " ]]; then
208
- ssh_ " ${maybesudo} tar -C /root/kexec -xvzf-" < " $kexec_url "
207
+ if [[ -f $kexec_url ]]; then
208
+ ssh_ " ${maybesudo} tar -C /root/kexec -xvzf-" < " $kexec_url "
209
209
elif [[ ${has_curl-n} == " y" ]]; then
210
210
ssh_ " curl --fail -Ss -L '${kexec_url} ' | ${maybesudo} tar -C /root/kexec -xvzf-"
211
211
elif [[ ${has_wget-n} == " y" ]]; then
214
214
curl --fail -Ss -L " ${kexec_url} " | ssh_ " ${maybesudo} tar -C /root/kexec -xvzf-"
215
215
fi
216
216
217
- ssh_ << SSH
217
+ ssh_ << SSH
218
218
TMPDIR=/root/kexec setsid ${maybesudo} /root/kexec/kexec/run
219
219
SSH
220
220
227
227
# watiting for machine to become available again
228
228
until ssh_ -o ConnectTimeout=10 -- exit 0; do sleep 5; done
229
229
fi
230
- for path in " ${! disk_encryption_keys[@]} "
231
- do
230
+ for path in " ${! disk_encryption_keys[@]} " ; do
232
231
echo " Uploading ${disk_encryption_keys[$path]} to $path "
233
- ssh_ " umask 077; cat > $path " < " ${disk_encryption_keys[$path]} "
232
+ ssh_ " umask 077; cat > $path " < " ${disk_encryption_keys[$path]} "
234
233
done
235
234
236
235
nix_copy --to " ssh://$ssh_connection " " $disko_script "
242
241
243
242
nix_copy --to " ssh://$ssh_connection ?remote-store=local?root=/mnt" " $nixos_system "
244
243
if [[ -n ${extra_files:- } ]]; then
245
- if [[ -d " $extra_files " ]]; then
244
+ if [[ -d $extra_files ]]; then
246
245
extra_files=" $extra_files /"
247
246
fi
248
247
rsync -vrlF -e " ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" " $extra_files " " ${ssh_connection} :/mnt/"
0 commit comments