nix-bitcoin/examples/deploy-qemu-vm.sh

69 lines
1.5 KiB
Bash
Raw Normal View History

2020-03-29 16:21:04 +00:00
#!/usr/bin/env bash
set -euo pipefail
# This script demonstrates how to run a nix-bitcoin node in QEMU.
# Running this script leaves no traces on your host system.
# This demo is a template for your own experiments.
# Run with option `--interactive` or `-i` to start a shell for interacting with
# the node.
2020-03-29 16:21:04 +00:00
# MAKE SURE TO REPLACE the SSH identity file if you use this script for
# anything serious.
if [[ ! -v IN_NIX_SHELL ]]; then
echo "Running script in nix shell env..."
cd "${BASH_SOURCE[0]%/*}"
2020-10-18 11:41:55 +00:00
exec nix-shell --run "./${BASH_SOURCE[0]##*/} $*"
2020-03-29 16:21:04 +00:00
fi
source qemu-vm/run-vm.sh
2020-03-29 16:21:04 +00:00
echo "Building VM"
nix-build --out-link $tmpDir/vm - <<'EOF'
2020-03-29 16:21:04 +00:00
(import <nixpkgs/nixos> {
configuration = {
imports = [
<configuration.nix>
<qemu-vm/vm-config.nix>
2020-03-29 16:21:04 +00:00
<nix-bitcoin/modules/secrets/generate-secrets.nix>
];
};
}).vm
EOF
vmNumCPUs=4
vmMemoryMiB=2048
2020-03-29 16:21:04 +00:00
sshPort=60734
runVM $tmpDir/vm $vmNumCPUs $vmMemoryMiB $sshPort
2020-03-29 16:21:04 +00:00
vmWaitForSSH
2020-03-29 16:21:04 +00:00
echo "Waiting until services are ready..."
c '
attempts=300
while ! systemctl is-active clightning &> /dev/null; do
((attempts-- == 0)) && { echo "timeout"; exit 1; }
sleep 0.2
done
'
echo
echo "Bitcoind service:"
c systemctl status bitcoind
echo
echo "Bitcoind network:"
c bitcoin-cli getnetworkinfo
echo
echo "lightning-cli state:"
c lightning-cli getinfo
echo
echo "Node info:"
c nodeinfo
2020-10-18 11:41:55 +00:00
case ${1:-} in
-i|--interactive)
. start-bash-session.sh
;;
esac
2020-04-15 16:54:02 +00:00
# Cleanup happens at exit (defined in qemu-vm/run-vm.sh)