From e6340426c1d14808c5e24e03b8d5ce5481c4b37a Mon Sep 17 00:00:00 2001 From: Erik Arvstedt Date: Sun, 18 Oct 2020 13:41:56 +0200 Subject: [PATCH] deploy-container.sh: fix sudo The 'echo sudo' approach used previously failed when PATH or NIX_PATH contains spaces. Exec the script with sudo instead. --- examples/deploy-container.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/deploy-container.sh b/examples/deploy-container.sh index 17c3496..c672fd0 100755 --- a/examples/deploy-container.sh +++ b/examples/deploy-container.sh @@ -20,6 +20,11 @@ if [[ ! -v IN_NIX_SHELL ]]; then exec nix-shell --run "./${BASH_SOURCE[0]##*/} $*" fi +if [[ $EUID != 0 ]]; then + # NixOS containers require root permissions + exec sudo "PATH=$PATH" "NIX_PATH=$NIX_PATH" "IN_NIX_SHELL=$IN_NIX_SHELL" "${BASH_SOURCE[0]}" "$@" +fi + # These commands can also be executed interactively in a shell session demoCmds=' echo @@ -65,7 +70,6 @@ read -d '' src <<'EOF' || true }; } EOF -$([[ $EUID = 0 ]] || echo sudo "PATH=$PATH" "NIX_PATH=$NIX_PATH") \ - $(type -P extra-container) shell -E "$src" "${runCmd[@]}" +extra-container shell -E "$src" "${runCmd[@]}" # The container is automatically deleted at exit