mirror of
https://github.com/nix-community/nixos-anywhere.git
synced 2024-09-11 16:45:28 +03:00
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>
This commit is contained in:
commit
b9b920844e
20
bors.toml
20
bors.toml
@ -1,14 +1,12 @@
|
||||
cut_body_after = "" # don't include text from the PR body in the merge commit message
|
||||
status = [
|
||||
# garnix
|
||||
"Evaluate flake.nix",
|
||||
"package docs [x86_64-linux]",
|
||||
"check from-nixos [x86_64-linux]",
|
||||
"package default [x86_64-linux]",
|
||||
"check from-nixos-with-sudo [x86_64-linux]",
|
||||
"package nixos-remote [x86_64-linux]",
|
||||
"check treefmt [x86_64-linux]",
|
||||
"package treefmt [x86_64-linux]",
|
||||
# github actions
|
||||
"deploy"
|
||||
"Evaluate flake.nix",
|
||||
"check from-nixos [x86_64-linux]",
|
||||
"check from-nixos-with-sudo [x86_64-linux]",
|
||||
"check treefmt [x86_64-linux]",
|
||||
"deploy",
|
||||
"devShell default [x86_64-linux]",
|
||||
"package default [x86_64-linux]",
|
||||
"package docs [x86_64-linux]",
|
||||
"package nixos-remote [x86_64-linux]"
|
||||
]
|
||||
|
40
flake.lock
40
flake.lock
@ -7,11 +7,11 @@
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1670529818,
|
||||
"narHash": "sha256-flPaFV2V4SBtGY+u5CYJzQWJutd1D6zSwomILcSgtCI=",
|
||||
"lastModified": 1674131019,
|
||||
"narHash": "sha256-NmbeqCEM9GwwlYPNmu4aWZX3nfBJuMvaJ7T7QzWd8MM=",
|
||||
"owner": "nix-community",
|
||||
"repo": "disko",
|
||||
"rev": "66add2cd9edab96f5e87477229772bf2b3ca513a",
|
||||
"rev": "e1eba38e8ea3ee6ca8ffef57668d4a37fff19ca4",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@ -43,16 +43,16 @@
|
||||
},
|
||||
"nixos-2211": {
|
||||
"locked": {
|
||||
"lastModified": 1659446231,
|
||||
"narHash": "sha256-hekabNdTdgR/iLsgce5TGWmfIDZ86qjPhxDg/8TlzhE=",
|
||||
"lastModified": 1674079783,
|
||||
"narHash": "sha256-RKenhBhPXBOE+iOD+2DfOU+QRZvMZjedkZCQiZmHwnk=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "eabc38219184cc3e04a974fe31857d8e0eac098d",
|
||||
"rev": "f664029d68acdffe8d86e98a295b2d8303369353",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "release-21.11",
|
||||
"ref": "release-22.11",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
@ -63,11 +63,11 @@
|
||||
"nixos-unstable": "nixos-unstable"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1671788592,
|
||||
"narHash": "sha256-MFcGltfuAicQ5FUHYiBzRjy4YMmEOcbFSVEY1bK1Oho=",
|
||||
"lastModified": 1674091005,
|
||||
"narHash": "sha256-HOdxpFfF2Nu/siZtVlXG0sO/R6AjAkjA07afzpnFqfY=",
|
||||
"owner": "nix-community",
|
||||
"repo": "nixos-images",
|
||||
"rev": "b14097667f2a9889083d6401ba468b046b2b52f1",
|
||||
"rev": "acbbb3494fdf4d7f8f8e8832beeab9c448563e9b",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@ -78,11 +78,11 @@
|
||||
},
|
||||
"nixos-unstable": {
|
||||
"locked": {
|
||||
"lastModified": 1671565324,
|
||||
"narHash": "sha256-FKnxM+07rV3HFNIOw3p1XaopZ3MkaxuHXNcZyYUJt2w=",
|
||||
"lastModified": 1673954326,
|
||||
"narHash": "sha256-oAKwsXTptcY6gRCBxJlZ+W1BrZHNr9a28+4fQMLuRu0=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "3c6d63d22ca8b57adc4120f7c1ea5262925c8c2d",
|
||||
"rev": "8fc3a1dcc98d3603221d4afd239e666eeedb6141",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@ -94,16 +94,16 @@
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1670559856,
|
||||
"narHash": "sha256-xUkgQRFqE6HIFQXs9SIXMZiXcLaH2415UR6w/FnsgcY=",
|
||||
"lastModified": 1674247172,
|
||||
"narHash": "sha256-6gbmukIy81hh95YS7xIFfHjhOCcwIuw37mEopJSsIzs=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "6bc6f77cb171a74001033d94f17f49043a9f1804",
|
||||
"rev": "f043916573c888930442d101ff4adc2e4cae3665",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nixos",
|
||||
"ref": "nixpkgs-unstable",
|
||||
"ref": "nixos-unstable-small",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
@ -119,11 +119,11 @@
|
||||
},
|
||||
"treefmt-nix": {
|
||||
"locked": {
|
||||
"lastModified": 1672931382,
|
||||
"narHash": "sha256-lgtc2Sct/xtvqkdzlJ4AL3Vesw0Wz/fxqNGOBFS7YXU=",
|
||||
"lastModified": 1674297056,
|
||||
"narHash": "sha256-IheUucTSpBsZ3JhAnrx2RWXf0Z5ekNGiW6ojct3FcZo=",
|
||||
"owner": "numtide",
|
||||
"repo": "treefmt-nix",
|
||||
"rev": "6717065d6a432bc3f5b827007ad959e6032d5856",
|
||||
"rev": "c117283f7482b99a89de0d6ae4b77318ad283294",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -2,7 +2,7 @@
|
||||
description = "A universal nixos installer, just needs ssh access to the target system";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
|
||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable-small";
|
||||
flake-parts = { url = "github:hercules-ci/flake-parts"; inputs.nixpkgs-lib.follows = "nixpkgs"; };
|
||||
disko = { url = "github:nix-community/disko/master"; inputs.nixpkgs.follows = "nixpkgs"; };
|
||||
# used for testing
|
||||
|
@ -108,7 +108,7 @@ while [[ $# -gt 0 ]]; do
|
||||
;;
|
||||
|
||||
*)
|
||||
if [[ -z ${ssh_connection:-} ]]; then
|
||||
if [[ -z ${ssh_connection-} ]]; then
|
||||
ssh_connection="$1"
|
||||
else
|
||||
showUsage
|
||||
@ -144,24 +144,24 @@ nix_build() {
|
||||
"$@"
|
||||
}
|
||||
|
||||
if [[ -z ${ssh_connection:-} ]]; then
|
||||
if [[ -z ${ssh_connection-} ]]; then
|
||||
abort "ssh-host must be set"
|
||||
fi
|
||||
|
||||
# parse flake nixos-install style syntax, get the system attr
|
||||
if [[ -n ${flake:-} ]]; then
|
||||
if [[ -n ${flake-} ]]; then
|
||||
if [[ $flake =~ ^(.*)\#([^\#\"]*)$ ]]; then
|
||||
flake="${BASH_REMATCH[1]}"
|
||||
flakeAttr="${BASH_REMATCH[2]}"
|
||||
fi
|
||||
if [[ -z ${flakeAttr:-} ]]; then
|
||||
if [[ -z ${flakeAttr-} ]]; then
|
||||
echo "Please specify the name of the NixOS configuration to be installed, as a URI fragment in the flake-uri."
|
||||
echo 'For example, to use the output nixosConfigurations.foo from the flake.nix, append "#foo" to the flake-uri.'
|
||||
exit 1
|
||||
fi
|
||||
disko_script=$(nix_build "${flake}#nixosConfigurations.${flakeAttr}.config.system.build.disko")
|
||||
nixos_system=$(nix_build "${flake}#nixosConfigurations.${flakeAttr}.config.system.build.toplevel")
|
||||
elif [[ -n ${disko_script:-} ]] && [[ -n ${nixos_system:-} ]]; then
|
||||
elif [[ -n ${disko_script-} ]] && [[ -n ${nixos_system-} ]]; then
|
||||
if [[ ! -e ${disko_script} ]] || [[ ! -e ${nixos_system} ]]; then
|
||||
echo "${disko_script} and ${nixos_system} must be existing store-paths"
|
||||
exit 1
|
||||
@ -171,12 +171,10 @@ else
|
||||
abort "flake must be set"
|
||||
fi
|
||||
|
||||
# wait for machine to become reachable (possibly forever)
|
||||
# TODO we probably need an architecture detection here
|
||||
# TODO if we have specified a user here but we are already booted into the
|
||||
# installer, than the user might not work anymore
|
||||
until facts=$(
|
||||
ssh_ -o ConnectTimeout=10 -- <<SSH
|
||||
import_facts() {
|
||||
local facts filtered_facts
|
||||
if ! facts=$(
|
||||
ssh_ -o ConnectTimeout=10 -- <<SSH
|
||||
set -efu ${enable_debug}
|
||||
has(){
|
||||
command -v "\$1" >/dev/null && echo "y" || echo "n"
|
||||
@ -194,14 +192,23 @@ has_wget=\$(has wget)
|
||||
has_curl=\$(has curl)
|
||||
FACTS
|
||||
SSH
|
||||
); do
|
||||
); then
|
||||
return 1
|
||||
fi
|
||||
filtered_facts=$(echo "$facts" | grep -E '^(has|is)_[a-z0-9_]+=\S+')
|
||||
if [[ -z $filtered_facts ]]; then
|
||||
abort "Retrieving host facts via ssh failed. Check with --debug for the root cause, unless you have done so already"
|
||||
fi
|
||||
# make facts available in script
|
||||
# shellcheck disable=SC2046
|
||||
export $(echo "$filtered_facts" | xargs)
|
||||
}
|
||||
|
||||
# wait for machine to become reachable (possibly forever)
|
||||
until import_facts; do
|
||||
sleep 5
|
||||
done
|
||||
|
||||
# make facts available in script
|
||||
# shellcheck disable=SC2046
|
||||
export $(echo "$facts" | grep -E '^(has|is)_[a-z0-9_]+=\S+' | xargs)
|
||||
|
||||
if [[ ${has_tar-n} == "n" ]]; then
|
||||
abort "no tar command found, but required to unpack kexec tarball"
|
||||
fi
|
||||
@ -264,7 +271,7 @@ if [[ ${stop_after_disko-n} == "y" ]]; then
|
||||
fi
|
||||
|
||||
nix_copy --to "ssh://$ssh_connection?remote-store=local?root=/mnt" "$nixos_system"
|
||||
if [[ -n ${extra_files:-} ]]; then
|
||||
if [[ -n ${extra_files-} ]]; then
|
||||
if [[ -d $extra_files ]]; then
|
||||
extra_files="$extra_files/"
|
||||
fi
|
||||
|
Loading…
Reference in New Issue
Block a user