From eee38aaa743a0416630e284c3e3799b6f9508696 Mon Sep 17 00:00:00 2001 From: DavHau Date: Thu, 29 May 2025 18:39:14 +0700 Subject: [PATCH 1/2] kexec: support other compression than gzip --- src/nixos-anywhere.sh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/nixos-anywhere.sh b/src/nixos-anywhere.sh index 9c0358be..c3f6848a 100755 --- a/src/nixos-anywhere.sh +++ b/src/nixos-anywhere.sh @@ -671,6 +671,18 @@ TMPDIR=/root/kexec setsid --wait ${maybeSudo} /root/kexec/kexec/run --kexec-extr local localUploadCommand=() local remoteUploadCommand=() + # 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 localUploadCommand=(cat "$kexecUrl") elif [[ $hasWget == "y" ]]; then @@ -686,14 +698,14 @@ TMPDIR=/root/kexec setsid --wait ${maybeSudo} /root/kexec/kexec/run --kexec-extr local remoteCommands if [[ ${#localUploadCommand[@]} -eq 0 ]]; then # Use remote command for download and execution - tarCommand="$(printf '%q ' "${remoteUploadCommand[@]}") | ${maybeSudo} tar -C /root/kexec -xvzf-" + tarCommand="$(printf '%q ' "${remoteUploadCommand[@]}") | ${maybeSudo} tar -C /root/kexec -xv ${tarDecomp}" remoteCommands=${remoteCommandTemplate//'%TAR_COMMAND%'/$tarCommand} runSsh sh -c "$(printf '%q' "$remoteCommands")" else # Use local command with pipe to remote - tarCommand="${maybeSudo} tar -C /root/kexec -xvzf-" + tarCommand="${maybeSudo} tar -C /root/kexec -xv ${tarDecomp}" remoteCommands=${remoteCommandTemplate//'%TAR_COMMAND%'/$tarCommand} "${localUploadCommand[@]}" | runSsh sh -c "$(printf '%q' "$remoteCommands")" From e29ae99c7f557397329a34e4d60b86267fce4482 Mon Sep 17 00:00:00 2001 From: DavHau Date: Thu, 29 May 2025 18:51:20 +0700 Subject: [PATCH 2/2] tests: rename kexec tarballs to allow compression heuristic --- tests/from-nixos-build-on-remote.nix | 2 +- tests/from-nixos-generate-config.nix | 4 ++-- tests/from-nixos-separated-phases.nix | 4 ++-- tests/from-nixos-with-sudo.nix | 2 +- tests/from-nixos.nix | 2 +- tests/modules/installer.nix | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/from-nixos-build-on-remote.nix b/tests/from-nixos-build-on-remote.nix index 0a013fe4..9d8704e0 100644 --- a/tests/from-nixos-build-on-remote.nix +++ b/tests/from-nixos-build-on-remote.nix @@ -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 """) diff --git a/tests/from-nixos-generate-config.nix b/tests/from-nixos-generate-config.nix index 686f0f9f..15cfb104 100644 --- a/tests/from-nixos-generate-config.nix +++ b/tests/from-nixos-generate-config.nix @@ -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 \ @@ -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 \ diff --git a/tests/from-nixos-separated-phases.nix b/tests/from-nixos-separated-phases.nix index 27633702..8e5b90fa 100644 --- a/tests/from-nixos-separated-phases.nix +++ b/tests/from-nixos-separated-phases.nix @@ -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 @@ -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 """) ''; } diff --git a/tests/from-nixos-with-sudo.nix b/tests/from-nixos-with-sudo.nix index aaf0465a..402b6e09 100644 --- a/tests/from-nixos-with-sudo.nix +++ b/tests/from-nixos-with-sudo.nix @@ -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) \ diff --git a/tests/from-nixos.nix b/tests/from-nixos.nix index c828adec..6b7e1994 100644 --- a/tests/from-nixos.nix +++ b/tests/from-nixos.nix @@ -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 \ diff --git a/tests/modules/installer.nix b/tests/modules/installer.nix index eaf5322d..325bdb10 100644 --- a/tests/modules/installer.nix +++ b/tests/modules/installer.nix @@ -9,6 +9,6 @@ environment.etc = { "nixos-anywhere/disko".source = inputs.system-to-install.config.system.build.diskoScriptNoDeps; "nixos-anywhere/system-to-install".source = inputs.system-to-install.config.system.build.toplevel; - "nixos-anywhere/kexec-installer".source = inputs.kexec-installer; + "nixos-anywhere/kexec-installer.tar.gz".source = inputs.kexec-installer; }; }