From cc7149eb785b98014032a816de25da4fc072a7dd Mon Sep 17 00:00:00 2001 From: Erik Arvstedt Date: Tue, 16 Mar 2021 12:45:17 +0100 Subject: [PATCH] examples: improve robustness of deploy scripts - The scripts now work within arbitrary nix-shells. Previously, they failed when run from nix shells other than `examples/shell.nix`. - The scripts now work from arbitrary working dirs. --- examples/deploy-container.sh | 6 ++++-- examples/deploy-krops.sh | 4 +++- examples/deploy-qemu-vm.sh | 4 +++- examples/shell.nix | 2 ++ 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/examples/deploy-container.sh b/examples/deploy-container.sh index 8cc424b..ccc3654 100755 --- a/examples/deploy-container.sh +++ b/examples/deploy-container.sh @@ -8,10 +8,12 @@ set -euo pipefail # Run with option `--interactive` or `-i` to start a shell for interacting with # the node. -if [[ ! -v IN_NIX_SHELL ]]; then +if [[ ! -v NIX_BITCOIN_EXAMPLES_DIR ]]; then echo "Running script in nix shell env..." cd "${BASH_SOURCE[0]%/*}" exec nix-shell --run "./${BASH_SOURCE[0]##*/} $*" +else + cd "$NIX_BITCOIN_EXAMPLES_DIR" fi if [[ $(sysctl -n net.ipv4.ip_forward || sudo sysctl -n net.ipv4.ip_forward) != 1 ]]; then @@ -22,7 +24,7 @@ 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]}" "$@" + exec sudo "PATH=$PATH" "NIX_PATH=$NIX_PATH" "NIX_BITCOIN_EXAMPLES_DIR=$NIX_BITCOIN_EXAMPLES_DIR" "${BASH_SOURCE[0]}" "$@" fi interactive= diff --git a/examples/deploy-krops.sh b/examples/deploy-krops.sh index ca6f42e..cf7de7f 100755 --- a/examples/deploy-krops.sh +++ b/examples/deploy-krops.sh @@ -12,10 +12,12 @@ set -euo pipefail # MAKE SURE TO REPLACE the SSH identity file if you use this script for # anything serious. -if [[ ! -v IN_NIX_SHELL ]]; then +if [[ ! -v NIX_BITCOIN_EXAMPLES_DIR ]]; then echo "Running script in nix shell env..." cd "${BASH_SOURCE[0]%/*}" exec nix-shell --run "./${BASH_SOURCE[0]##*/} $*" +else + cd "$NIX_BITCOIN_EXAMPLES_DIR" fi source qemu-vm/run-vm.sh diff --git a/examples/deploy-qemu-vm.sh b/examples/deploy-qemu-vm.sh index bff14db..77869b2 100755 --- a/examples/deploy-qemu-vm.sh +++ b/examples/deploy-qemu-vm.sh @@ -11,10 +11,12 @@ set -euo pipefail # MAKE SURE TO REPLACE the SSH identity file if you use this script for # anything serious. -if [[ ! -v IN_NIX_SHELL ]]; then +if [[ ! -v NIX_BITCOIN_EXAMPLES_DIR ]]; then echo "Running script in nix shell env..." cd "${BASH_SOURCE[0]%/*}" exec nix-shell --run "./${BASH_SOURCE[0]##*/} $*" +else + cd "$NIX_BITCOIN_EXAMPLES_DIR" fi source qemu-vm/run-vm.sh diff --git a/examples/shell.nix b/examples/shell.nix index 7f30899..59e5ac9 100644 --- a/examples/shell.nix +++ b/examples/shell.nix @@ -26,6 +26,8 @@ stdenv.mkDerivation rec { export NIX_PATH="nixpkgs=${nixpkgs-path}:nix-bitcoin=${toString nix-bitcoin-path}:." export PATH="${path}''${PATH:+:}$PATH" + export NIX_BITCOIN_EXAMPLES_DIR="${toString ./.}" + alias fetch-release="${toString nix-bitcoin-path}/helper/fetch-release" krops-deploy() {