@@ -108,7 +108,7 @@ while [[ $# -gt 0 ]]; do
108
108
;;
109
109
110
110
* )
111
- if [[ -z ${ssh_connection: - } ]]; then
111
+ if [[ -z ${ssh_connection-} ]]; then
112
112
ssh_connection=" $1 "
113
113
else
114
114
showUsage
@@ -144,24 +144,24 @@ nix_build() {
144
144
" $@ "
145
145
}
146
146
147
- if [[ -z ${ssh_connection: - } ]]; then
147
+ if [[ -z ${ssh_connection-} ]]; then
148
148
abort " ssh-host must be set"
149
149
fi
150
150
151
151
# parse flake nixos-install style syntax, get the system attr
152
- if [[ -n ${flake: - } ]]; then
152
+ if [[ -n ${flake-} ]]; then
153
153
if [[ $flake =~ ^(.* )\# ([^\#\" ]* )$ ]]; then
154
154
flake=" ${BASH_REMATCH[1]} "
155
155
flakeAttr=" ${BASH_REMATCH[2]} "
156
156
fi
157
- if [[ -z ${flakeAttr: - } ]]; then
157
+ if [[ -z ${flakeAttr-} ]]; then
158
158
echo " Please specify the name of the NixOS configuration to be installed, as a URI fragment in the flake-uri."
159
159
echo ' For example, to use the output nixosConfigurations.foo from the flake.nix, append "#foo" to the flake-uri.'
160
160
exit 1
161
161
fi
162
162
disko_script=$( nix_build " ${flake} #nixosConfigurations.${flakeAttr} .config.system.build.disko" )
163
163
nixos_system=$( nix_build " ${flake} #nixosConfigurations.${flakeAttr} .config.system.build.toplevel" )
164
- elif [[ -n ${disko_script: - } ]] && [[ -n ${nixos_system: - } ]]; then
164
+ elif [[ -n ${disko_script-} ]] && [[ -n ${nixos_system-} ]]; then
165
165
if [[ ! -e ${disko_script} ]] || [[ ! -e ${nixos_system} ]]; then
166
166
echo " ${disko_script} and ${nixos_system} must be existing store-paths"
167
167
exit 1
@@ -171,12 +171,10 @@ else
171
171
abort " flake must be set"
172
172
fi
173
173
174
- # wait for machine to become reachable (possibly forever)
175
- # TODO we probably need an architecture detection here
176
- # TODO if we have specified a user here but we are already booted into the
177
- # installer, than the user might not work anymore
178
- until facts=$(
179
- ssh_ -o ConnectTimeout=10 -- << SSH
174
+ import_facts () {
175
+ local facts filtered_facts
176
+ if ! facts=$(
177
+ ssh_ -o ConnectTimeout=10 -- << SSH
180
178
set -efu ${enable_debug}
181
179
has(){
182
180
command -v "\$ 1" >/dev/null && echo "y" || echo "n"
@@ -194,14 +192,23 @@ has_wget=\$(has wget)
194
192
has_curl=\$ (has curl)
195
193
FACTS
196
194
SSH
197
- ) ; do
195
+ ) ; then
196
+ return 1
197
+ fi
198
+ filtered_facts=$( echo " $facts " | grep -E ' ^(has|is)_[a-z0-9_]+=\S+' )
199
+ if [[ -z $filtered_facts ]]; then
200
+ abort " Retrieving host facts via ssh failed. Check with --debug for the root cause, unless you have done so already"
201
+ fi
202
+ # make facts available in script
203
+ # shellcheck disable=SC2046
204
+ export $( echo " $filtered_facts " | xargs)
205
+ }
206
+
207
+ # wait for machine to become reachable (possibly forever)
208
+ until import_facts; do
198
209
sleep 5
199
210
done
200
211
201
- # make facts available in script
202
- # shellcheck disable=SC2046
203
- export $( echo " $facts " | grep -E ' ^(has|is)_[a-z0-9_]+=\S+' | xargs)
204
-
205
212
if [[ ${has_tar-n} == " n" ]]; then
206
213
abort " no tar command found, but required to unpack kexec tarball"
207
214
fi
@@ -264,7 +271,7 @@ if [[ ${stop_after_disko-n} == "y" ]]; then
264
271
fi
265
272
266
273
nix_copy --to " ssh://$ssh_connection ?remote-store=local?root=/mnt" " $nixos_system "
267
- if [[ -n ${extra_files: - } ]]; then
274
+ if [[ -n ${extra_files-} ]]; then
268
275
if [[ -d $extra_files ]]; then
269
276
extra_files=" $extra_files /"
270
277
fi
0 commit comments