Skip to content

Commit b9b9208

Browse files
bors[bot]Mic92
andauthored
Merge #46
46: handle error case better when facts return no results back r=Mic92 a=Mic92 Co-authored-by: Jörg Thalheim <joerg@thalheim.io>
2 parents 6188fdf + 4ea8c99 commit b9b9208

File tree

4 files changed

+54
-49
lines changed

4 files changed

+54
-49
lines changed

bors.toml

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
cut_body_after = "" # don't include text from the PR body in the merge commit message
22
status = [
3-
# garnix
4-
"Evaluate flake.nix",
5-
"package docs [x86_64-linux]",
6-
"check from-nixos [x86_64-linux]",
7-
"package default [x86_64-linux]",
8-
"check from-nixos-with-sudo [x86_64-linux]",
9-
"package nixos-remote [x86_64-linux]",
10-
"check treefmt [x86_64-linux]",
11-
"package treefmt [x86_64-linux]",
12-
# github actions
13-
"deploy"
3+
"Evaluate flake.nix",
4+
"check from-nixos [x86_64-linux]",
5+
"check from-nixos-with-sudo [x86_64-linux]",
6+
"check treefmt [x86_64-linux]",
7+
"deploy",
8+
"devShell default [x86_64-linux]",
9+
"package default [x86_64-linux]",
10+
"package docs [x86_64-linux]",
11+
"package nixos-remote [x86_64-linux]"
1412
]

flake.lock

Lines changed: 20 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
description = "A universal nixos installer, just needs ssh access to the target system";
33

44
inputs = {
5-
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
5+
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable-small";
66
flake-parts = { url = "github:hercules-ci/flake-parts"; inputs.nixpkgs-lib.follows = "nixpkgs"; };
77
disko = { url = "github:nix-community/disko/master"; inputs.nixpkgs.follows = "nixpkgs"; };
88
# used for testing

src/nixos-remote.sh

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ while [[ $# -gt 0 ]]; do
108108
;;
109109

110110
*)
111-
if [[ -z ${ssh_connection:-} ]]; then
111+
if [[ -z ${ssh_connection-} ]]; then
112112
ssh_connection="$1"
113113
else
114114
showUsage
@@ -144,24 +144,24 @@ nix_build() {
144144
"$@"
145145
}
146146

147-
if [[ -z ${ssh_connection:-} ]]; then
147+
if [[ -z ${ssh_connection-} ]]; then
148148
abort "ssh-host must be set"
149149
fi
150150

151151
# parse flake nixos-install style syntax, get the system attr
152-
if [[ -n ${flake:-} ]]; then
152+
if [[ -n ${flake-} ]]; then
153153
if [[ $flake =~ ^(.*)\#([^\#\"]*)$ ]]; then
154154
flake="${BASH_REMATCH[1]}"
155155
flakeAttr="${BASH_REMATCH[2]}"
156156
fi
157-
if [[ -z ${flakeAttr:-} ]]; then
157+
if [[ -z ${flakeAttr-} ]]; then
158158
echo "Please specify the name of the NixOS configuration to be installed, as a URI fragment in the flake-uri."
159159
echo 'For example, to use the output nixosConfigurations.foo from the flake.nix, append "#foo" to the flake-uri.'
160160
exit 1
161161
fi
162162
disko_script=$(nix_build "${flake}#nixosConfigurations.${flakeAttr}.config.system.build.disko")
163163
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
165165
if [[ ! -e ${disko_script} ]] || [[ ! -e ${nixos_system} ]]; then
166166
echo "${disko_script} and ${nixos_system} must be existing store-paths"
167167
exit 1
@@ -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,14 +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)
204-
205212
if [[ ${has_tar-n} == "n" ]]; then
206213
abort "no tar command found, but required to unpack kexec tarball"
207214
fi
@@ -264,7 +271,7 @@ if [[ ${stop_after_disko-n} == "y" ]]; then
264271
fi
265272

266273
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
268275
if [[ -d $extra_files ]]; then
269276
extra_files="$extra_files/"
270277
fi

0 commit comments

Comments
 (0)