Skip to content

Unify Bitcoinix Packages on Unstable Nixpkgs - #224

Merged
prusnak merged 19 commits into
bitcoinix:masterfrom
viberaven:drop-stable
Nov 16, 2026
Merged

prusnak merged 19 commits into
bitcoinix:masterfrom
viberaven:drop-stable

Conversation

@viberaven

@viberaven viberaven commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

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 getchaininfo: wait for init and never report height 0 without a source 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.

@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 area: packages pkgs/ and flake pins labels Nov 7, 2026
@seberm

seberm commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

@viberaven Heads-up: I am retesting the parts CI doesn't cover locally, on the current head. A full review with results will follow.

  • VM scenarios: trustedcoin (passed), clightning-replication including the new mount-lifecycle checks (passed); hardened and lndPruned running
  • i2pLocal / i2p, with an extra check of what i2pd listens on besides SAM
  • Examples: deploy-qemu-vm.sh, deploy-krops.sh
  • Module eval against a system still on NixOS 26.05
  • Already passing: module-config check; generated files reproduce (update-flake.sh -f --refresh gives no diff, check-versions.sh passes)

We can't test the container examples, the test-runner container or the memlock flag here (they need root).

@ostermayer This PR moves the whole package and OS base from NixOS 26.05 to unstable, so it's a big one. Would you mind running it through your AI review setup when you have a moment? Thanks!

@seberm

seberm commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Thanks for the changes!


Changes requested: the I2P change exposes more than before, and the migration docs don't match what happens on a NixOS 26.05 system.

Must fix

  1. i2pd now runs the web console, HTTP proxy and SOCKS proxy, and publishes the router's addresses. The unstable i2pd module enables http, httpproxy and socksproxy with mkDefault true. i2pd 2.61 itself defaults ntcp2.published and ssu2.published to true. On master, bitcoinix's i2pd config enables only SAM and sets both published = false. With services.bitcoind.i2p on, the i2pLocal and i2p VMs show i2pd listening on 127.0.0.1:7070, 127.0.0.1:4444, 127.0.0.1:4447 and an NTCP2 port on 0.0.0.0, in addition to SAM. Every local user and every service outside a netns (e.g. via SSRF from a web service) can reach the unauthenticated web console, which shows the router's tunnels and SAM sessions and can shut it down. They can also use the I2P HTTP/SOCKS proxies. The node publishes its clearnet IP in the I2P netdb and accepts inbound I2P connections wherever the firewall allows them. Fix in modules/bitcoind.nix (mkDefault false conflicts with the module's mkDefault true, so use mkOverride 900):

    settings = {
      sam = { ... };
      http.enabled = mkOverride 900 false;
      httpproxy.enabled = mkOverride 900 false;
      socksproxy.enabled = mkOverride 900 false;
      ntcp2.published = mkDefault false;
      ssu2.published = mkDefault false;
    };

    Please also extend test_i2pd so that it fails when i2pd listens on anything besides SAM, e.g.:

    pid = machine.succeed("systemctl show -P MainPID i2pd").strip()
    out = machine.succeed("ss -Htlnp")
    ports = sorted({l.split()[3].rsplit(":", 1)[1] for l in out.splitlines() if f"pid={pid}," in l})
    assert ports == [str(sam["port"])], f"i2pd listens on {ports}"

    The current tests check only SAM, so this passed CI.

  2. Migration docs and the versioning message don't match what happens to users on NixOS 26.05. The modules now define options that exist only in unstable NixOS (services.i2pd.checkConfig, services.i2pd.settings). Any system evaluated with nixos-26.05 nixpkgs fails before assertions run, whatever useVersionLockedPkgs is set to and even without i2p or netns: The option `services.i2pd.checkConfig' does not exist. Those users never see the versioning message. docs/upgrading.md and the message say only "if you disable it, use unstable nixpkgs". Please state plainly:

    • The system itself must be evaluated with unstable nixpkgs. Quote the error above, since that's what these users will search for.
    • For users whose system follows bitcoinix/nixpkgs, as the examples do, the whole OS moves from 26.05 to unstable on update, not just the service packages.
    • With useVersionLockedPkgs = true now the default, the user's nixpkgs.overlays and nixpkgs.config no longer apply to the pinned service packages (bitcoind, lnd, clightning, …). An overlay that patches one of them is dropped silently.

Should fix

  1. Track nixos-unstable instead of nixpkgs-unstable. The input now builds the entire NixOS system, and only nixos-unstable waits for the NixOS tests to pass. nixpkgs-unstable advances on package builds alone.
  2. Link an upstream issue or PR for pkgs/trustedcoin/wait-for-initialization.patch (or open one), so we can drop the patch later.

Optional

  1. The memlock requirement for nspawn: please note in the commit what changed. CLN is 26.06.9 on both pins, so is it the host's systemd or the libsodium bump? The versioning entry text could then say who's affected.

