Skip to content
Merged
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
16 changes: 14 additions & 2 deletions src/nixos-anywhere.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be .zst

tarDecomp="--zstd"
elif [[ ${kexecUrl} =~ \.tar$ ]]; then
tarDecomp=""
fi

if [[ -f $kexecUrl ]]; then
localUploadCommand=(cat "$kexecUrl")
elif [[ $hasWget == "y" ]]; then
Expand All @@ -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")"
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 @@ -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;
};
}
Loading