Skip to content

Commit 92e0ef6

Browse files
committed
handle error case better when facts return no results back
1 parent 22d454d commit 92e0ef6

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

src/nixos-remote.sh

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,10 @@ else
171171
abort "flake must be set"
172172
fi
173173

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
180178
set -efu ${enable_debug}
181179
has(){
182180
command -v "\$1" >/dev/null && echo "y" || echo "n"
@@ -194,13 +192,23 @@ has_wget=\$(has wget)
194192
has_curl=\$(has curl)
195193
FACTS
196194
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
198209
sleep 5
199210
done
200211

201-
# make facts available in script
202-
# shellcheck disable=SC2046
203-
export $(echo "$facts" | grep -E '^(has|is)_[a-z0-9_]+=\S+' | xargs)
204212

205213
if [[ ${has_tar-n} == "n" ]]; then
206214
abort "no tar command found, but required to unpack kexec tarball"

0 commit comments

Comments
 (0)