Skip to content

barkd: add module for the Bark Ark wallet - #141

Draft
mvuk wants to merge 4 commits into
bitcoinix:masterfrom
mvuk:barkd-module-draft
Draft

mvuk wants to merge 4 commits into
bitcoinix:masterfrom
mvuk:barkd-module-draft

Conversation

@mvuk

@mvuk mvuk commented Oct 23, 2026

Copy link
Copy Markdown

Hi, I'm Matthew from Second, the team that builds Bark. Bark implements Ark,
a protocol for holding and sending bitcoin off-chain with an Ark server while
keeping a unilateral on-chain exit. The package is already in nixpkgs as
bark-wallet (0.7.1).

Implemented (modules/barkd.nix)

  • services.barkd: network (signet by default), Ark server, chain source
    (Esplora, or the local bitcoind via the public RPC user plus txindex and
    submitpackage), REST address/port, createWallet, Tor proxy/enforce, defaultHardening
  • The RPC password goes into config.toml via install -T -m 600 and is never in argv
  • Operator barkd-cli, netns-isolation (id 33), backups, nodeinfo, docs, README and example

Tested

  • New barkd test: /ping, 401 without a token, data dir 700 and config.toml 600,
    barkd-cli as operator, and a REST wallet create that passes the bitcoind checks
  • Also extends rpc-whitelist, config-replace and netns-isolation
  • Passing locally: -s barkd, -s regtest (this caught a port 3000 clash with RTL,
    so barkd now uses 3030), netns + regtest, nix flake check and shellcheck.sh

Next steps

  1. Update nixpkgs to 0.8.x
  2. An operator bark CLI and a safe SQLite backup
  3. A full regtest wallet test with captaind

I'm happy to change anything, or to open an issue first if you'd like to talk it through.

