Skip to content

modules: replace regtest with services.bitcoind.network - #253

Merged
prusnak merged 19 commits into
bitcoinix:masterfrom
viberaven:global-network-option
Nov 16, 2026
Merged

prusnak merged 19 commits into
bitcoinix:masterfrom
viberaven:global-network-option

Conversation

@viberaven

@viberaven viberaven commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Target release: 0.2.0. Merge after the v0.1.6 release.

Replace services.bitcoind.regtest with a writable services.bitcoind.network enum: "mainnet" (default) or "regtest". Service modules and VM scenarios use this selection while preserving existing ports, daemon network names and data paths. The old boolean forwards to the new option during migration, so existing regtest configurations receive the Mempool notice and correct historical cookie and electrs paths. Continued use after updating the config version emits a deprecation warning.

Replace the positional services.bitcoind.makeNetworkName helper with nix-bitcoin.lib.networkName. In modules that take config, bind nbLib = config.nix-bitcoin.lib;. Callers specify only names to override; other names pass through unchanged:

nbLib.networkName { mainnet = "bitcoin"; }

Mempool 3.3.2 supports regtest, but the module previously configured it as mainnet even when connected to a regtest node. Its backend now follows services.bitcoind.network. On regtest, frontend defaults select the same network using MAINNET_ENABLED, REGTEST_ENABLED and ROOT_NETWORK, keeping the site and API at their existing URLs. Mainnet uses the unchanged packaged frontend, avoiding an unnecessary Angular rebuild. Explicit frontend settings remain overridable. Existing regtest deployments receive a 0.2.0 migration notice covering automatic cache clearing and custom frontend settings.

Include release and upgrade notes, the example config-version update, configuration tests for network selection, helper overrides and migrations, and VM checks for the served Mempool frontend configuration and regtest genesis block through its API.

Charge-LND now receives explicit certificate and macaroon paths instead of staging symlinks under a synthetic mainnet directory. Remove its unused state directory and setup script. Default deployments need no changes; configurations selecting credentials through --lnddir in extraFlags receive a targeted 0.2.0 migration notice only if either --tlscert or --macaroon is missing.

Migration notices use the per-change files introduced in #257, including updated network paths in historical notices. Release and upgrade entries follow #259's heading convention; #260's services guide changes are preserved.

Validation after rebasing onto master (72e6be0):

  • nix flake check --all-systems, the docs build, and shellcheck passed.
  • Full default (mainnet) VM suite passed with the updated dependency pins, RTL certificate-pinning checks, and Tor-enforcement tests.
  • The first netnsRegtest run failed after LND 0.21.8 panicked during a stop in the configuration-replacement test (unable to subscribe to chans: subscription server shutting down). LND recovered, but the later clean-exit test detected the failure recorded in the journal. A full rerun passed without code changes.
  • The final master updates only pin the deployment examples to v0.1.6 and update AGENTS.md release-version guidance; they leave the tested modules and VM scenarios unchanged.
  • Direct evaluation of a legacy regtest configuration confirmed the new 0.1.6 RTL/Tor notices appear alongside all three 0.2.0 migration notices in version order.
  • The versioning collector, 0.1.6 notices and documentation, dependency pins, and upstream RTL/security changes are preserved.

@github-actions github-actions Bot added area: ci .github/, test/, dev/ area: docs docs/, README, examples/, SECURITY.md, book.toml, assets area: modules modules/ and pkgs/lib.nix status: rebase needed Merge conflicts need to be resolved labels Nov 13, 2026
@prusnak prusnak added this to the v0.2.0 milestone Nov 13, 2026
@viberaven viberaven changed the title modules: add deployment-wide network selection for 0.2.0 modules: replace regtest with services.bitcoind.network for 0.2.0 Nov 13, 2026
@github-actions github-actions Bot added the area: packages pkgs/ and flake pins label Nov 13, 2026
@viberaven
viberaven force-pushed the global-network-option branch from 9de177e to 44059ed Compare November 13, 2026 11:42
@github-actions github-actions Bot added status: rebase needed Merge conflicts need to be resolved and removed status: rebase needed Merge conflicts need to be resolved labels Nov 13, 2026
@prusnak prusnak changed the title modules: replace regtest with services.bitcoind.network for 0.2.0 modules: replace regtest with services.bitcoind.network Nov 13, 2026
@viberaven
viberaven force-pushed the global-network-option branch from 44059ed to f98fbd9 Compare November 13, 2026 18:36
@github-actions github-actions Bot added status: rebase needed Merge conflicts need to be resolved and removed status: rebase needed Merge conflicts need to be resolved labels Nov 13, 2026
@msgilligan

