Skip to content

kexec: support other compression than gzip #523

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions src/nixos-anywhere.sh
Original file line number Diff line number Diff line change
Expand Up @@ -630,18 +630,30 @@ SSH
kexecUrl=${kexecUrl/"github.com"/"gh-v6.com"}
fi

# gnu tar cannot automatically detect the compression when decompressing via stdin
tarDecomp=""
if [[ ${kexecUrl} =~ \.tar\.gz$ ]]; then
tarDecomp="--gzip"
elif [[ ${kexecUrl} =~ \.tar\.xz$ ]]; then
tarDecomp="--xz"
elif [[ ${kexecUrl} =~ \.tar\.zstd$ ]]; then
tarDecomp="--zstd"
elif [[ ${kexecUrl} =~ \.tar$ ]]; then
tarDecomp=""
fi

if [[ -f $kexecUrl ]]; then
runSsh "${maybeSudo} tar -C /root/kexec -xvzf-" <"$kexecUrl"
runSsh "${maybeSudo} tar -C /root/kexec -xv ${tarDecomp}" <"$kexecUrl"
elif [[ ${hasCurl} == "y" ]]; then
runSsh "curl --fail -Ss -L '${kexecUrl}' | ${maybeSudo} tar -C /root/kexec -xvzf-"
runSsh "curl --fail -Ss -L '${kexecUrl}' | ${maybeSudo} tar -C /root/kexec -xv ${tarDecomp}"
elif [[ ${hasWget} == "y" ]]; then
runSsh "wget '${kexecUrl}' -O- | ${maybeSudo} tar -C /root/kexec -xvzf-"
runSsh "wget '${kexecUrl}' -O- | ${maybeSudo} tar -C /root/kexec -xv ${tarDecomp}"
else
curl --fail -Ss -L "${kexecUrl}" | runSsh "${maybeSudo} tar -C /root/kexec -xvzf-"
curl --fail -Ss -L "${kexecUrl}" | runSsh "${maybeSudo} tar -C /root/kexec -xv ${tarDecomp}"
fi

runSsh <<SSH
TMPDIR=/root/kexec setsid ${maybeSudo} /root/kexec/kexec/run --kexec-extra-flags "${kexecExtraFlags}"
TMPDIR=/root/kexec setsid ${maybeSudo} /root/kexec/kexec/run --kexec-extra-flags "${kexecExtraFlags}"
SSH

# use the default SSH port to connect at this point
Expand Down
2 changes: 1 addition & 1 deletion tests/from-nixos-build-on-remote.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
-i /root/.ssh/install_key \
--debug \
--build-on-remote \
--kexec /etc/nixos-anywhere/kexec-installer \
--kexec /etc/nixos-anywhere/kexec-installer.tar.gz \
--store-paths /etc/nixos-anywhere/disko /etc/nixos-anywhere/system-to-install \
root@installed >&2
""")
Expand Down
4 changes: 2 additions & 2 deletions tests/from-nixos-generate-config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
nixos-anywhere \
-i /root/.ssh/install_key \
--debug \
--kexec /etc/nixos-anywhere/kexec-installer \
--kexec /etc/nixos-anywhere/kexec-installer.tar.gz \
--disk-encryption-keys /tmp/disk-1.key /tmp/disk-1.key \
--disk-encryption-keys /tmp/disk-2.key <(echo another-secret) \
--phases kexec,disko \
Expand All @@ -47,7 +47,7 @@
nixos-anywhere \
-i /root/.ssh/install_key \
--debug \
--kexec /etc/nixos-anywhere/kexec-installer \
--kexec /etc/nixos-anywhere/kexec-installer.tar.gz \
--disk-encryption-keys /tmp/disk-1.key /tmp/disk-1.key \
--disk-encryption-keys /tmp/disk-2.key <(echo another-secret) \
--phases kexec,disko \
Expand Down
4 changes: 2 additions & 2 deletions tests/from-nixos-separated-phases.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
nixos-anywhere \
-i /root/.ssh/install_key \
--debug \
--kexec /etc/nixos-anywhere/kexec-installer \
--kexec /etc/nixos-anywhere/kexec-installer.tar.gz \
--phases kexec \
--store-paths /etc/nixos-anywhere/disko /etc/nixos-anywhere/system-to-install \
nixos@installed >&2
Expand All @@ -46,7 +46,7 @@
--debug \
--phases install \
--store-paths /etc/nixos-anywhere/disko /etc/nixos-anywhere/system-to-install \
root@installed >&2
root@installed >&2
""")
'';
}
2 changes: 1 addition & 1 deletion tests/from-nixos-with-sudo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
nixos-anywhere \
-i /root/.ssh/install_key \
--debug \
--kexec /etc/nixos-anywhere/kexec-installer \
--kexec /etc/nixos-anywhere/kexec-installer.tar.gz \
--phases kexec,disko \
--disk-encryption-keys /tmp/disk-1.key /tmp/disk-1.key \
--disk-encryption-keys /tmp/disk-2.key <(echo another-secret) \
Expand Down
2 changes: 1 addition & 1 deletion tests/from-nixos.nix
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
nixos-anywhere \
-i /root/.ssh/install_key \
--debug \
--kexec /etc/nixos-anywhere/kexec-installer \
--kexec /etc/nixos-anywhere/kexec-installer.tar.gz \
--extra-files /tmp/extra-files \
--store-paths /etc/nixos-anywhere/disko /etc/nixos-anywhere/system-to-install \
--chown /home/user 1000:100 \
Expand Down
2 changes: 1 addition & 1 deletion tests/modules/installer.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ in
environment.etc = {
"nixos-anywhere/disko".source = system-to-install.config.system.build.diskoScriptNoDeps;
"nixos-anywhere/system-to-install".source = system-to-install.config.system.build.toplevel;
"nixos-anywhere/kexec-installer".source = kexec-installer;
"nixos-anywhere/kexec-installer.tar.gz".source = kexec-installer;
};
}
Loading