Add `services.barkd`, the REST daemon of bark (https://gitlab.com/ark-bitcoin/bark),
a wallet for the Ark protocol built by Second. The package is `bark-wallet` from
nixpkgs (pinned to nixpkgs-unstable).

- Network (signet by default), Ark server URL, chain source (Esplora, or the
  local bitcoind via the `public` RPC user with `txindex` and `submitpackage`)
- config.toml is written in preStart with `install -T -m 600`; the bitcoind
  RPC password never appears in argv
- Wallet created on first start (`createWallet`), mnemonic kept in the data dir
- `barkd-cli` for the operator (passes the bearer token via an fd)
- Tor proxy/enforce, defaultHardening, netns-isolation (id 33), backups,
  nodeinfo, docs, README and example config
- Tests: `barkd`, plus `rpc-whitelist`, `config-replace` and `netns-isolation`
  cases; barkd is enabled in the `full` and `regtest` scenarios

The default REST port is 3030 because barkd's own default (3000) collides
with RTL.

Assisted-by: Claude Code (Claude Opus 5.5)
@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 type: feature New capability or service labels Oct 23, 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.

Thanks for the module. I read it with the test and checked the Tor behaviour against bark 0.7.1's source. Three things need a change before this ships, and a few smaller ones follow.

  1. barkd isn't in modules/presets/enable-tor.nix. On a secure-node the preset turns on tor.proxy and tor.enforce for every service that talks out, but barkd gets neither, so it contacts the Ark server and the Esplora instance from the node's real IP. The defaults point at Second's servers on every network, so the counterparty the Ark model treats as untrusted learns the operator's IP. BARK_PLAN.md lists this as open question 3. Add barkd = defaultEnableTorProxy; there, but see the next point first.

  2. Wallet creation ignores the proxy. bark-cli/src/wallet.rs:450 builds its chain client with ChainSource::new(chain_spec, net, None, None), then calls chain.tip() and initial_wallet_scan on it. With Esplora those requests go direct even when socks5_proxy is set. barkd's REST wallet/create runs the same function (bark-cli/src/bin/barkd/main.rs:436), so the restore path in docs/services.md has the same hole. With tor.proxy the first start leaks the IP once. With tor.enforce the unit's IPAddressAllow is local only, so creation fails and barkd never starts. The module can't fix this by itself. It needs a bark fix (pass config.socks5_proxy into ChainSource::new in create_wallet) or a patch in pkgs/. Until then the docs should say that wallet creation isn't proxied, and the enable-tor entry needs that fix first or createWallet breaks under the preset.

  3. The assertion at modules/barkd.nix:197 rests on a wrong premise. The comment says bark bypasses the proxy only for loopback, so a non-local bitcoind can't be reached. In 0.7.1 the bitcoind backend never uses the proxy at all: bark/src/chain.rs:258 says so and creates both RPC clients without it. The loopback bypass in bark/src/config.rs:177 applies to the Ark server and Esplora URLs. So tor.proxy plus chainSource = "bitcoind" works with netns-isolation, because the RPC goes direct and tor.enforce allows 169.254.0.0/16. That is the combination a secure-node operator wants: Tor for the Ark server, the local node for chain data. Drop the assertion, or replace it with a note that the bitcoind connection never goes through Tor.

Smaller points:

  • modules/barkd.nix:273 adds submitpackage to the shared public RPC user, so lnd, clightning, electrs, fulcrum, nbxplorer and mempool get it too, and the btcpayserver user inherits it because its list is built from the public one. That is the pattern #127 describes. A dedicated RPC user for barkd, like btcpayserver has, keeps the grant with the service. config.toml already takes bitcoind_user and bitcoind_pass, so it is a nix-bitcoin.secrets entry and a rpc.users.barkd block.
  • modules/barkd.nix:223 writes bitcoind_pass into TOML without escaping. Generated passwords are pwgen alphanumeric, so they are fine, but a hand-placed password with " or \ produces a config bark can't parse. Either escape it or say in the option docs that the password must not contain those.
  • BARK_PLAN.md says about itself that it should be dropped before the branch leaves draft. The open questions fit the PR description.
  • services.backups now copies db.sqlite live. Same class as #95, so nothing new to fix here, but worth knowing when a restore fails.

Checked and fine: preStart runs as the service user and install -T replaces config.toml without following a symlink, the token reaches curl through a file descriptor, netns id 33 and its connections match the chain source, extraArgs isn't shell-evaluated, and the test covers the 401, the modes and the failed creation.

DeepSeek V4.1 Flash 1017 run at max reasoning and GLM 5.3 run at max reasoning reviewed the tree at 43a5c20. Both flagged the missing enable-tor entry, and DeepSeek flagged the inherited submitpackage grant. Codex (GPT-6 Astra, xhigh) read the diff and raised the creation path, the assertion and the TOML quoting, which I checked against bark 0.7.1's wallet.rs, chain.rs and barkd/main.rs.

matthewvuk added 3 commits October 23, 2026 22:32
Keep lowercase for code identifiers (`barkd`, the `bark` CLI, `bark-wallet`,
`services.barkd`) and URLs.

Assisted-by: Claude Code (Claude Opus 5.5)
Bark's `socks5_proxy` doesn't reach the chain source client that wallet
creation builds (`bark create`, REST `wallet/create`), so with Esplora the
first start contacted Esplora directly, and failed under `tor.enforce`.
That client honours the standard proxy variables, so set `ALL_PROXY` (and
`NO_PROXY` for local and netns addresses) when `tor.proxy` is enabled,
until Bark passes `socks5_proxy` there itself.

With creation proxied, add `barkd = defaultEnableTorProxy` to the
enable-tor preset.

Drop the assertion against `tor.proxy` with `chainSource = "bitcoind"`:
its premise was wrong. Bark never sends bitcoind RPC through the proxy
(bark/src/chain.rs), and the loopback bypass only applies to the Ark
server and Esplora URLs, so the combination works with netns-isolation.
The regtest scenario now enables `tor.proxy` to cover it.

Assisted-by: Claude Code (Claude Opus 5.5)
Grant `submitpackage` to a new `barkd` RPC user instead of the shared
`public` user, so lnd, clightning, electrs, fulcrum, mempool, nbxplorer
and btcpayserver don't inherit it. The password is a
`bitcoin-rpcpassword-barkd` secret, as for btcpayserver.

Escape `\` and `"` when writing `bitcoind_pass` into config.toml, so
hand-placed passwords still give a valid TOML string.

Assisted-by: Claude Code (Claude Opus 5.5)
@mvuk

mvuk commented Oct 24, 2026

Copy link
Copy Markdown
Author

Thanks a lot for the careful review, and for checking everything against the 0.7.1 source. You were right on all three main points. Here's what changed:

  1. enable-tor preset: barkd = defaultEnableTorProxy; is now in modules/presets/enable-tor.nix (aec46d0). I added it only after fixing point 2, so createWallet still works under the preset.

  2. Wallet creation ignored the proxy: confirmed. Until Bark fixes this itself, the module sets ALL_PROXY (plus NO_PROXY for loopback and 169.254.0.0/16) on the unit when tor.proxy is on (aec46d0). The Esplora client that creation builds honours the standard proxy variables. I checked this locally: with a dead proxy, creation fails at the proxy instead of connecting directly. That covers both bark create and the REST wallet/create restore path. It's marked TODO-EXTERNAL. The upstream fix, which passes socks5_proxy into ChainSource::new in create_wallet, is prepared upstream in Bark, and I will link the merge request here. Once it ships in nixpkgs, the environment workaround can go.

  3. The assertion at modules/barkd.nix:197: dropped (aec46d0). Its premise was wrong: the bitcoind backend never uses the proxy (bark/src/chain.rs). The chainSource docs now say that only the Ark server and Esplora go through Tor. The regtest scenario now enables tor.proxy with chainSource = "bitcoind". I also ran it with tor.enforce under netns-isolation, and creation reaches the Ark server step.

Smaller points:

  • Dedicated RPC user: barkd now has its own rpc.users.barkd with submitpackage and a bitcoin-rpcpassword-barkd secret, like btcpayserver. The public user no longer gets the grant, and rpc-whitelist tests both users (4b413cf).
  • TOML quoting: bitcoind_pass now has \ and " escaped (4b413cf).
  • BARK_PLAN.md: dropped from the branch. The open questions are in the PR description.
  • Backups: noted, no change.

Tests: ./test/run-tests.sh -s barkd build and a netns + regtest scenario with barkd (chainSource = "bitcoind", tor.proxy, tor.enforce) both pass, as do ./test/shellcheck.sh and nix flake check.

@ostermayer

Copy link
Copy Markdown
Collaborator

I read aec46d0 and 4b413cf against my review and the three main points are fixed. The enable-tor entry, the ALL_PROXY and NO_PROXY workaround for wallet creation and the dropped assertion all match what I found in the 0.7.1 source. The dedicated rpc.users.barkd user and the TOML escaping are what I'd have written too.

I ran the adversarial review on 4b413cf. GLM 5.3 (max reasoning) found nothing in the files this PR changes, but it reported two findings in bitcoind-remote.nix and bitcoind.nix, and Codex (GPT-6 Astra, xhigh) checked both and called them false positives. DeepSeek V4.1 Flash 1017 (max) timed out after an hour without output, so it gave no verdict on this head.

The branch now conflicts with master in pkgs/pinned.nix, because #145 removed bitcoind-knots from the same list where this PR adds bark. Nothing else conflicts. Once you've rebased I'll rerun the review on the new head and approve.

bobberb added a commit to bobberb/bitcoinix that referenced this pull request Oct 25, 2026
…id, admin-credential docs)

