From b6abac7b0e2405b1ee4da44b6130c4571b2ed8bb Mon Sep 17 00:00:00 2001 From: c_14 Date: Mon, 15 Jan 2024 11:21:06 +0100 Subject: [PATCH] fix container detection When systemd-detect-virt exists and we aren't in a container, is_container contains "y none none" instead of none. 1. has outputs y/n to stdout which we need to remove 2. has always returns truthy, we need to check it's string value not the exit value 3. systemd-detect-virt --container returns non-zero when we aren't in a container, use if then else instead of && || --- src/nixos-anywhere.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nixos-anywhere.sh b/src/nixos-anywhere.sh index 1456615..00fb57e 100755 --- a/src/nixos-anywhere.sh +++ b/src/nixos-anywhere.sh @@ -314,7 +314,7 @@ is_arch=\$(uname -m) 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=\$(has systemd-detect-virt && systemd-detect-virt --container || echo "none") +is_container=\$(if [[ "\$(has systemd-detect-virt)" == "y" ]]; then systemd-detect-virt --container; else echo "none"; fi) has_tar=\$(has tar) has_sudo=\$(has sudo) has_wget=\$(has wget)