Copy link
Copy Markdown
Collaborator

@viberaven @prusnak @seberm I"m looking forward to trying this. I'm hoping we can get it working on Testnet5 (yes, five)

@viberaven
viberaven force-pushed the global-network-option branch from e57638d to 052260d Compare November 14, 2026 23:05
@github-actions github-actions Bot added type: feature New capability or service and removed status: rebase needed Merge conflicts need to be resolved labels Nov 14, 2026

@ostermayer ostermayer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 052260d7. Mainnet looks the same as on master: ports, data paths, network names, units and secrets don't change, and the networkName callers give the old makeNetworkName result on both networks. charge-lnd still reads /run/lnd/charge-lnd.macaroon (0400, its own user), and flags in extraFlags still come last.

The problems are in the upgrade path for existing regtest configs.

1. The old regtest = true doesn't reach network, so notices that depend on the network see mainnet.

services.bitcoind.regtest is now a removed option, so on an old regtest config network is "mainnet" until the user migrates. The versioning error shows before the removed-option error, so the notices are computed for mainnet:

  • modules/versioning/0.2.0/mempool-network.nix:4 checks network == "regtest", so it never fires for a regtest node that's upgrading. With regtest = true, services.mempool.enable = true and configVersion = "0.1.6", the error lists only the bitcoin-network notice and says to set configVersion = "0.2.0". The user never sees the Mempool notice.
  • modules/versioning/0.1.3/electrs-reindex.nix:8 and modules/versioning/0.1.2/bitcoind-rpc-cookie.nix:10 now print mainnet paths. With regtest = true, electrs and configVersion = "0.1.1", the error says rm -r /var/lib/electrs/bitcoin and names /var/lib/bitcoind/.cookie. Master says /var/lib/electrs/regtest and /var/lib/bitcoind/regtest/.cookie for the same config. The regtest index stays, and electrs 0.12 then refuses to start.
  • The tests don't catch this, because testHistoricalNetworkMigrationPaths and testMempoolNetworkMigration set network = "regtest" at old config versions, where that option didn't exist.

One fix is mkChangedOptionModule from regtest to network, so the old value still reaches network during the upgrade. Another is to read options.services.bitcoind.regtest in these notices too.

2. Is this meant to merge after the v0.1.6 tag?

The notices are in modules/versioning/0.2.0/ and examples/configuration.nix:287 sets 0.2.0, but the upcoming release is 0.1.6. AGENTS.md:174 says to bump only the last component. If this merges before the tag, 0.1.6 ships notices that say to set configVersion = "0.2.0". A config at 0.2.0 then skips every 0.1.6 notice that lands later, for example the one in #258.

3. The makeNetworkName part of the bitcoin-network notice can't fire, and the replacement text names a variable users don't have.

  • On master makeNetworkName is read-only with a default (modules/bitcoind.nix:157-160 at f91deeaf), so no config could define it, and options.services.bitcoind.makeNetworkName.isDefined is never true for a real upgrade. A config that calls it gets the mkRemovedOptionModule message instead, which is clear. testRemovedNetworkNameHelper defines the option, which wasn't possible before.
  • modules/versioning/0.2.0/bitcoin-network.nix:11, modules/obsolete-options.nix:23 and docs/upgrading.md:45 say nbLib.networkName. nbLib is a let binding inside the modules, so in a user config it's an undefined variable. docs/release-notes.md:12 has the right name, config.nix-bitcoin.lib.networkName.

4. Minor: the charge-lnd notice also fires for configs that aren't affected.

modules/versioning/0.2.0/charge-lnd-credentials.nix:5 fires on any --lnddir, also when extraFlags gives --tlscert and --macaroon too. charge-lnd then doesn't use --lnddir for the credentials, so the paths are the same before and after.

