diff --git a/configuration.nix b/configuration.nix index 81961b1..80f501c 100644 --- a/configuration.nix +++ b/configuration.nix @@ -24,13 +24,10 @@ # Option schema (lnbits-sensei.*). ./modules/core.nix - # LNbits service wrapper. - ./modules/lnbits.nix - # Git remote topology — upstream / fork / extras. ./modules/git/remotes.nix - # Dev environment (worktree mgmt, regtest, fakewallet, tmux). + # Dev environment (worktree mgmt, regtest stack, dev CLI, tmux). ./modules/dev-env ]; diff --git a/modules/core.nix b/modules/core.nix index f07fd57..c6adfc3 100644 --- a/modules/core.nix +++ b/modules/core.nix @@ -49,37 +49,20 @@ in regtest = mkEnableOption '' Full Bitcoin/Lightning regtest docker stack (LND + CLN + Eclair - + bitcoind + electrs). Implies a container engine. See - modules/dev-env/regtest.nix and modules/dev-env/scripts/regtest.sh - ''; - - fakewallet = mkEnableOption '' - FakeWallet dev mode — no docker, no chains, nothing to start. - Default LNbits backend; this flag mostly controls dev-env - helpers and symmetry with the regtest workflow + + bitcoind + electrs). Implies a container engine — install + docker only if you actually plan to invoke `dev up --regtest`. + The default `dev up` (FakeWallet) needs none of this ''; }; - # --- LNbits service config --- + # --- LNbits bind addr --- + # + # Backend selection lives in the `dev` CLI (--fakewallet | --regtest), + # not as a NixOS option: the dev-env scaffold doesn't manage a + # systemd lnbits service, and we don't want two knobs (build-time + # vs runtime) that can disagree. lnbits = { - backend = mkOption { - type = types.enum [ - "FakeWallet" - "LndRestWallet" - "CoreLightningWallet" - "EclairWallet" - ]; - default = "FakeWallet"; - description = '' - Which Lightning backend LNbits talks to. FakeWallet is the - default — no real chain, no docker, nothing to start. The - regtest dev mode (modules/dev-env/regtest.nix) flips this to - LndRestWallet or CoreLightningWallet at activation time. - ''; - example = "LndRestWallet"; - }; - port = mkOption { type = types.port; default = 5000; diff --git a/modules/dev-env/options.nix b/modules/dev-env/options.nix index 160e165..6f623bb 100644 --- a/modules/dev-env/options.nix +++ b/modules/dev-env/options.nix @@ -121,8 +121,9 @@ in enable = mkEnableOption '' Bitcoin/Lightning regtest docker stack. Wraps an upstream fork of `lnbits/legend-regtest-enviroment` (LND + CLN + - Eclair + bitcoind + electrs). Implies a container engine — - the substantive pass will gate this on a containers feature + Eclair + bitcoind + electrs). Brought up via + `dev up --regtest`. Implies a container engine — the + substantive pass will gate this on a containers feature ''; repoUrl = mkOption { @@ -136,15 +137,6 @@ in }; }; - fakewallet = { - enable = mkEnableOption '' - FakeWallet dev mode helpers. Installs the symmetric `fakewallet` - wrapper script (a no-op for parity with `regtest up`) so the - dev experience is identical whether you're on the default - FakeWallet path or the full regtest stack - ''; - }; - tmux = { enable = mkEnableOption "declarative tmux session launcher"; diff --git a/modules/dev-env/scripts/dev.sh b/modules/dev-env/scripts/dev.sh new file mode 100755 index 0000000..2c98e17 --- /dev/null +++ b/modules/dev-env/scripts/dev.sh @@ -0,0 +1,53 @@ +#!/usr/bin/env bash +# dev — single entry point for spinning up an LNbits dev environment. +# +# dev up [--fakewallet|--regtest] start lnbits (default: --fakewallet) +# dev down tear down whatever's running +# dev logs follow lnbits (and docker, if regtest) logs +# dev shell drop into the lnbits venv (or regtest container) +# +# Modes: +# --fakewallet (default) LNBITS_BACKEND_WALLET_CLASS=FakeWallet — no docker, +# no chains, instant. Good for extension / UI work. +# --regtest docker-compose up the multi-node regtest stack +# (LND + CLN + Eclair + bitcoind + electrs), then +# start lnbits pointed at the LND-rest endpoint. +# Wraps lnbits/legend-regtest-enviroment. +# +# Skeleton — no real wiring yet. The substantive pass will: +# - locate the lnbits checkout via inputs.lnbits-src (or a configurable path) +# - locate the regtest docker repo via config.lnbits-sensei.devEnv.regtest.repoUrl +# - bring up containers, wait-for-it, populate LND credentials, exec lnbits + +set -euo pipefail + +cmd="${1:-up}" +shift || true + +mode="fakewallet" +while [[ $# -gt 0 ]]; do + case "$1" in + --fakewallet) mode="fakewallet"; shift ;; + --regtest) mode="regtest"; shift ;; + *) echo "dev: unknown flag: $1" >&2; exit 1 ;; + esac +done + +case "$cmd" in + up) + echo "dev up --$mode: TODO — wire substantive startup in next pass." + ;; + down) + echo "dev down: TODO — wire teardown in next pass." + ;; + logs) + echo "dev logs: TODO — tail lnbits + (docker logs if regtest) here." + ;; + shell) + echo "dev shell: TODO — drop into venv / regtest container here." + ;; + *) + echo "Usage: dev {up|down|logs|shell} [--fakewallet|--regtest]" >&2 + exit 1 + ;; +esac diff --git a/modules/dev-env/scripts/fakewallet.sh b/modules/dev-env/scripts/fakewallet.sh deleted file mode 100755 index e61852e..0000000 --- a/modules/dev-env/scripts/fakewallet.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env bash -# fakewallet.sh — symmetric no-op for parity with regtest.sh. -# -# FakeWallet is the default LNbits backend. There is nothing to start, -# nothing to stop, nothing to log: LNbits with `LNBITS_BACKEND_WALLET_CLASS=FakeWallet` -# just runs. -# -# This wrapper exists purely so the dev experience is symmetric with -# the regtest stack: -# -# fakewallet up # no-op, prints reassurance -# fakewallet down # no-op, prints reassurance -# fakewallet logs # tails lnbits' own logs (not a backend's) -# fakewallet shell # no-op (no container to enter) -# -# Muscle memory wins. `regtest up` and `fakewallet up` mean the same -# thing — "make the chosen backend ready" — even when one is a docker -# stack and the other is a constant. - -set -euo pipefail - -# TODO(skeleton): wire the substantive variants in a later pass. -# `up` / `down` / `shell` stay no-ops by design; `logs` should -# `journalctl --user -u lnbits` (or whatever unit the lnbits module -# ends up declaring) so the dev still has a single place to look. - -case "${1:-up}" in - up | down | shell) - echo "FakeWallet is the default — nothing to start." - ;; - logs) - echo "fakewallet logs: TODO — tail the lnbits service log here." - ;; - *) - echo "Usage: fakewallet {up|down|logs|shell}" - exit 1 - ;; -esac diff --git a/modules/dev-env/scripts/regtest.sh b/modules/dev-env/scripts/regtest.sh deleted file mode 100755 index efc7146..0000000 --- a/modules/dev-env/scripts/regtest.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env bash -# regtest.sh — wrapper around a Bitcoin/Lightning regtest docker stack. -# -# Mirrors the workflow of `lnbits/legend-regtest-enviroment` (LND + CLN -# + Eclair + bitcoind + electrs). Cloned to -# `${dev-env.root}/local/docker/regtest/` by the bootstrap script -# (later pass); this wrapper just dispatches `up` / `down` / `logs` / -# `shell` to the underlying docker-compose stack. -# -# Symmetric with fakewallet.sh so the dev experience reads the same -# whether you're on the default FakeWallet path or the regtest stack: -# -# regtest up # boot the regtest stack -# regtest down # tear it down -# regtest logs # tail compose logs -# regtest shell # drop into a node container -# -# Once `regtest up` is healthy, point LNbits at the appropriate -# backend (LndRestWallet / CoreLightningWallet) by flipping -# `lnbits-sensei.lnbits.backend` and rebuilding. - -set -euo pipefail - -# TODO(skeleton): replace with real dispatcher in the substantive pass. -# Intended shape: -# case "${1:-}" in -# up) docker compose -f "${REGTEST_DIR}/docker-compose.yml" up -d ;; -# down) docker compose -f "${REGTEST_DIR}/docker-compose.yml" down ;; -# logs) docker compose -f "${REGTEST_DIR}/docker-compose.yml" logs -f ;; -# shell) docker compose -f "${REGTEST_DIR}/docker-compose.yml" exec "${2}" sh ;; -# *) usage ;; -# esac - -echo "regtest: TODO — substantive implementation lands in a later pass." -echo "See modules/dev-env/scripts/regtest.sh for the intended dispatcher shape." -exit 0 diff --git a/modules/lnbits.nix b/modules/lnbits.nix deleted file mode 100644 index 1080d61..0000000 --- a/modules/lnbits.nix +++ /dev/null @@ -1,42 +0,0 @@ -# lnbits-sensei — LNbits service wrapper. -# -# Stub. Wraps an as-yet-unwritten `services.lnbits` NixOS module (or -# a hand-rolled systemd unit) and exposes the small surface area -# consumers actually tune: backend, port, host. Sourced from -# `config.lnbits-sensei.lnbits.*` so the option schema stays in -# modules/core.nix. -# -# Default `backend = "FakeWallet"` — no docker, no chains, nothing to -# start. The regtest mode (modules/dev-env/regtest.nix, scripts/regtest.sh) -# flips this to LndRestWallet / CoreLightningWallet and wires the -# credentials from the regtest stack's generated artifacts. -{ - config, - lib, - pkgs, - ... -}: - -let - inherit (lib) mkIf; - cfg = config.lnbits-sensei; -in -{ - config = mkIf cfg.enable { - # TODO(skeleton): wire services.lnbits (or a hand-rolled systemd - # user/system unit) here. Intended shape: - # - # services.lnbits = { - # enable = true; - # backend = cfg.lnbits.backend; - # host = cfg.lnbits.host; - # port = cfg.lnbits.port; - # # source = inputs.lnbits-src; (resolved in flake.nix → specialArgs) - # }; - # - # Until a real services.lnbits module is published in nixpkgs, - # the substantive pass will likely declare a systemd.services.lnbits - # entry that runs `poetry run lnbits` out of a checkout of - # `inputs.lnbits-src`. - }; -}