Skip to content

clightning-replication: require the mounts for a local replica directory - #275

Merged
prusnak merged 2 commits into
bitcoinix:masterfrom
ostermayer:clightning-replication-local-mount
Nov 18, 2026
Merged

prusnak merged 2 commits into
bitcoinix:masterfrom
ostermayer:clightning-replication-local-mount

Conversation

@ostermayer

@ostermayer ostermayer commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

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 (Keep unreleased migration notices visible on master #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.

@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 type: feature New capability or service labels Nov 16, 2026

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

Reviewed 240ce5439437.

No actionable findings. Both the direct local-replica service and the encrypted-replica mount service acquire the required mount dependencies. The quoting accounts for whitespace, quotes, backslashes and systemd specifiers; the docs clearly state the declared-mount and symlink limitations. The broader migration-notice condition avoids the documented module recursion. Local module-config and mdBook builds pass. I inspected the missing-disk VM test but did not rerun the replication VM locally.

Review performed with Codex (GPT-6 Astra).

@github-actions github-actions Bot added the status: rebase needed Merge conflicts need to be resolved label Nov 16, 2026
@ostermayer
ostermayer force-pushed the clightning-replication-local-mount branch from 240ce54 to 393634e Compare November 18, 2026 00:19
With `local.directory`, nothing tied clightning to the disk or share that
should hold the replica. When that mount 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 also ran `gocryptfs -init` there. The node looked healthy, but a
failure of the primary disk took both copies.

Add `RequiresMountsFor` for the directory to clightning, and to
clightning-replication-mounts when it's set. systemd then mounts the
directory first and doesn't start these units while the mount fails. This
works only for mounts that systemd knows, so the docs now say to declare the
disk or share in `fileSystems`. A directory on the root filesystem has no
mount to wait for and starts as before.

systemd splits path settings at whitespace and expands `%` specifiers, so
quote and escape the directory in `RequiresMountsFor` and in clightning's
`ReadWritePaths`. Before, a directory with a space became two paths.

clightning now stays down without the mount, so add a 0.2.0 notice for
local replication. It isn't limited to directories below a `fileSystems`
entry, because systemd also waits for mounts that aren't in `fileSystems`,
like `systemd.mounts` entries.

Fixes bitcoinix#122.

Assisted-by: Claude Code (Claude Opus 5.5)
@ostermayer
ostermayer force-pushed the clightning-replication-local-mount branch from 393634e to f5420b0 Compare November 18, 2026 01:01
@github-actions github-actions Bot added status: rebase needed Merge conflicts need to be resolved and removed status: rebase needed Merge conflicts need to be resolved labels Nov 18, 2026
@prusnak prusnak added this to the v0.2.0 milestone Nov 18, 2026
@github-actions github-actions Bot removed the status: rebase needed Merge conflicts need to be resolved label Nov 18, 2026
@prusnak
prusnak merged commit aba23bd into bitcoinix:master Nov 18, 2026
26 checks passed
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 type: feature New capability or service

Projects

None yet

Development

Successfully merging this pull request may close these issues.

clightning-replication: a local replica directory has no mount dependency, so a missing disk puts the replica on the primary filesystem

3 participants