I checked the errors in 1 with nix eval against the PR head and master. The configuration checks pass on the head.

@viberaven

Copy link
Copy Markdown
Contributor Author

Addressed in 809b5f7 and 36cbdf5:

  1. regtest now forwards to network via mkChangedOptionModule. Tests cover legacy configs, the Mempool notice, and correct historical regtest paths.
  2. Yes—this targets 0.2.0 and will merge after v0.1.6. The PR description now states this explicitly.
  3. Removed the unreachable helper-definition check and tested an actual call to the removed helper. The error uses config.nix-bitcoin.lib.networkName; the docs explicitly define nbLib.
  4. The Charge-LND notice now skips configs that explicitly set both credential paths. Tests cover partial and complete overrides.

Flake checks, docs build, shellcheck, and targeted migration checks passed.

@ostermayer ostermayer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked 36cbdf5e. All four points are fixed:

  1. With regtest = true and configVersion = "0.1.1", the electrs and cookie notices now give /var/lib/electrs/regtest and /var/lib/bitcoind/regtest/.cookie. With Mempool and configVersion = "0.1.6", the Mempool notice fires.
  2. Merging after v0.1.6 settles the version question.
  3. The removed-helper message says config.nix-bitcoin.lib.networkName, and the docs show where nbLib comes from.
  4. The charge-lnd notice no longer fires when extraFlags sets both --tlscert and --macaroon, and it still fires for --lnddir alone.

I checked each with nix eval against the head.

@seberm

seberm commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

@prusnak Fable review


Reviewed 36cbdf5. One must-fix that the earlier review rounds didn't cover; the migration path and charge-lnd changes look right.

Must fix

  • modules/mempool.nix: the frontend defaults are also set on mainnet, so frontend.settings is no longer {} and staticContentRoot becomes mempool-frontend.withConfig {...} instead of the mempool-frontend package. With services.mempool.enable = true on mainnet, the drvPath changes from aahsrl48…-mempool-frontend-3.3.2.drv (master, equal to the package) to qh55p0zc…-mempool-frontend-3.3.2.drv. The values equal upstream's defaults, so nothing changes at runtime, but every mainnet Mempool host rebuilds the Angular frontend on upgrade, and CI's build job no longer builds what default deployments run. Set the defaults only off mainnet, e.g. services.mempool.frontend.settings = mkIf (bitcoind.network != "mainnet") { ... }, and expect frontend = {} for mainnet in testMempoolNetworks.

Nits

  • defaultText for the two ports is prose now and renders as a Nix expression in the options docs. Use literalMD, or keep an expression.
  • Upgraded hosts keep a stale /var/lib/charge-lnd/lnddir-proxy (symlinks only). A tmpfiles R rule or a sentence in the upgrade note.

Exposure: no new listener or netns connection. network is a closed enum and fails closed. The Mempool change only touches config values. charge-lnd loses a writable StateDirectory and its preStart, and reads the public cert and its user-only macaroon directly. defaultHardening is unchanged.

Tested: eval only, against 36cbdf5 and master. Mainnet Mempool frontend drvPath comparison (above); regtest = true with configVersion = "0.2.0" gives network = "regtest" plus the deprecation warning; the packaged charge-lnd has --tlscert/--macaroon and they take precedence over --lnddir; mempool 3.3.2 clears disk caches from another network (backend/src/api/disk-cache.ts). VM coverage: CI is green on 36cbdf5 (default, netnsRegtest).

Assisted-by: Claude Code (Claude Fable 5.1, Claude Fable 5.1 as advisor)

@viberaven

Copy link
Copy Markdown
Contributor Author

Fixed in e42fbe4:

  1. Frontend defaults now apply only off mainnet. Mainnet retains the package derivation; regression tests verify this and the regtest configuration. Updated the VM check for compiled mainnet defaults.
  2. Both port descriptions now use literalMD.
  3. The upgrade notes explain that the unused /var/lib/charge-lnd/lnddir-proxy tree can be removed after upgrading.

Flake checks, docs build, test-runner check, and focused Mempool VM tests on mainnet and regtest passed.

@seberm seberm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes - let's hold the merge until v0.1.6 is tagged.

Replace services.bitcoind.regtest with nix-bitcoin.network and migrate network consumers. Add configuration contracts and migration guidance for 0.2.0.

Assisted-by: Codex (GPT-6 Astra)
Use services.bitcoind.network as the writable deployment-wide enum and update consumers, tests and 0.2.0 migration guidance.

Assisted-by: Codex (GPT-6 Astra)
Use services.bitcoind.network directly. Document the 0.2.0 migration and reject obsolete helper definitions.

Assisted-by: Codex (GPT-6 Astra)
Assisted-by: Codex (GPT-6 Astra)
Assisted-by: Codex (GPT-6 Astra)
Assisted-by: Codex (GPT-6 Astra)
Replace repeated network name mappings with networkName, preserving unmapped names. Update migration guidance and test empty, partial and full overrides.

Assisted-by: Codex (GPT-6 Astra)
Assisted-by: Codex (GPT-6 Astra)
Assisted-by: Codex (GPT-6 Astra)
Assisted-by: Codex (GPT-6 Astra)
Follow the release-note convention introduced on master.

Assisted-by: Codex (GPT-6 Astra)
Configure backend and frontend network settings for mainnet and regtest. Keep the selected network at the site root, preserve frontend overrides, and cover the served config and regtest API in integration tests. Add 0.2.0 migration guidance for existing regtest deployments.

Assisted-by: Codex (GPT-6 Astra)
Pass explicit TLS certificate and macaroon paths and remove the unused state directory and symlink setup. Document the migration for custom --lnddir flags and verify direct credential access on both networks.

Assisted-by: Codex (GPT-6 Astra)
Add release and upgrade entry headings following the documentation convention. Check that the extracted historical notices still resolve cookie and electrs paths for both networks.

Assisted-by: Codex (GPT-6 Astra)
Forward the old regtest boolean to services.bitcoind.network so existing configs receive the Mempool notice and the correct historical cookie and electrs paths. Cover legacy configurations and conflicting old/new selections.

Remove the unreachable makeNetworkName definition check, test a real call to the removed helper, and make the replacement instructions usable in user modules.

Assisted-by: Codex (GPT-6 Astra)
Only notify configurations that use --lnddir without explicitly overriding both credential paths. Cover separate, equals and mixed flag forms, including partially overridden credentials, and clarify the upgrade instructions.

Assisted-by: Codex (GPT-6 Astra)
Apply frontend network defaults only off mainnet, preserving the package derivation and avoiding an unnecessary Angular rebuild. Verify derivation selection for both networks and adapt the VM check for compiled mainnet defaults.

Render port default descriptions as Markdown and document removal of the obsolete charge-lnd proxy tree after upgrading.

Assisted-by: Codex (GPT-6 Astra)
@viberaven
viberaven force-pushed the global-network-option branch from e42fbe4 to fd01856 Compare November 16, 2026 17:24
@prusnak
prusnak merged commit cf39a66 into bitcoinix:master Nov 16, 2026
21 checks passed
prusnak added a commit that referenced this pull request Nov 16, 2026
bitcoinix currently selects packages from stable and unstable nixpkgs.
This change uses a single `nixpkgs` input tracking `nixos-unstable` for
systems and packages. The flake NixOS module defaults
`nix-bitcoin.useVersionLockedPkgs` to true; the 0.2.0 migration explains
when callers instead control the service package pin.

- Remove the separate input and `pkgsUnstable` plumbing. Inline package
selection in `pkgs/default.nix`, remove generated `pkgs/pinned.nix`, and
simplify version reporting and update helpers. Preserve public `.pinned`
paths and the non-flake lock-file adapter.
- Adapt I2P, FUSE replication mounts, VM/debug runners and deployment
examples to unstable NixOS. Preserve SAM-only I2P exposure and
replication recovery, and allow Core Lightning's memory-locking syscalls
in nspawn examples and test containers.
- Add the 0.2.0 notices as separate files under
`modules/versioning/0.2.0/`, using master's collector and its automatic
documentation references. Cover package-pinning/database downgrade
risks, whole-system unstable evaluation, firewall/FUSE defaults and
custom containers. Document I2P validation limits. Keep the NixOS
assertion safeguard against migration recursion, and test both
individual notices and the assertion. Read the container runner's config
version from the notice directories.
- Preserve master's network selection, secret validation, RTL
certificate pinning/lifecycle and Tor-enforcement changes. Use the
single package set's Bun for Unbeholden Wallet. Preserve all released
upgrade/release-note sections and their headings.
- Fetch both patches from nbd-wtf/trustedcoin#44
(`3210fc9`, `21a1f43`) with the supplied hashes, replacing the local
patch. They fix initialization races and reporting height zero without a
source.
- Use the unmodified nixpkgs electrs package: the refreshed pin supplies
pkg-config and zstd, so the override is removed.

Rebased on `master` at `cf39a66` (including #253 and the versioning
refactor). Ran `helper/update-flake.sh`; the single nixpkgs input is now
`d5cc6833999746cffdfe0598f7bc801a57b887a9`, verified as the current
`nixos-unstable` head on 2026-11-16. Core Lightning stays at 26.06.10;
compared with the previous PR head, LND moves to 0.21.8-beta and RTL to
0.15.17. Rechecked treewide TODO-EXTERNAL comments and the CVE
exceptions against the new runtime closure.

Validation after this rebase/update:

- `nix flake check --all-systems` (including module/migration checks,
test-runner checks, LND macaroon filters, CVE tools and workflow
checks).
- Builds of the unmodified electrs package and TrustedCoin with both
upstream patches, including TrustedCoin's package tests.
- VM scenarios passed: `default`, `netns`, `netnsRegtest`,
`trustedcoin`, `i2p` and `i2pLocal`. The first `netnsRegtest` run failed
during LND's automatic macaroon-cleanup restart with `panic: unable to
subscribe to chans: subscription server shutting down`; the unchanged VM
retry passed. This PR and current master select the identical LND
0.21.8-beta derivation.
- Flakes and Colmena deployment examples built with their deployment
tools. The persistent container example also built with CLN enabled and
config version 0.2.0; its generated nspawn configuration includes
`--system-call-filter=@memlock`.
- Generated-version check, shellcheck, mdBook build and nixos-search
export. The export was run directly because the CI script's Cachix setup
requires permissions unavailable to this local user.
- Representative node runtime closure (including Unbeholden Wallet)
built and scanned with/without the whitelist. Retained exception
packages have unchanged outputs; the same eight other CVE identifiers
across brotli, dhcpcd, jq, rsync and sqlite remain visible for triage.
This is not a clean vulnerability scan.

ARM outputs were evaluated, not built or VM-tested. Other VM scenarios
and the complete package build set were not rerun.
prusnak added a commit that referenced this pull request Nov 23, 2026
Target release **v0.2.0**. Follows #253 and addresses #17 for signet and
testnet4.

Set `services.bitcoind.network` to `"signet"` or `"testnet4"` to
configure Bitcoin Core and its dependent services. Core Lightning,
electrs, Fulcrum, Unbeholden Wallet, Mempool and BTCPay Server can use
either network. Evaluation rejects LND on both because the packaged
`lndinit` cannot initialize those wallets. CLBOSS and Trustedcoin are
rejected on testnet4.

The configuration guide warns that switching networks in place reuses
the Fulcrum, Mempool, BTCPay Server and NBXplorer databases. Use
separate deployments to keep their data apart.

On regtest, the generated Tor mapping now forwards port 18444 to local
port 18445. Users who maintain their own mapping can update its target
or keep `services.bitcoind.onionPort = 8334;`. The 0.2.0 migration
notice targets nodes using the default.

**Verification**

- Offline signet and testnet4 VMs verified genesis hashes, Core
Lightning network selection, NBXplorer cookie access and Mempool
frontend settings.
- A regtest VM verified that bitcoind listens on 18445. Evaluation tests
cover the generated mapping, explicit overrides and incompatible service
combinations.
- The release-note validator and documentation build passed with the
0.2.0 drafts.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: ci .github/, test/, dev/ area: docs docs/, README, examples/, SECURITY.md, book.toml, assets area: modules modules/ and pkgs/lib.nix area: packages pkgs/ and flake pins type: feature New capability or service

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants