omnixient/tests/regtest-node.nix
Padreug 7f4a71b98d test: VM smoke and Lightning regtest suites
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-28 10:00:14 +02:00

59 lines
2 KiB
Nix

# regtest-node — shared bitcoind(regtest) + Core Lightning + LND config.
#
# The single source of truth for the regtest stack, imported by BOTH:
# - the CI test → tests/regtest-core.nix
# - the interactive VM → tests/regtest-interactive.nix (via flake.nix)
# so the two can never drift.
#
# Consumers must ALSO import `nix-bitcoin.nixosModules.default` — it needs
# the flake input, which a plain module can't reach on its own.
#
# Both LN nodes are co-located and share the local bitcoind; lnd's p2p
# port is moved to 9736 so it doesn't clash with clightning's 9735. CLIs
# run as the nix-bitcoin `operator` user.
{
config,
pkgs,
lib,
...
}:
{
nix-bitcoin.generateSecrets = true;
nix-bitcoin.operator.enable = true;
services.bitcoind = {
enable = true;
regtest = true;
# regtest has no fee estimation, so sendtoaddress/funding need a
# fallback fee. nix-bitcoin appends extraConfig inside the [regtest]
# section, so this applies to the regtest network.
extraConfig = "fallbackfee=0.0002";
};
# Pre-mine a funded "test" wallet on bitcoind startup. 110 > 100 so the
# coinbase outputs are mature/spendable.
# NOTE: keep this height in sync with the assertions in
# tests/regtest-core.nix (it checks the nodes reach block 110).
systemd.services.bitcoind.postStart = lib.mkAfter ''
cli=${config.services.bitcoind.cli}/bin/bitcoin-cli
if ! $cli listwallets | ${pkgs.jq}/bin/jq -e 'index("test")' >/dev/null; then
"$cli" -named createwallet wallet_name=test load_on_startup=true
addr=$("$cli" -rpcwallet=test getnewaddress)
"$cli" generatetoaddress 110 "$addr"
fi
'';
services.clightning.enable = true; # p2p :9735
services.lnd = {
enable = true;
port = 9736; # avoid clashing with clightning's 9735
};
# jq is used by the test script and the interactive helpers.
environment.systemPackages = [ pkgs.jq ];
# Headroom for bitcoind + two lightning daemons in one VM.
virtualisation.cores = 2;
virtualisation.memorySize = 3072;
virtualisation.diskSize = 8192;
}