- Build the RPC cookie in a root-only mktemp -d and mv -fT it into place, so
  the service user cannot swap a symlink in /run/rbitcoin mid-write.
- Use utils.escapeSystemdExecArgs for ExecStart so % and $ in extraArgs survive.
- Move the rbitcoin netns id from 33 to 34 (also claimed by bitcoinix#141 and bitcoinix#2).
- Document that the RPC cookie is an administrative credential and that
  mempool holds it, in the rpc.enable and electrumServer descriptions and
  docs/services.md.
- Test that no cookie temp dir is left behind.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@prusnak prusnak added status: changes needed Cannot proceed until suggested changes are implemented status: rebase needed Merge conflicts need to be resolved labels Nov 4, 2026
@prusnak prusnak added this to the v0.2.1 milestone Nov 18, 2026
bobberb added a commit to bobberb/bitcoinix that referenced this pull request Nov 19, 2026
…id, admin-credential docs)

- Build the RPC cookie in a root-only mktemp -d and mv -fT it into place, so
  the service user cannot swap a symlink in /run/rbitcoin mid-write.
- Use utils.escapeSystemdExecArgs for ExecStart so % and $ in extraArgs survive.
- Move the rbitcoin netns id from 33 to 34 (also claimed by bitcoinix#141 and bitcoinix#2).
- Document that the RPC cookie is an administrative credential and that
  mempool holds it, in the rpc.enable and electrumServer descriptions and
  docs/services.md.
- Test that no cookie temp dir is left behind.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
bobberb added a commit to bobberb/bitcoinix that referenced this pull request Nov 19, 2026
…id, admin-credential docs)

- Build the RPC cookie in a root-only mktemp -d and mv -fT it into place, so
  the service user cannot swap a symlink in /run/rbitcoin mid-write.
