2020-03-29 09:21:04 -07: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.
|
2021-02-01 13:53:06 -08:00
|
|
|
# Run with option `--interactive` or `-i` to start a shell for interacting with
|
|
|
|
# the node.
|
2020-03-29 09:21:04 -07:00
|
|
|
|
|
|
|
# MAKE SURE TO REPLACE the SSH identity file if you use this script for
|
|
|
|
# anything serious.
|
|
|
|
|
2021-03-16 04:45:17 -07:00
|
|
|
if [[ ! -v NIX_BITCOIN_EXAMPLES_DIR ]]; then
|
2020-03-29 09:21:04 -07:00
|
|
|
echo "Running script in nix shell env..."
|
2020-10-11 11:02:24 -07:00
|
|
|
cd "${BASH_SOURCE[0]%/*}"
|
2020-10-18 04:41:55 -07:00
|
|
|
exec nix-shell --run "./${BASH_SOURCE[0]##*/} $*"
|
2021-03-16 04:45:17 -07:00
|
|
|
else
|
|
|
|
cd "$NIX_BITCOIN_EXAMPLES_DIR"
|
2020-03-29 09:21:04 -07:00
|
|
|
fi
|
|
|
|
|
2021-03-08 06:11:15 -08:00
|
|
|
source qemu-vm/run-vm.sh
|
2020-03-29 09:21:04 -07:00
|
|
|
|
|
|
|
echo "Building VM"
|
2021-03-08 06:11:15 -08:00
|
|
|
nix-build --out-link $tmpDir/vm - <<'EOF'
|
2020-03-29 09:21:04 -07:00
|
|
|
(import <nixpkgs/nixos> {
|
|
|
|
configuration = {
|
|
|
|
imports = [
|
2021-03-08 06:11:14 -08:00
|
|
|
<configuration.nix>
|
2021-03-08 06:11:15 -08:00
|
|
|
<qemu-vm/vm-config.nix>
|
2020-03-29 09:21:04 -07:00
|
|
|
];
|
2021-03-10 05:08:34 -08:00
|
|
|
nix-bitcoin.generateSecrets = true;
|
2020-03-29 09:21:04 -07:00
|
|
|
};
|
2022-06-27 15:08:28 -07:00
|
|
|
}).config.system.build.vm
|
2020-03-29 09:21:04 -07:00
|
|
|
EOF
|
|
|
|
|
|
|
|
vmNumCPUs=4
|
2021-03-08 06:11:15 -08:00
|
|
|
vmMemoryMiB=2048
|
2020-03-29 09:21:04 -07:00
|
|
|
sshPort=60734
|
2021-03-08 06:11:15 -08:00
|
|
|
runVM $tmpDir/vm $vmNumCPUs $vmMemoryMiB $sshPort
|
2020-03-29 09:21:04 -07:00
|
|
|
|
2021-03-08 06:11:15 -08:00
|
|
|
vmWaitForSSH
|
2021-03-08 06:11:16 -08:00
|
|
|
printf "Waiting until services are ready"
|
|
|
|
c "
|
|
|
|
$(cat qemu-vm/wait-until.sh)
|
|
|
|
waitUntil 'systemctl is-active clightning &> /dev/null' 100
|
|
|
|
"
|
|
|
|
echo
|
|
|
|
|
2020-03-29 09:21:04 -07:00
|
|
|
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 04:41:55 -07:00
|
|
|
case ${1:-} in
|
|
|
|
-i|--interactive)
|
|
|
|
. start-bash-session.sh
|
|
|
|
;;
|
|
|
|
esac
|
2020-04-15 09:54:02 -07:00
|
|
|
|
2021-03-08 06:11:15 -08:00
|
|
|
# Cleanup happens at exit (defined in qemu-vm/run-vm.sh)
|