Skip to content

Commit 73b80b8

Browse files
authored
Merge pull request #523 from DavHau/dave
kexec: support other compression than gzip
2 parents 94c3849 + e29ae99 commit 73b80b8

File tree

7 files changed

+22
-10
lines changed

7 files changed

+22
-10
lines changed

src/nixos-anywhere.sh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,18 @@ TMPDIR=/root/kexec setsid --wait ${maybeSudo} /root/kexec/kexec/run --kexec-extr
671671
local localUploadCommand=()
672672
local remoteUploadCommand=()
673673
674+
# gnu tar cannot automatically detect the compression when decompressing via stdin
675+
tarDecomp=""
676+
if [[ ${kexecUrl} =~ \.tar\.gz$ ]]; then
677+
tarDecomp="--gzip"
678+
elif [[ ${kexecUrl} =~ \.tar\.xz$ ]]; then
679+
tarDecomp="--xz"
680+
elif [[ ${kexecUrl} =~ \.tar\.zstd$ ]]; then
681+
tarDecomp="--zstd"
682+
elif [[ ${kexecUrl} =~ \.tar$ ]]; then
683+
tarDecomp=""
684+
fi
685+
674686
if [[ -f $kexecUrl ]]; then
675687
localUploadCommand=(cat "$kexecUrl")
676688
elif [[ $hasWget == "y" ]]; then
@@ -686,14 +698,14 @@ TMPDIR=/root/kexec setsid --wait ${maybeSudo} /root/kexec/kexec/run --kexec-extr
686698
local remoteCommands
687699
if [[ ${#localUploadCommand[@]} -eq 0 ]]; then
688700
# Use remote command for download and execution
689-
tarCommand="$(printf '%q ' "${remoteUploadCommand[@]}") | ${maybeSudo} tar -C /root/kexec -xvzf-"
701+
tarCommand="$(printf '%q ' "${remoteUploadCommand[@]}") | ${maybeSudo} tar -C /root/kexec -xv ${tarDecomp}"
690702
691703
remoteCommands=${remoteCommandTemplate//'%TAR_COMMAND%'/$tarCommand}
692704
693705
runSsh sh -c "$(printf '%q' "$remoteCommands")"
694706
else
695707
# Use local command with pipe to remote
696-
tarCommand="${maybeSudo} tar -C /root/kexec -xvzf-"
708+
tarCommand="${maybeSudo} tar -C /root/kexec -xv ${tarDecomp}"
697709
remoteCommands=${remoteCommandTemplate//'%TAR_COMMAND%'/$tarCommand}
698710
699711
"${localUploadCommand[@]}" | runSsh sh -c "$(printf '%q' "$remoteCommands")"

tests/from-nixos-build-on-remote.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
-i /root/.ssh/install_key \
3939
--debug \
4040
--build-on-remote \
41-
--kexec /etc/nixos-anywhere/kexec-installer \
41+
--kexec /etc/nixos-anywhere/kexec-installer.tar.gz \
4242
--store-paths /etc/nixos-anywhere/disko /etc/nixos-anywhere/system-to-install \
4343
root@installed >&2
4444
""")

tests/from-nixos-generate-config.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
nixos-anywhere \
2323
-i /root/.ssh/install_key \
2424
--debug \
25-
--kexec /etc/nixos-anywhere/kexec-installer \
25+
--kexec /etc/nixos-anywhere/kexec-installer.tar.gz \
2626
--disk-encryption-keys /tmp/disk-1.key /tmp/disk-1.key \
2727
--disk-encryption-keys /tmp/disk-2.key <(echo another-secret) \
2828
--phases kexec,disko \
@@ -47,7 +47,7 @@
4747
nixos-anywhere \
4848
-i /root/.ssh/install_key \
4949
--debug \
50-
--kexec /etc/nixos-anywhere/kexec-installer \
50+
--kexec /etc/nixos-anywhere/kexec-installer.tar.gz \
5151
--disk-encryption-keys /tmp/disk-1.key /tmp/disk-1.key \
5252
--disk-encryption-keys /tmp/disk-2.key <(echo another-secret) \
5353
--phases kexec,disko \

tests/from-nixos-separated-phases.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
nixos-anywhere \
2424
-i /root/.ssh/install_key \
2525
--debug \
26-
--kexec /etc/nixos-anywhere/kexec-installer \
26+
--kexec /etc/nixos-anywhere/kexec-installer.tar.gz \
2727
--phases kexec \
2828
--store-paths /etc/nixos-anywhere/disko /etc/nixos-anywhere/system-to-install \
2929
nixos@installed >&2
@@ -46,7 +46,7 @@
4646
--debug \
4747
--phases install \
4848
--store-paths /etc/nixos-anywhere/disko /etc/nixos-anywhere/system-to-install \
49-
root@installed >&2
49+
root@installed >&2
5050
""")
5151
'';
5252
}

tests/from-nixos-with-sudo.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
nixos-anywhere \
2323
-i /root/.ssh/install_key \
2424
--debug \
25-
--kexec /etc/nixos-anywhere/kexec-installer \
25+
--kexec /etc/nixos-anywhere/kexec-installer.tar.gz \
2626
--phases kexec,disko \
2727
--disk-encryption-keys /tmp/disk-1.key /tmp/disk-1.key \
2828
--disk-encryption-keys /tmp/disk-2.key <(echo another-secret) \

tests/from-nixos.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
nixos-anywhere \
4848
-i /root/.ssh/install_key \
4949
--debug \
50-
--kexec /etc/nixos-anywhere/kexec-installer \
50+
--kexec /etc/nixos-anywhere/kexec-installer.tar.gz \
5151
--extra-files /tmp/extra-files \
5252
--store-paths /etc/nixos-anywhere/disko /etc/nixos-anywhere/system-to-install \
5353
--chown /home/user 1000:100 \

tests/modules/installer.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
environment.etc = {
1010
"nixos-anywhere/disko".source = inputs.system-to-install.config.system.build.diskoScriptNoDeps;
1111
"nixos-anywhere/system-to-install".source = inputs.system-to-install.config.system.build.toplevel;
12-
"nixos-anywhere/kexec-installer".source = inputs.kexec-installer;
12+
"nixos-anywhere/kexec-installer.tar.gz".source = inputs.kexec-installer;
1313
};
1414
}

0 commit comments

Comments
 (0)