Skip to content

Commit

Permalink
Detect IPv6 automatically, Rewrite kexec url
Browse files Browse the repository at this point in the history
This uses ip r g 1.1.1.1 to test if there's any route to an IPv4
internet host

If that fails and the url is a github.com one it will change github.com
to gh-v6.com,
as specified in the documentation

This saves the user from an extra manual step and makes nixos-anywhere
better

Co-authored-by: Jörg Thalheim <[email protected]>
  • Loading branch information
2 people authored and mergify[bot] committed Apr 30, 2024
1 parent 3170c45 commit 313ac87
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/get-facts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ is_kexec=$(if test -f /etc/is_kexec; then echo "y"; else echo "n"; fi)
is_nixos=$is_nixos
is_installer=$(if [ "$is_nixos" = "y" ] && grep -q VARIANT_ID=installer /etc/os-release; then echo "y"; else echo "n"; fi)
is_container=$(if [ "$(has systemd-detect-virt)" = "y" ]; then systemd-detect-virt --container; else echo "none"; fi)
has_ipv6_only=$(if [[ "$(has ip)" == "n" ]] || ip r g 1 >/dev/null 2>/dev/null || ! ip -6 r g :: >/dev/null 2>/dev/null; then echo "n"; else echo "y"; fi)
has_tar=$(has tar)
has_sudo=$(has sudo)
has_doas=$(has doas)
Expand Down
7 changes: 6 additions & 1 deletion src/nixos-anywhere.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Options:
* -L, --print-build-logs
print full build logs
* --env-password
set a password used by ssh-copy-id, the password should be set by
set a password used by ssh-copy-id, the password should be set by
the environment variable SSH_PASS
* -s, --store-paths <disko-script> <nixos-system>
set the store paths to the disko-script and nixos-system directly
Expand Down Expand Up @@ -379,6 +379,11 @@ $maybe_sudo rm -rf /root/kexec
$maybe_sudo mkdir -p /root/kexec
SSH

# no way to reach global ipv4 destinations, use gh-v6.com automatically if github url
if [[ ${has_ipv6_only-n} == "y" ]] && [[ $kexec_url == "https://github.com/"* ]]; then
kexec_url=${kexec_url/"github.com"/"gh-v6.com"}
fi

if [[ -f $kexec_url ]]; then
ssh_ "${maybe_sudo} tar -C /root/kexec -xvzf-" <"$kexec_url"
elif [[ ${has_curl-n} == "y" ]]; then
Expand Down

0 comments on commit 313ac87

Please sign in to comment.