Tested f0cae02: clightning-replication passes, including the new mount-shutdown and crash-restart subtests for all three replication modes. The rest ran on the previous head, eb3db02, whose tree differs only in the replication module, its test and docs: module-config passes; generated files reproduce (update-flake.sh -f --refresh gives no diff, check-versions.sh passes); trustedcoin, hardened and lndPruned pass; deploy-qemu-vm.sh passes; deploy-krops.sh fails at evaluation (The option `source."configuration.nix".file.assertions' does not exist), the same on master, so it doesn't come from this PR; the fix in item 1 is verified in i2pLocal/i2p with the listener assertion above (fails without the fix, passes with it); evaluation against nixos-26.05 nixpkgs fails with the error in item 2. Not tested (need root): container examples, test-runner container, persistent container example, the memlock flag. Not run: CVE scan of the new pin (mempool isn't cached for the PR's pin).

Review performed with Claude Code (Claude Opus 5.5).

@viberaven

Copy link
Copy Markdown
Contributor Author

@seberm Addressed the review and force-pushed the updated branch, now at 8ade3ca.

  1. I2P exposure: disabled the web console, HTTP proxy and SOCKS proxy with mkOverride 900 false; restored mkDefault false for NTCP2/SSU2 address publication. Explicit user opt-ins still work. test_i2pd now asserts that SAM is i2pd's only TCP listening port, alongside the SAM handshake check. Module tests cover the defaults and explicit overrides. The upgrade guide also records these defaults.
  2. Migration guidance: both the 0.1.5 upgrade guide and versioning message now state that system evaluation requires unstable nixpkgs regardless of useVersionLockedPkgs, quote the NixOS 26.05 unknown-option error, explain that following bitcoinix/nixpkgs updates the whole OS, and warn that host nixpkgs.overlays/nixpkgs.config do not apply to pinned service packages. The guide describes how to retain customizations and says to keep the existing system.stateVersion.
  3. Channel choice deferred: retained nixpkgs-unstable for now because this branch incorporates the CLN 26.06.10 security update; I rechecked nixos-unstable and it still carries 26.06.9. Switching today would undo that update. A TODO-EXTERNAL in flake.nix tracks switching once the NixOS channel includes 26.06.10.
  4. Trustedcoin patch: linked the patch to getchaininfo: wait for init and never report height 0 without a source nbd-wtf/trustedcoin#44, with a removal note for a release containing the upstream fix.
  5. nspawn memlock: the commit message records that the observed failure was already present with CLN 26.06.9 on the unstable base. The precise systemd/libsodium change responsible has not been isolated, so no causal attribution is claimed. The migration notice is restricted to nspawn containers with CLN enabled and documents the host-side flag.

Validation on the updated local branch: i2pLocal and i2p VM scenarios passed (the former reused a successful Nix result; the latter executed here), the x86_64 module-config check built successfully, nix flake check passed, all-system flake evaluation passed with --all-systems --no-build, and generated-version checks, shellcheck, and mdBook passed. ARM builds and the remaining VM/container scenarios were not rerun during this review follow-up.

Assisted by Codex (gpt-6.1-sol).

@seberm

seberm commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

@prusnak I think we should release the v0.1.5 before merging this one. Let's target this for v0.1.6 - agree?

btw - running another round of review.

@seberm

seberm commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

The previous round's points (I2P listeners, migration docs, channel choice, trustedcoin upstream link, memlock wording) are all addressed. A treewide recheck and a full-node diff against master (every service, netns, i2p, hardened-extended) found the following.

Must fix

  1. Non-flake users no longer get the locked packages. nix-bitcoin.useVersionLockedPkgs exists only in the flake's nixosModule. Configurations that import <nix-bitcoin/modules/modules.nix> directly (examples/configuration.nix, krops) get nix-bitcoin.pkgs from modules/nix-bitcoin.nix, i.e. import ../pkgs { inherit pkgs; } with the system's pkgs. On master, pkgsUnstable still defaulted to the locked revision there; with this PR, every pinned package comes from the user's <nixpkgs>. Evaluated without the flake, master with a NixOS 26.05 <nixpkgs> gives CLN 26.06.10; this PR with an older unstable <nixpkgs> (6dadaf4) gives 26.06.9, without the security fix. This contradicts the new docs and versioning message. Fix in modules/nix-bitcoin.nix:
    default = (import ../pkgs {
      pkgs = import (import ../pkgs/nixpkgs-pinned.nix).nixpkgs {
        inherit (pkgs.stdenv.hostPlatform) system;
        config = {};
        overlays = [];
      };
    }).modulesPkgs;
    With this, the non-flake case gives CLN 26.06.10. Flake users are unaffected: useVersionLockedPkgs = false still uses the system's pkgs, and module-config passes. Please also drop the <nixpkgs> default in the top-level default.nix, and add a test/configuration.nix case that evaluates the modules without the flake.

Should fix

  1. The unstable pin lags master's 26.05 base on security fixes. These system packages are older than on master: curl 8.22.0 vs 8.23.0 (8.23.0 fixes a high-severity vulnerability), brotli 1.2.0 vs 1.2.1 (out-of-bounds write), c-ares 1.34.8 vs 1.34.9, nodejs_24 24.21.0 vs 24.22.1, unbound 1.26.1 vs 1.26.2. On master, only the unstable-pinned packages used brotli 1.2.0; with this PR, the whole OS does. The fixes are on nixpkgs master but not yet in nixpkgs-unstable or nixos-unstable. Please bump the lock once the channel has them, before merge or at the latest before the 0.1.5 release.
  2. nginx and mysql lose MemoryDenyWriteExecute. Unstable's modules now set it to false for pcre2 JIT. bitcoinix sets neither, so mempool's nginx frontend and MariaDB run with weaker sandboxing than on master. bitcoinix never enables pcre_jit. With this in modules/mempool.nix, the default scenario passes (mempool, BTCPay Server, RTL), with no nginx or mysqld errors:
    # Unstable NixOS disables this for pcre2 JIT, which neither service needs here
    systemd.services.mysql.serviceConfig.MemoryDenyWriteExecute = mkOverride 99 true;
    systemd.services.nginx.serviceConfig.MemoryDenyWriteExecute = mkIf cfg.frontend.enable (mkOverride 99 true);
    mkOverride 99 beats upstream's plain false, while a user's mkForce still wins.

Optional

  1. i2pd now runs with DynamicUser and StateDirectory=i2pd. systemd migrates an existing /var/lib/i2pd to /var/lib/private/i2pd, but no test covers upgrading a node that already has i2pd state.
  2. test_i2pd takes its ss snapshot right after wait_for_unit, before the SAM handshake wait. Moving the port check after the handshake avoids missing a late listener or an unbound SAM.
  3. test/lib/make-test.nix: the comment "NixOS 26.05 derives the container's networking.interfaces…" should no longer name 26.05.

Tested b290eb8 merged with current master: module-config passes; VM scenarios i2pLocal, i2p, trustedcoin, clightning-replication and hardened pass; default passes with the fixes from items 1 and 3 applied. Full-node diff against master: no evaluation warnings (also none for examples/flakes); tor, MariaDB and PostgreSQL settings identical; PostgreSQL 17 and MariaDB 11.4 unchanged; unit changes only in i2pd, nginx/mysql MemoryDenyWriteExecute and the intended replication change. With NixOS 26.05, evaluation fails with the quoted services.i2pd.checkConfig error. Not tested here: container examples and the memlock flag (need root), and the CVE scan of the new pin.

Assisted-by: Claude Code (Claude Opus 5.5)

@prusnak

prusnak commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

@prusnak I think we should release the v0.1.5 before merging this one. Let's target this for v0.1.6 - agree?

Yes. This PR is definitely post-0.1.5

@seberm seberm modified the milestones: v0.1.6, v0.2.0 Nov 8, 2026
@viberaven

Copy link
Copy Markdown
Contributor Author

Rebased onto current master (2835053) and switched the single input to nixos-unstable (f4a03c0), which now includes CLN 26.06.10. Removed the deferred-switch TODO and regenerated via helper/update-flake.sh -f --refresh; pinned service versions are unchanged.

Since 0.1.5 has now been released, moved this PR's unstable-only and nspawn migration notices to 0.1.6, preserved the released 0.1.5 notes, updated the main example's configVersion, and adjusted the migration checks.

Validation passed on the new pin: all-system flake evaluation; all four x86_64 flake check builds; i2pLocal, i2p, trustedcoin, and clightning-replication VM scenarios; Flakes and Colmena deployment builds; generated-version checks, shellcheck, and mdBook. ARM builds and the remaining VM/container scenarios were not rerun. Updated the PR description to reflect the current channel, config version, and validation scope.

Assisted by Codex (gpt-6.1-sol).

@viberaven

Copy link
Copy Markdown
Contributor Author

Fixed the test_scenario (default) build failure in 55f0eb4.

The pinned nixpkgs electrs 0.12.0 derivation lacks pkg-config, which zstd-sys invokes to locate system zstd. Added pkg-config to native build inputs and zstd to build inputs through the bitcoinix package override. Generated pins, locked inputs, and package versions are unchanged. The override has a removal TODO for when nixpkgs supplies these inputs.

Local validation passed:

  • Built electrs from source, including all nine package tests.
  • Reran the complete default VM scenario successfully.
  • All-system flake evaluation (nix flake check --all-systems --no-build).
  • Generated-version consistency and git diff --check.

Assisted by Codex (gpt-6.1-sol).

@prusnak

prusnak commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

The pinned nixpkgs electrs 0.12.0 derivation lacks pkg-config,

fixed in NixOS/nixpkgs#585046

let's wait until the fix hits nixos-unstable - see https://pr.bitcoinix.net/?pr=585046 - and then rebase dropping the patch

@seberm seberm added type: maintenance No user-visible change: refactor, CI, deps, tooling, docs-only breaking Changes existing user config; needs a versioning.nix entry labels Nov 9, 2026
@viberaven

Copy link
Copy Markdown
Contributor Author

Rebased onto current master (8d8a87f), including #245 and the subsequently merged #239.

For #245, preserved the switch to nixpkgs RTL, TrustedCoin, Trezor, and Lightning Python packages. The removed local derivations stay removed. The Python package set now uses the single unstable pkgs input and its matching interpreter. TrustedCoin's startup patch is applied to pkgs.trustedcoin with overrideAttrs, retaining nixpkgs' source, static-build settings, and package path. The electrs build-input override remains in place.

Kept clnrest's package-only rename in release notes and its config-version notice/test removed. Updated the new package release notes and developer guidance for the single input, and linked the 0.1.6 system migration from the release notes. Regenerated with helper/update-flake.sh -f --refresh; the generated files reproduce.

Validation passed: nix flake check --all-systems, all four x86_64 check builds, default, netns, netnsRegtest, and trustedcoin VM scenarios, shellcheck, generated-version checks, and mdBook. Both namespace scenarios were rerun after #239, including the new br_netfilter reachability checks. Evaluated that RTL, Trezor, and the Lightning Python packages match their nixpkgs derivations. ARM was evaluated only; other VM and deployment/container scenarios were not rerun for this rebase.

Assisted by Codex (gpt-6-astra).

@github-actions github-actions Bot added the type: removal Module, package or option dropped (implies breaking) label Nov 10, 2026
@viberaven

Copy link
Copy Markdown
Contributor Author

Simplified package selection and aligned this PR with its existing v0.2.0 milestone in a526123.

  • Removed generated pkgs/pinned.nix and its generation/checking machinery. The selection and overrides now live together in pkgs/default.nix; version reporting reads that actual selection. Public .pinned paths are preserved, and pkgs/nixpkgs-pinned.nix remains for non-flake entry points.
  • Moved this PR's migration notices, upgrading guide, main example configVersion, and release notes to 0.2.0. Kept use the pinned nixpkgs packages #245's inherited package changes under 0.1.6. Migration tests now verify that 0.1.6 still requires acknowledgement and 0.2.0 accepts it.
  • Updated contributor guidance and the PR description.

Validation: all 14 pinned and 19 module package derivation paths match the previous head on both x86_64-linux and aarch64-linux. The refresh helper leaves the lock file and version metadata unchanged. nix flake check --all-systems, all four x86_64 check builds, version consistency, shellcheck, mdBook, and git diff --check pass. VM tests were not repeated for this package-preserving cleanup.

Assisted by Codex (gpt-6-astra).

@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.

I ran this through Fable 5.2 (xhigh), GPT-6 Astra (max), Kimi K3.1 Pro (max, two passes), DeepSeek V4.1 Flash 1017 (max) and GLM 5.3 (max). Astra and K3.1 found nothing. I checked the other findings against the code, and these five hold up.

  1. The packages master takes from the separately locked unstable input (btcpayserver clboss clightning electrs fulcrum lnd lndinit nbxplorer rtl trustedcoin in pkgs/pinned.nix) now come from the one pkgs. So they follow the system's own nixpkgs in three setups:

    • Non-flake imports. modules/nix-bitcoin.nix passes the system pkgs to pkgs/default.nix, and useVersionLockedPkgs isn't declared there. On master the pkgsUnstable default in pkgs/default.nix still locked these packages.
    • nix-bitcoin.useVersionLockedPkgs = false, which the 0.2.0 notice suggests for keeping overlays.
    • Flakes that set bitcoinix.inputs.nixpkgs.follows.

    A routine update of the user's nixpkgs can then move lnd or clightning to a release bitcoinix hasn't tested, or back to an older one that refuses the newer database. The 0.2.0 notice says service packages use the locked revision, but that isn't true without flakes. I'd at least say this in the notice and in docs/upgrading.md.

  2. Systems that follow bitcoinix's nixpkgs also pick up unstable's new NixOS defaults, and the 0.2.0 section of docs/upgrading.md doesn't name them. Two of them matter on a node. networking.firewall.checkReversePath goes from true to "loose", and programs.fuse.enable goes from on to off, so an operator's own non-root FUSE mounts, like an sshfs backup target, lose fusermount. This PR turns FUSE on only for replication.

  3. examples/container/flake.nix doesn't add --system-call-filter=@memlock, but examples/deploy-container.sh and test/lib/make-test.nix do. A new user who starts from that example and enables clightning gets the lightning_hsmd abort that the notice describes.

  4. .github/cve-whitelist.toml asks to re-check its exceptions when nixpkgs is updated, and its header still points to the review against the old pins. This PR is that update, so the exceptions need a check against f4a03c0.

  5. services.i2pd.checkConfig = mkDefault false in modules/netns-isolation.nix turns off i2pd's build-time check for every netns node with I2P. A typo in custom services.i2pd.settings then shows up only at runtime. The i2p and i2pLocal scenarios cover the generated config, but the description doesn't list them among the scenarios rerun after the rebase.

Nothing here puts funds at risk. lnd 0.21.6 and clightning 26.06.10 are the same at both pins, the i2pd settings keep the 26.05 exposure, and the trustedcoin patch matches v0.8.7.

@prusnak
prusnak merged commit 0d12e6c into bitcoinix:master Nov 16, 2026
27 checks passed
prusnak added a commit that referenced this pull request Nov 18, 2026
… store (#266)

Fixes #64.

`bitcoin.conf` is built with `builtins.toFile`. So the
`rpcauth=<name>:<salt>$<hmac>` line of every custom RPC user in
`services.bitcoind.rpc.users` ends up in the world-readable Nix store.
Any local user can read the salt and HMAC and test password guesses
offline. A long random password is safe. A weak one isn't. The
`passwordHMAC` description didn't say so, and the docs didn't cover
custom RPC users at all.

This PR documents the risk. It doesn't change behavior.

- The `passwordHMAC` description now says that the value goes to the Nix
store, and advises a long random password, like the one that Bitcoin
Core's `share/rpcauth/rpcauth.py` generates when you don't pass a
password.
- The LAN RPC section of `docs/configuration.md` gets a short custom RPC
user example with the same warning. It also covers `rpcauth` lines in
`extraConfig`, which land in the store too. And it says to change a weak
password, because the old HMAC stays in the store until it is
garbage-collected.
- A 0.2.0 release note points existing users to that section.

The built-in users `privileged`, `public` and `btcpayserver` read their
HMAC from the secrets dir, so they aren't affected.

Keeping a custom user's HMAC out of the store is possible, with a public
`passwordHMACFromFile` that declares a `bitcoin-HMAC-<name>` secret. But
that's a new feature: secret generation doesn't create the file, and the
docs need steps to provide it. I left it for a follow-up.

## Testing

- `nix eval .#ciTestInfo`: pass
- `nix build .#checks.x86_64-linux.module-config`: pass
- `nix build .#checks.x86_64-linux.test-runner`: pass
- `mdbook build`: pass. The new text renders, and the release note link
resolves to the `allow-bitcoind-rpc-connections-from-lan` heading.
- The evaluated `passwordHMAC` description shows the new text.

No VM test, because nothing changes at runtime.
- After the rebase onto master 0d12e6c, `module-config`, `test-runner`,
`ci-workflows` and the mdBook build pass on the KVM host.

## Models

Claude Opus 5.5 wrote the change. Codex GPT-5.6 Sol, Codex GPT-6 Astra
(two passes), Kimi K3.1 Pro (two passes), DeepSeek V4.1 Flash 1017 and
GLM 5.3 reviewed it. Claude Opus 5.5 rebased it onto #224.
prusnak added a commit that referenced this pull request Nov 18, 2026
…s funds (#274)

Part of #87.

With `services.btcpayserver.lightningBackend = "clightning"`, BTCPay
Server joins the
clightning group and talks to lightningd over its RPC socket
`lightning-rpc`. The socket
allows every method. So BTCPay Server can pay invoices (`pay`, `xpay`),
withdraw on-chain
funds (`withdraw`), open and close channels (`fundchannel`, `close`) and
start plugins
(`plugin`), which run as the clightning user. A bug in BTCPay Server, a
malicious BTCPay
plugin or a stolen admin session can drain the node.

With `lnd`, BTCPay Server gets its own macaroon
(`services.lnd.macaroons.btcpayserver`).
It can read the node's state and create invoices and addresses, but it
can't send funds
or open or close channels.

Neither the option nor the docs said this. This PR changes no behavior.
It adds these docs.

- The access of each backend in the `lightningBackend` option
description, with a
  recommendation to use `lnd` when BTCPay Server should be limited.
- A BTCPay Server section in `docs/services.md` with the same facts and
the reason. It
also says that with clnrest enabled, the clightning group can read
clnrest's admin rune.
- A note at the clightning backend in `examples/configuration.nix`.
- A 0.2.0 release note that points to the new section, so existing users
see it.

The second commit adds two notes that the red-team review found. The
backend limits only
the Lightning node, so BTCPay Server can spend a hot wallet with either
backend. And
bitcoinix turns on Core Lightning for BTCPay Server only while it's the
backend. So before
a node with Core Lightning channels switches to `lnd`, it needs
`services.clightning.enable = true` and another lnd port, or its
channels closed.

bitcoinix can't give BTCPay Server a restricted rune today. BTCPay
Server 2.4.7 uses
BTCPayServer.Lightning 1.7.14. Its Core Lightning client accepts only
`type=clightning;server=unix://...` or `tcp://...` and sends raw
JSON-RPC. It has no
clnrest or rune support.

It needs no versioning notice, since nothing changes at runtime.

## Not in this PR

The fix for the access itself stays open in #87. I believe there are two
ways to fix it.

- A method allowlist in front of `lightning-rpc` for BTCPay Server.
Receiving payments
needs `invoice`, `listinvoices`, `waitanyinvoice`, `getinfo` and
`delinvoice`. The
  Lightning node page and payouts need more, including `xpay`.
- Rune support in BTCPayServer.Lightning upstream, so bitcoinix can
connect BTCPay Server
  through clnrest with a restricted rune.

## Testing

- `nix eval .#ciTestInfo` passes.
- `nix build .#checks.x86_64-linux.module-config` and
`.#checks.x86_64-linux.test-runner` pass.
- `nix shell --inputs-from . nixpkgs#mdbook -c mdbook build` succeeds.
The new section and
  its link to Custom macaroons render.
- No VM run, because nothing changes at runtime.
- After the rebase onto master 0d12e6c, `module-config`, `test-runner`,
`ci-workflows` and the mdBook build pass on the KVM host.

## Models

Claude Opus 5.5 wrote the change. Codex GPT-5.6 Sol, Codex GPT-6 Astra
(two passes plus rechecks), Kimi K3.1 Pro (two passes), DeepSeek V4.1
Flash 1017 and GLM 5.3 reviewed it. Claude Opus 5.5 rebased it onto
#224.
prusnak added a commit that referenced this pull request Nov 18, 2026
#268)

Fixes #128.

The btcpayserver user is in NBXplorer's group, because BTCPay Server
reads NBXplorer's API cookie (`/var/lib/nbxplorer/<network>/.cookie`).
But the secret `bitcoin-rpcpassword-btcpayserver`, NBXplorer's bitcoind
RPC password, had the same group and the default mode `0440`. So BTCPay
Server could read the password, although it never uses it.

The secret now belongs to NBXplorer's user, with mode `0400`. Only
NBXplorer reads it, in its `preStart`. bitcoind reads only
`bitcoin-HMAC-btcpayserver`, which doesn't change. The group still gives
BTCPay Server the cookie. `setup-secrets` and nixops apply the new owner
and mode on the next deployment.

A program that read the password through the group, or as the `bitcoin`
user, now fails. So config version 0.2.0 gets a notice for configs with
BTCPay Server, and `docs/upgrading.md` says what to do. It also says how
to replace the password if BTCPay Server was compromised. Users who
manage the secret files outside bitcoinix have to change this one by
hand. The notice targets 0.2.0, the lowest open milestone.

## Testing

The `btcpayserver` VM test now checks that the password file is
`nbxplorer`-owned with mode `0400`, that the btcpayserver user can't
read it, and that it can still read NBXplorer's cookie. Before this
change, the first two checks fail.

- `regtest`: passes. NBXplorer still connects to bitcoind, and BTCPay
Server's `/api/v1/health` reports `synchronized`, so BTCPay Server still
authenticates to NBXplorer with the cookie.
- `default`: passes.
- `ciTestInfo`, `checks.x86_64-linux.module-config` and
`checks.x86_64-linux.test-runner`: pass.
- Evaluation: a BTCPay Server config at config version 0.1.6 gets the
notice, which names the configured NBXplorer user. On master it's a
warning. A config without BTCPay Server gets no notice.
- `mdbook build`: passes, and the release note links to the new
upgrading section.

## Not in this PR

- NBXplorer's RPC proxy (`POST /v1/cryptos/BTC/rpc`) still lets the
cookie holder call the methods NBXplorer allows without `exposerpc`, for
example `sendrawtransaction` and `gettxout`. This PR removes BTCPay
Server's direct access to the rest of the whitelist and its copy of the
credential.
- NBXplorer's data dir is `0770 nbxplorer:nbxplorer`, so the
btcpayserver user can write there. That could be its own issue.
- After the rebase onto master c3d955c (#283), `module-config`,
`test-runner`, `ci-workflows` and `regtest` pass on the KVM host. On
master, the notice is a warning until 0.2.0 is released, and the tests
pass with `version.nix` at 0.1.6 and at 0.2.0.

## Models

Claude Opus 5.5 wrote the change. Codex GPT-5.6 Sol, Codex GPT-6 Astra
(two passes), Kimi K3.1 Pro (two passes), DeepSeek V4.1 Flash 1017 and
GLM 5.3 reviewed it. Claude Opus 5.5 rebased it onto #224 and #283.
prusnak added a commit that referenced this pull request Nov 18, 2026
…ervice (#273)

Fixes #132.

The `secure-node.nix` preset always publishes sshd as an onion service,
but nothing in `modules/` turned off SSH password login. Only the
example configs did. NixOS allows passwords by default. So a config that
imports the preset into an existing setup let anyone with the onion
address try passwords over Tor. This includes the operator, who is in
the groups that control funds (`bitcoin`, `clightning`, `lnd`).

The preset now sets `services.openssh.settings.PasswordAuthentication`
and `KbdInteractiveAuthentication` to `mkDefault false`. sshd then
accepts only keys, over the onion service and over the node's IP
address. A config that needs passwords can still set either option to
`true`.

This can lock out an account that logs in with a password, so it comes
with a 0.2.0 notice. It fires for every config that uses the preset and
enables sshd. A narrower condition would need to tell how the config
defines the two options, and every way to do that missed some affected
configs. A missed notice can lock the operator out of the node, and a
needless one only costs a config version bump. The notice and the
upgrade notes say that nothing changes for a config that already sets
both options to `false`, like the flakes and Colmena examples.

Keyboard-interactive login through PAM depends on the PAM module,
because NixOS sets `security.pam.services.sshd.unixAuth` from
`PasswordAuthentication`. I checked sshd's PAM stack in the pinned
nixpkgs:

- `googleAuthenticator`: without `unixAuth`, the stack is only
`pam_deny`, so such setups need both options set back to `true`. With
`services.homed.enable`, NixOS adds the rule without `unixAuth`.
- `otpwAuth`: with `unixAuth`, a `sufficient pam_unix` rule comes before
`pam_otpw`, so a plain password would skip the one-time password. Such
setups need only `KbdInteractiveAuthentication = true`.

The upgrade notes say this and tell users to test a new login before
they close their session.

A config that sets one of the options to `true` with `lib.mkDefault`
fails evaluation with "conflicting definition values", because the
preset uses the same priority. This happens at any config version,
before the notice shows. The upgrade notes say to set the option without
`lib.mkDefault`.

Docs:
- `docs/upgrading.md`: a 0.2.0 entry with the check, the PAM case, the
conflict error and the way back.
- `docs/release-notes.md`: a 0.2.0 entry.
- `docs/introduction.md` and the SSH onion service section of
`docs/services.md` now say that the preset turns off SSH password login.

Nothing else in the repo uses SSH password login. The tests, the QEMU
and krops deployment scripts and the deployment examples all log in with
keys. The preset doesn't change `PermitRootLogin`, so root keeps the
NixOS default `prohibit-password`.

## Testing

- `nix build .#checks.x86_64-linux.module-config` passes. Two new tests:
- `testSecureNodeSshKeysOnly`: the preset gives `false` for both
options, an explicit `true` wins, and without the preset both stay
`true`. It fails with the preset from master.
- `testVersioningSecureNodeSshPasswords`: the notice fires with the
preset and sshd, not with sshd disabled, not without the preset, and not
for a 0.2.0 config once 0.2.0 is released.
- `nix build .#checks.x86_64-linux.test-runner` passes.
- `nix eval .#ciTestInfo` passes.
- `./test/run-tests.sh -s secureNode` passes.
- A config with the preset and `PasswordAuthentication = lib.mkDefault
true` fails with "conflicting definition values" before and after 0.2.0
is released.
- After the rebase onto master c3d955c (#283), `module-config`,
`test-runner`, `ci-workflows` and `secureNode` pass on the KVM host.
`acknowledged` replaces `current`, because master now rejects config
version 0.2.0 before the release. It checks that a config at 0.2.0
doesn't get the notice once 0.2.0 is released. On master, the notice is
a warning until 0.2.0 is released, and the tests pass with `version.nix`
at 0.1.6 and at 0.2.0.

## Models

Claude Opus 5.5 wrote the change. Codex GPT-5.6 Sol, Codex GPT-6 Astra
(two passes plus rechecks), Kimi K3.1 Pro (two passes), DeepSeek V4.1
Flash 1017 and GLM 5.3 reviewed it. Claude Opus 5.5 rebased it onto #224
and #283. Kimi K3.1 Pro (two passes) and Claude Fable 5.2 reviewed the
second rebase.
prusnak added a commit that referenced this pull request Nov 18, 2026
Fixes #124.

Two documented steps left users with a recovery file that recovers
nothing.

When lnd starts without a wallet, as after the first deploy,
`modules/lnd.nix` creates a new wallet and writes its seed to
`lnd-seed-mnemonic` in lnd's data dir. "Migrate existing services to
bitcoinix" in `docs/configuration.md` copies the old data dir with
`rsync -a`, which keeps that file. lnd reads the file only to create a
wallet, so nothing notices that it doesn't match the migrated wallet.
And `examples/configuration.nix` says to back it up as the wallet seed.

With `nix-bitcoin.generateSecrets`, `services.backups` includes the
secrets dir, and with it `backup-encryption-password`, the password that
decrypts the backups. No copy of it exists outside the node and the
backups. So when the node's disk dies, the backups can't be decrypted.

This PR changes only docs and one option description:

- The lnd step of the migration section says to copy `lnd-seed-mnemonic`
off the node and remove it before the copy, and to keep that copy if the
new wallet got funds, because the migration replaces that wallet. It
says the seed of a migrated wallet is the seed of the old node. Users
who migrated before get a paragraph on how to tell which seed the file
holds.
- The lnd backup note in `examples/configuration.nix` says that
bitcoinix creates the seed file only with a new wallet, and points to
the migration section.
- The backups section of `examples/configuration.nix` and the
description of `services.backups.enable` say to keep a copy of
`backup-encryption-password` off the node. The example uses the default
secrets dir and says so.
- A 0.2.0 release note points users who already migrated or already run
backups to these steps.

There's no backups page under `docs/`, so the example config and the
option description are where the backups are documented.

## Testing

- `nix eval .#ciTestInfo` passes.
- `nix build .#checks.x86_64-linux.module-config` passes.
- `mdbook build` passes on the final head, and the built
`configuration.html` has the new lnd step.
- No VM test, because nothing changes at run time.
- After the rebase onto master 0d12e6c, `module-config`, `test-runner`,
`ci-workflows` and the mdBook build pass on the KVM host.

## Models

Claude Opus 5.5 wrote the change. Codex GPT-5.6 Sol, Codex GPT-6 Astra
(two passes plus rechecks), Kimi K3.1 Pro (two passes), DeepSeek V4.1
Flash 1017 and GLM 5.3 reviewed it. Claude Opus 5.5 rebased it onto
#224.
prusnak added a commit that referenced this pull request Nov 18, 2026
Fixes #127.

clightning added `getblockfrompeer` and mempool added `gettxoutsetinfo`
to the whitelist of
the shared `public` RPC user. `rpcwhitelist` is a list option, so the
module system merged
both into one list for `public`, and every service that connects as
`public` got them. With
mempool enabled, electrs, fulcrum and lnd could call `gettxoutsetinfo`,
which walks the whole
UTXO set and can keep bitcoind busy for minutes. BTCPay's user builds on
the public list, so
it got `gettxoutsetinfo` too. The comment in
`bitcoind-rpc-public-whitelist.nix` said each
module grants these methods to itself, which only btcpayserver did.

This PR gives clightning and mempool their own RPC users, as
btcpayserver has:

- `clightning`: the public whitelist plus `getblockfrompeer` when bcli
is the backend. With
  trustedcoin, it's the public whitelist alone.
- `mempool`: the public whitelist plus `gettxoutsetinfo`.
- An empty `rpcwhitelist` disables whitelisting for its user. So when
the public
whitelist is empty, both new whitelists stay empty too, and the services
keep the
  unrestricted access they had through `public`.
- Each user gets its own generated password and HMAC
(`bitcoin-rpcpassword-<user>`,
  `bitcoin-HMAC-<user>`), owned like the btcpayserver ones.
- clightning and mempool connect as their new users and leave the
`bitcoinrpc-public`
  group, since they no longer read its password.
- The `public` user keeps only the base whitelist. BTCPay's whitelist is
now the base list
plus `getblockfrompeer`, which is what nbxplorer probes for. It never
needed
  `gettxoutsetinfo`.

The pinned trustedcoin 0.8.7 reads `bitcoin-rpcuser` and
`bitcoin-rpcpassword` from
lightningd and calls `getblockchaininfo`, `getblockhash`, `getblock`,
`getrawtransaction`,
`estimatesmartfee` and `sendrawtransaction`. All of them are in the base
list, so it keeps
working with the `clightning` user. It still logs that password at
startup (#191), but now
it's the password of the clightning user, not the one that electrs,
fulcrum and lnd share.
The other clightning plugins don't talk to bitcoind.

## Migration

A 0.2.0 notice fires for every config that enables clightning or
mempool. No option
marks a bitcoind on another node, since the `bitcoind-remote.nix` preset
only changes the
bitcoind unit. And configs that supply their own secrets have to act
either way. So the
text depends on the config instead. With `nix-bitcoin.generateSecrets`,
it says there's
nothing else to do when bitcoind runs on the node. Otherwise it says to
create the new secrets first.
For a bitcoind on another node, it lists the whitelists to set there. It
also says to
remove `getblockfrompeer` and `gettxoutsetinfo` from the remote public
user if it has
them, whatever the new config enables, since the old config may have
added them. With
BTCPay Server, it says to set the remote BTCPay user's whitelist again,
since that list
builds on the public one and had `gettxoutsetinfo` with mempool.

The released 0.1.5 notice for mempool's RPC password told users to save
the password
to `bitcoin-rpcpassword-public`. Notices are evaluated against the
current code, which
reads `bitcoin-rpcpassword-mempool`, so it now names that file. So does
the 0.1.5 section
of `docs/upgrading.md`, which also says that releases before 0.2.0 read
`bitcoin-rpcpassword-public`.

`docs/upgrading.md` says what each setup has to do. The guide for a
bitcoind on another
node in `docs/configuration.md` now lists the new users, their
whitelists, their
password files, and the local HMAC files that setup checks.

The migration tests for the currencyrate and rebalance plugins and for
mempool's RPC
password stay as master has them. Once 0.2.0 is released, later notices
block every
older config there, so a new test checks the 0.1.5 notices by their
message.

## Testing

- `test/configuration.nix`: new checks that `public` has neither method,
`clightning` and
`btcpayserver` have only `getblockfrompeer`, `mempool` has only
`gettxoutsetinfo`, and
`clightning` with trustedcoin has neither. With an empty public
whitelist, both new
  whitelists are empty. Also that both services read their own
password and aren't in `bitcoinrpc-public`, and what the notice says for
which config,
  including the remote public and BTCPay whitelists.
- `test/suite/security.py`, test `rpc-whitelist`: `public` can't call
either method, and
each service user can call only its own. Before this change, `public`
could call
  `gettxoutsetinfo` in the `regtest` scenario.
- `module-config` and `test-runner` checks pass, and the mdBook build
succeeds.
- `regtest` scenario passes. The bitcoind log shows `public` refused
`gettxoutsetinfo` and `getblockfrompeer`, `mempool` refused
`getblockfrompeer`, and
  `clightning` and `btcpayserver` refused `gettxoutsetinfo`.
- `trustedcoin` scenario fails, as it does on master 772846d.
trustedcoin logs
`bitcoind RPC working` as user `clightning`, and `rpc-whitelist` passes:
`clightning`
is refused `getblockfrompeer` and `gettxoutsetinfo`. The failure is a
startup race in
trustedcoin, unrelated to this change. When clightning restarts right
after bitcoind,
lightningd asks for the chain tip before trustedcoin's `OnInit` has set
up its
bitcoind client. trustedcoin then falls back to block explorers, which
the VM can't
reach, returns `tip: 0`, and lightningd exits with `bitcoind has gone
backwards`.
  The start then hangs in clightning's `postStart` until it times out.
- After the rebase onto master c3d955c (#283), `module-config`,
`test-runner`, `ci-workflows`, `regtest` and `trustedcoin` pass on the
KVM host. `acknowledged` replaces `current`, because master now rejects
config version 0.2.0 before the release. It checks that a config at
0.2.0 doesn't get the notice once 0.2.0 is released. On master, the
notice is a warning until 0.2.0 is released, and the tests pass with
`version.nix` at 0.1.6 and at 0.2.0. Deleting a 0.1.5 notice fails
`testMigrationNotices015` with `version.nix` at 0.1.6 and at 0.2.0.

## Models

Claude Opus 5.5 wrote the change. Codex GPT-5.6 Sol, Codex GPT-6 Astra
(two passes plus rechecks), Kimi K3.1 Pro (two passes), DeepSeek V4.1
Flash 1017 and GLM 5.3 reviewed it. Claude Opus 5.5 rebased it onto #224
and #283. Kimi K3.1 Pro (two passes) and Claude Fable 5.2 reviewed both
rebases.
prusnak added a commit that referenced this pull request Nov 18, 2026
Fixes #123.

This is hardening of the data dir route. The RPC socket already lets
every member of the clightning group run code as the clightning user,
for example with `plugin start`. Taking BTCPay Server off the socket is
#87. The bitcoind and lnd data dirs stay `0770`, because only the
operator joins those groups.

The Core Lightning data dir had mode `0770`, so every member of the
clightning group could create, rename and delete entries in it. The
group holds the operator user when `nix-bitcoin.operator.enable` is set,
the btcpayserver user with `services.btcpayserver.lightningBackend =
"clightning"`, and any user you add. A member could rename its own file
over `config` after `preStart` wrote it and before lightningd read it,
and make lightningd load a plugin as the clightning user. Or it could
move the network dir aside and plant one with its own `hsm_secret`.

Group members only need to pass through the data dir to reach the RPC
socket and to read `config`, so the dir is now `0750`. The tmpfiles rule
sets this mode on existing nodes at the next deployment. lightningd
creates the network dir with mode `0700`, and `postStart` adds only
`g+x`. So the RPC socket is the only entry under the data dir that the
group can write. I checked each user of the group: BTCPay Server,
`lightning-cli`, `lnconnect-clnrest`, nodeinfo, RTL's root scripts, the
clnrest rune, the plugins and replication. None of them writes to the
data dir as a group member.

A script that writes to the data dir as a group member now fails. So
config version 0.2.0 gets a notice for configs with clightning.
`docs/upgrading.md` explains the change and how to list entries that a
group member created. The release notes get a 0.2.0 entry.

Tests:

- The `clightning` test checks the data dir's owner, group and mode. It
checks that the RPC socket is the only entry the group or others can
write, and that every entry belongs to the clightning user. For each
member of the clightning group, it checks that `lightning-cli getinfo`
works and that creating a file in the data dir fails.
- The new scenario `btcpayserverClightning` runs BTCPay Server on the
clightning backend. It's in the CI matrix. The `btcpayserver` test
checks lnd's macaroon only with the lnd backend. The Greenfield request
in the `regtest` test reaches clightning through the socket.
- `config-replace` plants its symlink as the clightning user, because
the operator can't write the data dir anymore.
- `module-config` checks which configs get the notice.

## Testing

On an x86_64-linux KVM host:

- `./test/run-tests.sh -s btcpayserverClightning`: pass on the final
head
- `./test/run-tests.sh -s regtest`, `-s default` and `-s
lnconnectNoOperatorRole`: pass on the previous head. Since then only the
test's quoting and member loop and the docs changed.
- `nix eval .#ciTestInfo`: pass, and it lists `btcpayserverClightning`
- `nix build
.#checks.x86_64-linux.{module-config,test-runner,ci-workflows,lnd-macaroon-filters}`:
pass
- `./test/shellcheck.sh`: pass
- `systemd-tmpfiles --create` with a `d <dir> 0750` rule changes an
existing `0770` dir to `0750`, as on an upgraded node.

I didn't run `netns` and `netnsRegtest`. CI runs them.
- After the rebase onto master c3d955c (#283), `module-config`,
`test-runner`, `ci-workflows`, `shellcheck` and `btcpayserverClightning`
pass on the KVM host. This PR doesn't change master's plugin migration
checks. On master, the notice is a warning until 0.2.0 is released, and
the tests pass with `version.nix` at 0.1.6 and at 0.2.0.

## Models

Claude Opus 5.5 wrote the change. Codex GPT-5.6 Sol, Codex GPT-6 Astra
(two passes plus a recheck), Kimi K3.1 Pro (two passes), DeepSeek V4.1
Flash 1017 and GLM 5.3 reviewed it. Claude Opus 5.5 rebased it onto #224
and #283.
prusnak added a commit that referenced this pull request Nov 18, 2026
…278)

Fixes #131.

BTCPay Server makes the first account that registers the server admin.
That account can
use the internal Lightning node and install plugins. bitcoinix started
BTCPay with no
admin, so until the operator registered, any local user, or a service
that can reach the
port, could register first and take it. The window also covers the onion
service and any
LAN or WireGuard address.

BTCPay 2.4.7 has no setting that closes it:

- There's no option, environment variable or CLI flag to create the
first admin or to
  require a token or an invite for it.
- `disable-registration` (default true) locks registration only once the
first admin
  exists.
- Turning `LockSubscription` on before that blocks the web form, but not
`POST /api/v1/users`. While no admin exists, BTCPay treats an anonymous
caller of the
Greenfield API as an admin and lets it create one. The regtest test used
exactly this
  request until now.

At the network level, loopback can't tell local users apart.
`IPAddressAllow` filters by
address. netns-isolation lets every process in the host namespace reach
the service
namespaces through the bridge. A UID owner match in the firewall would
need an allow list
of every client (the operator's SSH tunnel, Tor, a reverse proxy) for
both iptables and
nftables. BTCPay binds only to an address and port, so a Unix socket
would mean a new
listener setup and would break the onion service and existing tunnels.

So this PR creates the admin before BTCPay opens its port:

- A new oneshot unit `btcpayserver-admin` runs before each start of
`btcpayserver`. If the
  database has an admin, it exits.
- Otherwise it starts BTCPay in a private network namespace
(`PrivateNetwork`), bound to
`127.0.0.1`, which no other process can reach. It creates
`admin@localhost` through the
Greenfield API with the password in the new secret
`btcpayserver-admin-password`, then
  stops BTCPay. BTCPay then locks registration.
- `btcpayserver` requires the unit, so it doesn't start when the admin
can't be created.
- The secret belongs to `services.btcpayserver.user` and `.group`, so a
custom user or
  group works with `setup-secrets`.
- The setup instance's API URL follows `services.btcpayserver.rootpath`,
with `/` and a
  trailing `/` treated like BTCPay does.
- The BTCPay config is now a function of the bind address, because
BTCPay binds to every
  `bind` in its config file and on its command line.
- Nodes that already have an admin keep it and don't run the setup
instance.

Nodes that ran without an admin before this change may already have an
admin that isn't
the operator's. The docs say how to check the admins in Server Settings
> Users. An admin
that isn't yours could have installed plugins that run as the
`btcpayserver` user and
use the Lightning node, so the docs say to treat the node as
compromised: stop BTCPay
Server, move the funds to a wallet this node doesn't control and set up
the node again.
They give no in-place recovery steps.

Docs: a new "Connect to BTCPay Server" section with "Check the admin
accounts" in
`docs/services.md`, the 0.2.0 upgrade notes and release notes, the
example config and
the BTCPay recipe in `dev/dev-features.sh`. The old warning in
`examples/configuration.nix`
about creating the admin before enabling the onion service is gone,
since the admin now
exists first.

The 0.2.0 notice is for every node with BTCPay. Nodes without an admin
now sign in with
the generated account instead of registering. Nodes with an admin should
check that it's
theirs. Setups that supply their own secrets must add the new one.

## Testing

The `btcpayserver` VM test now checks that:

- `btcpayserver-admin` runs with `PrivateNetwork`.
- `admin@localhost` with the generated password is a `ServerAdmin`.
- An anonymous `POST /api/v1/users` gets 401, with and without
`isAdministrator`.
- `/register` redirects.

Before this change, the anonymous request created the first admin. The
regtest test
relied on it. That test now signs in as the generated admin for its
Greenfield request.
BTCPay accepts Basic auth only in an account's first five minutes, so a
test helper
resets the account's creation time before each request.

New eval tests in `test/configuration.nix`:

- With a custom user and group, the secret's owner is that user and
group, and both
  exist.
- The health URL of the setup instance for `rootpath` null, `/`,
`btcpay`, `/btcpay` and
  `btcpay/`.

Results:

- `regtest` VM scenario: pass.
- `netnsRegtest` VM scenario: pass on an earlier revision of this
branch, without the
last fixes. That run checked the `bind` handling in a service namespace:
the config
file's `bind` is the namespace address, so the setup instance gets its
own config with
`bind=127.0.0.1`. An earlier version passed `--bind=127.0.0.1` on the
command line and
  failed in both scenarios.
- The `shellcheck-services` build in the VM scenarios covers the new
unit script.
- `checks.x86_64-linux.module-config` and
`checks.x86_64-linux.test-runner`: pass.

Not tested: the mainnet scenarios, a running node with `rootpath`, and a
rerun of
`btcpayserver-admin` on a node that already has an admin.
- After the rebase onto master c3d955c (#283), `module-config`,
`test-runner`, `ci-workflows`, `shellcheck` and `regtest` pass on the
KVM host. On master, the notice is a warning until 0.2.0 is released,
and the tests pass with `version.nix` at 0.1.6 and at 0.2.0.

## Models

Claude Opus 5.5 wrote the change. Codex GPT-5.6 Sol, Codex GPT-6 Astra
(two passes plus rechecks), Kimi K3.1 Pro (two passes), DeepSeek V4.1
Flash 1017 and GLM 5.3 reviewed it. Claude Opus 5.5 rebased it onto #224
and #283.
prusnak added a commit that referenced this pull request Nov 18, 2026
#267)

Fixes #67.

Without a host, `nix-bitcoin-wg-connect` ran `lndconnect` to find the
node's external IP. `lndconnect` does this through `go-external-ip`,
which queries third-party IP lookup services over clearnet. That
revealed the node's public IP to them, also on a node that otherwise
uses only Tor. #201 documented the lookup, but the command still did it.

This makes the host required. Without it, the command prints a usage
message and exits with status 1:

```
Usage: nix-bitcoin-wg-connect [--text] <host>

<host> is the address where your WireGuard client reaches this node:
its public IP or hostname, or its LAN IP for a client in your local network.
'ip address' lists the node's own addresses. Behind NAT, your router shows
the public IP.
```

The rest of the command works as before. The preset no longer references
the `lndconnect` package.

A call that used to work now fails, so this adds a config version 0.2.0
notice for configs that import the preset
(`modules/versioning/0.2.0/wireguard-connect-host.nix`).
`docs/upgrading.md` and `docs/release-notes.md` get 0.2.0 entries. The
note from #201 in `docs/services.md` now says that the address is
required and how to find it. The dev topic
`dev/topics/lndconnect-and-wireguard.sh` passes a host.

## Testing

- `wireguard-lndconnect` passes. A new subtest runs the command without
a host and checks that it fails with the usage message and prints no
config.
- `checks.x86_64-linux.module-config` passes. The new
`testVersioningWireguardConnectHost` checks that the notice fires for an
older config with the preset and not without the preset, and that a
config at 0.2.0 doesn't get it once 0.2.0 is released. Without the
notice file, it fails.
- `checks.x86_64-linux.test-runner` and `nix eval .#ciTestInfo` pass.
- `shellcheck` passes on `dev/topics/lndconnect-and-wireguard.sh`.
- The CVE scan node (`test/ci/scan-node.nix`) got `lndconnect` through
the preset before. It now enables `services.lnd.lndconnect.enable`, so
the scan still covers `lndconnect`. It evaluates, with `lndconnect` in
its closure.
- After the rebase onto master c3d955c (#283), `module-config`,
`test-runner`, `ci-workflows`, `shellcheck` and `wireguard-lndconnect`
pass on the KVM host. `acknowledged` replaces `current`, because master
now rejects config version 0.2.0 before the release. It checks that a
config at 0.2.0 doesn't get the notice once 0.2.0 is released. On
master, the notice is a warning until 0.2.0 is released, and the tests
pass with `version.nix` at 0.1.6 and at 0.2.0.

## Models

Claude Opus 5.5 wrote the change. Codex GPT-5.6 Sol, Codex GPT-6 Astra
(two passes), Kimi K3.1 Pro (two passes), DeepSeek V4.1 Flash 1017 and
GLM 5.3 reviewed it. Claude Opus 5.5 rebased it onto #224 and #283.
prusnak added a commit that referenced this pull request Nov 18, 2026
…ory (#275)

Fixes #122.

With `services.clightning.replication.local.directory`, nothing tied
clightning to the disk or share that should hold the replica. Only the
SSHFS setup had a dependency, through `bindsTo` on
`clightning-replication-mounts`. When the mount for a local directory
was missing, tmpfiles created the directory on the filesystem below the
mount point, and clightning wrote the replica there, usually to the
primary disk. With `encrypt`, the mounts service ran `mkdir -p` and
`gocryptfs -init` there too. The node looked healthy, but a failure of
the primary disk took both copies. `docs/services.md` said that
clightning doesn't start while the target is unavailable, which held
only for SSHFS.

This PR adds `RequiresMountsFor` for `local.directory` to
`clightning.service`, and to `clightning-replication-mounts.service`
when `encrypt` is set. systemd then mounts the directory first and
doesn't start these units while the mount fails. A directory on the root
filesystem has no mount to wait for, so it starts as before.

systemd splits `RequiresMountsFor` and `ReadWritePaths` at whitespace,
unquotes each word and expands `%` specifiers. So the module now writes
the directory as a quoted word, with `\` and `"` escaped and `%`
doubled, in both settings. Before, a directory with a space became two
paths, and clightning failed with `226/NAMESPACE`.

systemd can only wait for the mounts it knows, like `fileSystems`
entries, and it doesn't follow symlinks. The docs now say this, with a
`fileSystems` example for an external disk. I didn't add an assertion or
a warning for a `local.directory` outside a declared mount. A replica on
the root filesystem or a ZFS dataset that ZFS mounts itself is valid, so
a check would break or nag valid configs.

clightning now stays down without the mount, so there's a 0.2.0 notice
for local replication, with upgrade notes and a release note. The notice
shows for every local replica directory, also on the root filesystem,
where nothing changes. A condition that reads `fileSystems` would miss
the mounts that systemd knows from elsewhere, like `systemd.mounts`.

## Testing

- `test/configuration.nix`:
- `testReplicationRequiresLocalMounts` checks `RequiresMountsFor` on
both units for a local directory, with and without `encrypt`, and its
absence with SSHFS.
- `testReplicationQuotesLocalDirectory` checks the quoting of a path
with a space, `"`, `\` and `%` in `RequiresMountsFor` and
`ReadWritePaths`.
- `testVersioningReplicationLocalMounts` checks the notice for local
directories and its absence with SSHFS.
- These tests fail without this change. `checks.module-config` (139
tests) and `checks.test-runner` pass.
- `clightning-replication` VM scenario: passes. A new last subtest
switches to a config that declares a `nofail` mount at `/mnt/replica
disk` whose disk is missing. clightning's start fails with result
`dependency`, no replica appears under the mount point, and `systemctl
show` lists the path as one word in `RequiresMountsFor` and
`ReadWritePaths`. Without the mount dependency (checked with
`/mnt/replica`), the switch succeeds and clightning starts anyway.
Without the quoting, systemd ignores `disk` as a relative path, and
clightning fails with `226/NAMESPACE` instead of the dependency. The
subtest fails in both cases.
- `nix eval .#ciTestInfo`: passes.
- The mdBook build passes.
- After the rebase onto master c3d955c (#283), `module-config`,
`test-runner`, `ci-workflows` and `clightning-replication` pass on the
KVM host. `acknowledged` replaces `current`, because master now rejects
config version 0.2.0 before the release. It checks that a config at
0.2.0 doesn't get the notice once 0.2.0 is released. On master, the
notice is a warning until 0.2.0 is released, and the tests pass with
`version.nix` at 0.1.6 and at 0.2.0.

## Models

Claude Opus 5.5 wrote the change. Codex GPT-5.6 Sol, Codex GPT-6 Astra
(two passes plus a recheck), Kimi K3.1 Pro (two passes), DeepSeek V4.1
Flash 1017 and GLM 5.3 reviewed it. Claude Opus 5.5 rebased it onto #224
and #283. Kimi K3.1 Pro (two passes) and Claude Fable 5.2 reviewed the
first rebase.
prusnak added a commit that referenced this pull request Nov 18, 2026
…276)

Fixes #66. Fixes #153.

`services.hardware-wallets` gives Ledger and Trezor devices to group
`hardware-wallets`. Two things bypassed that group:

- Our Trezor rules added `TAG+="uaccess"`.
- systemd's `70-uaccess.rules` adds the same tag to every device in its
hardware wallet hwdb, which includes all Ledger and Trezor devices. In
systemd 262, which master pins, that's `SUBSYSTEM=="usb",
ENV{ID_HARDWARE_WALLET}=="1", TAG+="uaccess"` and the same rule for
`hidraw`.

With the tag, `73-seat-late.rules` has systemd-logind give the user of
the active local session an ACL on the device, also when that user isn't
in the group.

The module also turned on the Trezor Bridge (`services.trezord.enable =
true`). In the pinned nixpkgs, trezord runs as user `trezord`, which
isn't in group `hardware-wallets`. The nixpkgs `51-trezor.rules` set
`GROUP="trezord"`, but our rules come later and replace it. So the
bridge couldn't open the device. Making it work lets every local user
and service use the Trezor through the bridge's HTTP API on
`127.0.0.1:21325`, which has no authentication. Nothing in bitcoinix
uses the bridge. HWI and `trezorctl` open the device directly.

This PR:

- moves our rules to `71-hardware-wallets-ledger.rules` and
`71-hardware-wallets-trezor.rules`, and each rule line now removes the
tag with `TAG-="uaccess"`. udevd sorts the files of `/etc/udev/rules.d`
and systemd's own rules dir together by name. So ours run after
`51-trezor.rules` and `70-uaccess.rules`, and before
`73-seat-late.rules`, which applies the tag. In systemd 260, `TAG-=`
drops the tag from the device's current tags. `73-seat-late.rules`
matches current tags, and logind checks the current tag again before it
sets ACLs on a session switch.
- removes the tag only on the devices our rules give to the group.
systemd's hwdb also lists generic USB serial chips and other wallets,
which no group would get otherwise.
- makes the Ledger rules match every Ledger device in systemd's hwdb:
all products of vendor `2c97`, and the HW.1 and early Nano IDs of vendor
`2581`. They matched only `2c97:0001` before. Real Ledger devices show
other product IDs, for example a Nano S as `2c97:1011`, so the group
didn't get them and the session did.
- adds `services.hardware-wallets.trezorBridge` (default `false`). It
turns on trezord and sets `SupplementaryGroups` on its unit, so a switch
restarts a running bridge with the group. The option description says
what the bridge exposes.
- warns when trezord runs with `trezor` but without the group, since it
then can't open the device. That happens when `services.trezord.enable`
is set directly. The warning stays off when trezord gets the group in
another way: through `users.users.trezord`,
`users.groups.<group>.members`, the unit's `Group` or
`SupplementaryGroups`, or `services.hardware-wallets.group = "trezord"`.
- adds two 0.2.0 notices, upgrade notes, release notes and a paragraph
in the Trezor section of `docs/services.md`. One notice covers session
access for Ledger and Trezor users. The other covers the bridge, for
Trezor users who don't run trezord.

A device that's plugged in while you deploy keeps the session user's ACL
until you unplug it. The upgrade note says so.

A config that turned the bridge off with `services.trezord.enable =
lib.mkForce false` gets the bridge notice too, although nothing changes
for it. Detecting that needs option priority introspection, so this
config only has to bump `configVersion` once more.

## Testing

- New tests in `test/configuration.nix`:
- Every Ledger and Trezor rule line sets the group and removes the
`uaccess` tag. The `2c97` rule matches every product, and the `2581`
rule has the HW.1 IDs.
- trezord is off by default and needs `trezor`. With the bridge on, its
unit has the group.
- The warning appears only when trezord runs with `trezor` but without
the group. It doesn't appear with `trezorBridge`,
`users.users.trezord.extraGroups`,
`users.groups.hardware-wallets.members`, the unit's `Group` or
`SupplementaryGroups` (also as a space-separated string), or `group =
"trezord"`.
  - Each notice fires only for the configs it describes.
- The check build lists the system's udev rules dir, which on NixOS also
holds copies of systemd's rules. It checks that `51-trezor.rules`,
`70-uaccess.rules`, our two files and `73-seat-late.rules` sort in that
order, and that systemd still tags hardware wallets in
`70-uaccess.rules`. It also runs `udevadm verify` on our files.
- These tests fail with our files at `52-`, and with `TAG-="uaccess"`
removed.
- `nix build .#checks.x86_64-linux.module-config` (139 tests) and
`.#checks.x86_64-linux.test-runner` pass.
- `nix eval .#ciTestInfo` passes.
- VM scenario `netns` passes on the final head. It enables
`services.hardware-wallets.trezor` and `ledger` through `full`.

Not tested on a device. I didn't run `udevadm test` against a fake
device in a VM.
- After the rebase onto master c3d955c (#283), `module-config`,
`test-runner`, `ci-workflows` and `netns` pass on the KVM host. On
master, the notice is a warning until 0.2.0 is released, and the tests
pass with `version.nix` at 0.1.6 and at 0.2.0.

## Models

Claude Opus 5.5 wrote the change. Codex GPT-5.6 Sol, Codex GPT-6 Astra
(two passes plus rechecks), Kimi K3.1 Pro (two passes), DeepSeek V4.1
Flash 1017 and GLM 5.3 reviewed it. Claude Opus 5.5 rebased it onto #224
and #283. Kimi K3.1 Pro (two passes) and Claude Fable 5.2 reviewed the
first rebase.
prusnak added a commit that referenced this pull request Nov 18, 2026
…279)

Fixes #95.

The backups service copied the whole lnd and Core Lightning data dirs
while the daemons ran. So the backup had lnd's `channel.db` and Core
Lightning's `lightningd.sqlite3`, copied while the daemons wrote them. A
copy made during a write can be torn. And a node that runs from an
outdated copy can broadcast a revoked channel state. The peer can then
take all funds in that channel. The docs didn't warn against restoring
these files. The bitcoind wallet files were copied live too.

This PR changes three things:

- The filelist leaves out the Lightning channel databases:
- lnd's `graph` dir. In lnd 0.21 it holds `channel.db`,
`sphinxreplay.db` and `wtclient.db`, or `channel.sqlite` and
`lnd.sqlite` with the SQLite backend.
- Core Lightning's `lightningd.sqlite3` and the SQLite files that
`services.clightning.wallet` sets, such as a replica. Each database also
gets a `<file>-*` line for its journal files. Like Core Lightning, the
DSN is split at the first `:` only. A relative path in it starts in the
network dir, and an empty one names no file.
- The gocryptfs dir of an encrypted replica in `local.directory`, which
holds the encrypted database. With SSHFS or encrypted replication, also
the mounts dir `/var/cache/clightning-replication`, which holds the
SSHFS cipher dir and the plaintext mount.

The paths are normalised, because duplicity matches them as strings, so
`./` or `../` would slip through. duplicity also reads each line as a
glob, so `[`, `*` and `?` in a path are escaped as one-char classes.
Only paths under `services.duplicity.root`, normalised too, are listed,
because duplicity aborts the whole backup on a selection outside its
root. These entries come first in the filelist, so `extraFiles` can't
include them. The backup keeps the files for recovery:
`lnd-seed-mnemonic` and `channel.backup` for lnd, and `hsm_secret` and
`emergency.recover` for Core Lightning. lnd and Core Lightning replace
both files atomically, so a live copy of them is safe.
- A new `bitcoind-wallet-backup` unit runs before each backup, like the
PostgreSQL dumps. It runs as the bitcoind user with the usual hardening,
write access only to `/var/lib/bitcoind/wallet-backups`, and network
access only to `localhost` and bitcoind's RPC address. Here's what it
does:
- It removes the files of the last backup. It deletes only the files it
writes, because the dir can also hold other files, like a wallet named
`wallet-backups`.
- If bitcoind runs, it asks it for a consistent copy of each loaded
wallet with `backupwallet`. Each copy goes to `wallet-<sha256 of the
wallet name>.dat.tmp` and is renamed to `wallet-<sha256>.dat` only when
it's complete. The hash keeps the file name short for any wallet name.
`wallet-names.json` maps each copy to its wallet name, so a restore can
find the right file.
- If bitcoind is stopped, it makes no copies, because the wallet files
are consistent then.
- If bitcoind is starting or stopping, or a copy fails, the unit fails,
and so does the `duplicity` unit after the backup.

`bitcoin-cli` runs with `-noconf` and explicit RPC options. The operator
can replace `bitcoin.conf` in the data dir, and a planted config could
make `bitcoin-cli` send the first line of a file it can read to any
address. With the `bitcoind-remote.nix` preset, the wallets are on the
other node, so the unit is masked and the backup doesn't start it. The
live wallet files stay in the backup, because they're the only copy of
wallets that bitcoind doesn't load.
- `docs/services.md` gets a Backups section. It says what the backup
holds and what it leaves out and why. It and the `postgresqlDatabases`
option say not to list Core Lightning's PostgreSQL database, because its
dump is an outdated copy of the channel state. It also says how to
recover Lightning funds: the seed and `channel.backup` for lnd,
`hsm_secret` and `emergency.recover` for Core Lightning, and database
replication for a Core Lightning database that's always current.

The backup no longer covers data it covered before, and the `duplicity`
unit can now fail in new cases. So a 0.2.0 notice tells every config
with backups about both changes. Backups made before this change still
contain the channel databases. The notice and the upgrade notes say to
never restore them.

## Testing

- `test/suite/backups.py` runs two backups while bitcoind and the
Lightning daemons run. Both must have the copy of the loaded test wallet
and no channel database. The test checks that `wallet-names.json` maps
the copy to the wallet. Before the second backup, the test adds a stale
copy, a `wallet.dat` and another file. The second backup must leave out
the stale copy and any `.tmp` file, and the other two files must still
exist. After the backup with bitcoind stopped, the test checks these
things:
  - The backup has no wallet copy.
- It has lnd's `channel.backup` and Core Lightning's
`emergency.recover`, next to the seed and `hsm_secret`.
- `graph/mainnet/channel.db` and `lightningd.sqlite3` exist on disk but
aren't in the backup.

lnd writes `channel.backup` only once it's synced to the chain, which
the test node never is, so the test adds a stand-in file for that check.
- `test/configuration.nix` checks these things:
- The exclusions come first in the filelist: for the default config, a
DSN with `./`, `../`, `//` and a replica name that ends with `:`, a DSN
with an empty replica, an empty `sqlite3://` DSN, a database named
`channel[1].sqlite3`, an encrypted local replica, an encrypted SSHFS
replica, a duplicity root of `/var/lib` with a replica outside it, and a
root of `/var/lib/.`.
- The wallet unit is defined and started for a local bitcoind, and not
for the `bitcoind-remote.nix` preset or `disablewallet`.
  - The 0.2.0 notice shows for any config with backups.
- `nix eval .#ciTestInfo`, `.#checks.x86_64-linux.module-config` and
`.#checks.x86_64-linux.test-runner` pass.
- VM scenario `default` (the secure node scenario with backups, lnd,
Core Lightning and BTCPay Server) passes.
- VM scenario `netns` with the backups test turned on passes. It checks
that the wallet unit reaches bitcoind across the namespace with its IP
allow list.
- I ran duplicity 3.0.7 on its own with a filelist like the new one. It
leaves out the databases, their `-journal`, `-wal` and super-journal
files, a database named `h`, and `channel[1].sqlite3` with its journal.
It keeps `channel1.sqlite3`, `channel.backup`, `hsm_secret` and
`emergency.recover`.
- After the rebase onto master c3d955c (#283), `module-config`,
`test-runner`, `ci-workflows` and `default` pass on the KVM host. On
master, the notice is a warning until 0.2.0 is released, and the tests
pass with `version.nix` at 0.1.6 and at 0.2.0.

## Models

Claude Opus 5.5 wrote the change. Codex GPT-5.6 Sol, Codex GPT-6 Astra
(two passes plus rechecks), Kimi K3.1 Pro (two passes), DeepSeek V4.1
Flash 1017 and GLM 5.3 reviewed it. Claude Opus 5.5 rebased it onto #224
and #283.
seberm added a commit that referenced this pull request Nov 20, 2026
Since #224, scenarios that replace the test set with
`tests = mkForce { ... }` failed to evaluate with "attribute 'i2pd'
missing": test.data.i2pd read config.tests.i2pd, which such scenarios
don't define. This broke wireguardIptablesLegacy,
lnconnectNoOperatorRole and the selectedTests example pattern. CI
doesn't build them, so the failure went unnoticed.

A missing tests.i2pd entry now counts as false. Which tests run is
unchanged.

Follow-up to #224
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 breaking Changes existing user config; needs a versioning.nix entry type: feature New capability or service type: maintenance No user-visible change: refactor, CI, deps, tooling, docs-only type: removal Module, package or option dropped (implies breaking)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants