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.
This commit is contained in:
Erik Arvstedt 2021-03-16 12:45:17 +01:00
parent 4022f86b92
commit cc7149eb78
No known key found for this signature in database
GPG Key ID: 33312B944DD97846
4 changed files with 12 additions and 4 deletions

View File

@ -8,10 +8,12 @@ set -euo pipefail
# Run with option `--interactive` or `-i` to start a shell for interacting with # Run with option `--interactive` or `-i` to start a shell for interacting with
# the node. # the node.
if [[ ! -v IN_NIX_SHELL ]]; then if [[ ! -v NIX_BITCOIN_EXAMPLES_DIR ]]; then
echo "Running script in nix shell env..." echo "Running script in nix shell env..."
cd "${BASH_SOURCE[0]%/*}" cd "${BASH_SOURCE[0]%/*}"
exec nix-shell --run "./${BASH_SOURCE[0]##*/} $*" exec nix-shell --run "./${BASH_SOURCE[0]##*/} $*"
else
cd "$NIX_BITCOIN_EXAMPLES_DIR"
fi fi
if [[ $(sysctl -n net.ipv4.ip_forward || sudo sysctl -n net.ipv4.ip_forward) != 1 ]]; then 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 if [[ $EUID != 0 ]]; then
# NixOS containers require root permissions # 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 fi
interactive= interactive=

View File

@ -12,10 +12,12 @@ set -euo pipefail
# MAKE SURE TO REPLACE the SSH identity file if you use this script for # MAKE SURE TO REPLACE the SSH identity file if you use this script for
# anything serious. # anything serious.
if [[ ! -v IN_NIX_SHELL ]]; then if [[ ! -v NIX_BITCOIN_EXAMPLES_DIR ]]; then
echo "Running script in nix shell env..." echo "Running script in nix shell env..."
cd "${BASH_SOURCE[0]%/*}" cd "${BASH_SOURCE[0]%/*}"
exec nix-shell --run "./${BASH_SOURCE[0]##*/} $*" exec nix-shell --run "./${BASH_SOURCE[0]##*/} $*"
else
cd "$NIX_BITCOIN_EXAMPLES_DIR"
fi fi
source qemu-vm/run-vm.sh source qemu-vm/run-vm.sh

View File

@ -11,10 +11,12 @@ set -euo pipefail
# MAKE SURE TO REPLACE the SSH identity file if you use this script for # MAKE SURE TO REPLACE the SSH identity file if you use this script for
# anything serious. # anything serious.
if [[ ! -v IN_NIX_SHELL ]]; then if [[ ! -v NIX_BITCOIN_EXAMPLES_DIR ]]; then
echo "Running script in nix shell env..." echo "Running script in nix shell env..."
cd "${BASH_SOURCE[0]%/*}" cd "${BASH_SOURCE[0]%/*}"
exec nix-shell --run "./${BASH_SOURCE[0]##*/} $*" exec nix-shell --run "./${BASH_SOURCE[0]##*/} $*"
else
cd "$NIX_BITCOIN_EXAMPLES_DIR"
fi fi
source qemu-vm/run-vm.sh source qemu-vm/run-vm.sh

View File

@ -26,6 +26,8 @@ stdenv.mkDerivation rec {
export NIX_PATH="nixpkgs=${nixpkgs-path}:nix-bitcoin=${toString nix-bitcoin-path}:." export NIX_PATH="nixpkgs=${nixpkgs-path}:nix-bitcoin=${toString nix-bitcoin-path}:."
export PATH="${path}''${PATH:+:}$PATH" export PATH="${path}''${PATH:+:}$PATH"
export NIX_BITCOIN_EXAMPLES_DIR="${toString ./.}"
alias fetch-release="${toString nix-bitcoin-path}/helper/fetch-release" alias fetch-release="${toString nix-bitcoin-path}/helper/fetch-release"
krops-deploy() { krops-deploy() {