- Use utils.escapeSystemdExecArgs for ExecStart so % and $ in extraArgs survive.
- Move the rbitcoin netns id from 33 to 34 (also claimed by bitcoinix#141 and bitcoinix#2).
- Document that the RPC cookie is an administrative credential and that
  mempool holds it, in the rpc.enable and electrumServer descriptions and
  docs/services.md.
- Test that no cookie temp dir is left behind.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@github-actions github-actions Bot added the size: L 100–499 changed lines (additions + deletions) label Nov 24, 2026
bobberb added a commit to bobberb/bitcoinix that referenced this pull request Nov 26, 2026
…id, admin-credential docs)

- Build the RPC cookie in a root-only mktemp -d and mv -fT it into place, so
  the service user cannot swap a symlink in /run/rbitcoin mid-write.
- Use utils.escapeSystemdExecArgs for ExecStart so % and $ in extraArgs survive.
- Move the rbitcoin netns id from 33 to 34 (also claimed by bitcoinix#141 and bitcoinix#2).
- Document that the RPC cookie is an administrative credential and that
  mempool holds it, in the rpc.enable and electrumServer descriptions and
  docs/services.md.
- Test that no cookie temp dir is left behind.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Assisted-by: Claude Code (claude-sonnet-5-5)
bobberb added a commit to bobberb/bitcoinix that referenced this pull request Nov 26, 2026
…id, admin-credential docs)

- Build the RPC cookie in a root-only mktemp -d and mv -fT it into place, so
  the service user cannot swap a symlink in /run/rbitcoin mid-write.
- Use utils.escapeSystemdExecArgs for ExecStart so % and $ in extraArgs survive.
- Move the rbitcoin netns id from 33 to 34 (also claimed by bitcoinix#141 and bitcoinix#2).
- Document that the RPC cookie is an administrative credential and that
  mempool holds it, in the rpc.enable and electrumServer descriptions and
  docs/services.md.
- Test that no cookie temp dir is left behind.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Assisted-by: Claude Code (claude-sonnet-5-5)
@seberm seberm removed this from the v0.2.1 milestone Nov 27, 2026

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

@mvuk thanks for the fixes, ostermayer confirmed them. Could you rebase onto current master and re-test on bark 0.8.1, which nixpkgs ships now? Since the branch was written, master has changed what the module plugs into:

Must

  1. pkgs/pinned.nix is gone. Add bark-wallet to pinned in pkgs/default.nix, otherwise evaluation fails on nbPkgs.bark-wallet.
  2. netns id 33 now belongs to unbeholden-wallet, and the module doesn't check that ids are unique. After a rebase, both services silently get 169.254.1.33. Use a free id.
  3. Test bodies now live in test/suite/, and each @test must be listed in TEST_PHASES in test/tests.py, or the runner raises.
  4. The service page now goes in docs/service/barkd.md (listed in docs/SUMMARY.md), plus a release-note draft in docs/release-notes/<next milestone>/barkd.md.

Should

  • With chainSource = "esplora", the wallet scan sends every wallet address to the Esplora server, which on mainnet is Second's by default. Please say so in the docs and recommend chainSource = "bitcoind" for mainnet.

Optional

  • Link ark-bitcoin/bark!2674 (still a draft) in the TODO-EXTERNAL comment.

Checked on 0.8.1: the ALL_PROXY workaround is still needed and works. Without it, bark create connects directly to the Esplora server despite socks5_proxy. barkd's /ping, the 401, {"fingerprint":null} and the non-loopback bind behave as the test expects.

Assisted-by: Claude Code (Claude Opus 5.5)

bobberb added a commit to bobberb/bitcoinix that referenced this pull request Nov 29, 2026
…id, admin-credential docs)

- Build the RPC cookie in a root-only mktemp -d and mv -fT it into place, so
  the service user cannot swap a symlink in /run/rbitcoin mid-write.
- Use utils.escapeSystemdExecArgs for ExecStart so % and $ in extraArgs survive.
- Move the rbitcoin netns id from 33 to 34 (also claimed by bitcoinix#141 and bitcoinix#2).
- Document that the RPC cookie is an administrative credential and that
  mempool holds it, in the rpc.enable and electrumServer descriptions and
  docs/services.md.
- Test that no cookie temp dir is left behind.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Assisted-by: Claude Code (claude-sonnet-5-5)
@prusnak

prusnak commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

bark-wallet 0.9.0 merged to nixpkgs master, nixos-unstable channel being updated -> https://pr.bitcoinix.net/?pr=596295

This branch has not been deployed

No deployments
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 size: L 100–499 changed lines (additions + deletions) status: changes needed Cannot proceed until suggested changes are implemented status: rebase needed Merge conflicts need to be resolved type: feature New capability or service

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants