Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 62 additions & 37 deletions pm-stack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ forks of upstream projects.
| PostgreSQL | `postgres:16-alpine` + digest | Kaneo's database; named volume `pm-stack_postgres_data`; never exposed on a host port |

Phase 2 (2026-10-24) added three layers, each in its own subdirectory
with the same deploy shape (SOPS → mode-600 env → compose/unit →
health gate):
with pinned configuration, bootstrap/seed helpers, and health
endpoints. NixOS owns the live service lifecycle described below:

| Layer | Piece | Version / pin | Reach | Deployment definition |
| --------- | --------------- | ---------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- | --------------------- |
Expand All @@ -26,9 +26,18 @@ health gate):
| Intake | pm-dispatch | this repo (Bun app, user unit `pm-dispatch`) | `127.0.0.1:4879` + tailnet; public via tunnel as `dispatch.security.cab` | `dispatch/` |
| Console | pm-console | this repo (Bun app, user unit `pm-console`) | `127.0.0.1:4872`; public behind sign-in as `pm.security.cab` (console at `/console`, dashboard at `/` through the console's gate) | `console/` |

ready-for-agent runs as a systemd **user unit** (like `pm-tunnel`)
because upstream ships only an npm package; Pad and Grist run as
containers per the standing container rule. Grist was chosen over
The live manager is NixOS, not an interactive deploy script:

- `nixos/services/pm-apps` owns the `pm-grist` and `pm-pad` OCI
containers and the `ready-for-agent` systemd **user unit**.
- `nixos/services/pm-stack` owns the `pm-kaneo` systemd user service,
which runs the Compose-backed Kaneo/PostgreSQL stack, plus the other
PM user services and timers.

The `pad/` and `grist/` `deploy.sh` files remain bootstrap/fallback
helpers for rendering their on-machine env files; they are not the live
manager path. After the migration, use `nixos-rebuild switch` on `amd`
and the host-side readiness probe for status. Grist was chosen over
Baserow — the evaluation is in the design record.

## Environment numbers (the #2835 contract)
Expand Down Expand Up @@ -72,7 +81,8 @@ that hostname to `http://localhost:5173`. The tunnel connector runs as
the `pm-tunnel` systemd **user** unit (see `systemd/pm-tunnel.service`);
the same tunnel also maps `dispatch.security.cab` to
`http://localhost:4879` (pm-dispatch, added 2026-10-30). On `amd`, one
`nixos-rebuild switch` deploys the whole stack: the user units
`nixos-rebuild switch` deploys the whole stack: the `pm-apps` services
(`pm-grist`, `pm-pad`, and `ready-for-agent`), the PM user units
(`pm-aggregator`, `pm-projector`, `pm-dispatch`, `pm-tunnel`) and the
Kaneo stack's lifecycle are declared in
[`../nixos/services/pm-stack`](../nixos/services/pm-stack).
Expand Down Expand Up @@ -179,8 +189,9 @@ login until the database password is changed to match.
# 1. Check out this repo (or copy this directory + ../secrets) and cd in
cd pm-stack

# 2. Render env and start the stack (waits for the health endpoint)
./deploy.sh
# 2. Apply the NixOS-managed runtime on the laptop host.
# This owns Pad, Grist, ready-for-agent, Kaneo, and PostgreSQL.
nixos-rebuild switch
Comment on lines +192 to +194

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Render Pad and Grist env files before the first switch

On a fresh checkout, the first-time procedure no longer creates ~/pm-stack/pad/.env or ~/pm-stack/grist/.env, yet nixos/services/pm-apps/default.nix:117,131 requires those files through environmentFiles. The NixOS module does not render them, and the component sections also remove the deploy commands that previously did so. Document running pad/deploy.sh render and grist/deploy.sh render before applying the configuration; otherwise both containers lack required env files and cannot start.

Useful? React with 👍 / 👎.


# 3. Install + start the tunnel connector
install -Dm644 systemd/pm-tunnel.service ~/.config/systemd/user/pm-tunnel.service
Expand Down Expand Up @@ -317,16 +328,22 @@ clone` clones/fetches them all into `ready-for-agent/repos/`, and

### Pad (planning layer)

Pad is the `pm-pad` OCI container declared by
`nixos/services/pm-apps`; do not start it with `pad/deploy.sh` or
`docker compose` on the live host. Apply `nixos-rebuild switch` and use
the readiness probe for lifecycle/status. The seed helper is still a
safe, idempotent API client:

```bash
cd pad
./deploy.sh # SOPS -> .env, compose up, health gate on /api/v1/health
./seed.sh # idempotent REST seed of the Plan items in seed/
```

- **Health:** `GET http://127.0.0.1:7777/api/v1/health` →
`{"status":"ok",…}`. (`/healthz` only hits the SPA fallback.)
- **Bootstrap (first time only):** `pad init` must run **inside**
the server container (`docker compose exec pad pad init`) —
the NixOS-managed `pm-pad` container (for example,
`docker exec pm-pad pad init`) —
bootstrap is loopback/token-gated (token at
`/data/.bootstrap-token`). Create the admin from the
`pad_admin_*` SOPS credentials and the workspace
Expand All @@ -345,9 +362,14 @@ cd pad

### Grist (table layer)

Grist is the `pm-grist` OCI container declared by
`nixos/services/pm-apps`; do not start it with `grist/deploy.sh` or
`docker compose` on the live host. Apply `nixos-rebuild switch` and use
the host readiness probe for lifecycle/status. The seed helper remains
an idempotent API client:

```bash
cd grist
./deploy.sh # SOPS -> .env, compose up, health gate
./seed.sh # idempotent seed: workspace, doc, Roadmap table + rows
```

Expand Down Expand Up @@ -412,23 +434,25 @@ uses the Grist API.

## Day-2 operations

- **Status:** `docker compose ps`, `docker compose logs -f kaneo`,
`systemctl --user status pm-tunnel`. Phase 2 pieces:
`docker compose -f pad/compose.yml ps`, `curl --fail
http://127.0.0.1:7777/api/v1/health` (Pad), `docker compose -f
grist/compose.yml ps` (Grist), `systemctl --user status
ready-for-agent` + `ready-for-agent status
developing-today/code` (dispatch).
- **Restart with current env:** `./deploy.sh restart`. Environment
changes require `./deploy.sh` (compose applies env on recreate, not
restart). Each Phase 2 subdirectory has the same `deploy.sh`
contract (Pad, Grist); ready-for-agent refreshes via
`ready-for-agent/install.sh`.
- **Update Kaneo or PostgreSQL:** after reviewing the upstream release
notes, bump the tag and digest together in `compose.yml`, then
`./deploy.sh`. Never float on a mutable tag. Same rule per component:
Pad/Grist image pins (tag + digest) in their `compose.yml`,
ready-for-agent's `PINNED_VERSION` in `ready-for-agent/install.sh`.
- **Status:** Kaneo/PostgreSQL are the Compose-backed `pm-kaneo` user
service (`systemctl --user status pm-kaneo` and
`docker compose ps`/logs for inspection). Pad and Grist are the
NixOS-managed `docker-pm-pad`/`docker-pm-grist` services; inspect them
with `systemctl status docker-pm-pad docker-pm-grist pm-apps-health`.
Check the HTTP probes at `7777` (Pad), `8484` (Grist), and `6056`
(ready-for-agent); dispatch status is
`ready-for-agent status developing-today/code`.
- **Restart with current configuration:** use `nixos-rebuild switch`
for Pad, Grist, and ready-for-agent. For Kaneo/PostgreSQL, use
`systemctl --user restart pm-kaneo.service`; its NixOS-managed unit
invokes the top-level `deploy.sh` and preserves the database volume.
The `pad/deploy.sh` and `grist/deploy.sh` scripts are bootstrap/
fallback helpers, not live restart commands.
- **Update images:** for Kaneo/PostgreSQL, review release notes and
update the tag and digest together in `compose.yml`; then apply the
NixOS switch so `pm-kaneo` invokes the change. For Pad/Grist, update
the pinned tag and digest in `nixos/services/pm-apps/default.nix`,
then run `nixos-rebuild switch`. Never float on a mutable tag.
- **Pad API token:** expires 90 days after minting (current:
2027-01-22) — re-mint, re-file (SOPS + both vaults), restart
nothing (the token is used by external automation, not the
Expand All @@ -440,11 +464,12 @@ developing-today/code` (dispatch).
(SQLite) under the volume's `/persist/docs`, plus `home.sqlite3`
for the install itself.
- **Move hosts:** copy this directory + `../secrets`, ensure the new
host's age key is a SOPS recipient, run `./deploy.sh`, install the
unit, done. Pad and Grist pick up the new host's tailnet address at
render time (`deploy.sh` writes `PM_STACK_TAILNET_IP` from
`tailscale ip -4`; set it in the environment to override, and with
no tailnet address both bind loopback only). The tunnel is
host's age key is a SOPS recipient, and apply the NixOS configuration.
`pm-kaneo` invokes the top-level `deploy.sh`; Pad and Grist are
created by `services.pm-apps` and pick up the new host's tailnet
address from the module. The fallback scripts still derive
Comment on lines +469 to +470

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Set the destination host's tailnet address explicitly

When moving to a host with a different Tailscale address, the module does not discover that address as the old deploy scripts did: services.pm-apps.tailnetAddress defaults to the literal 100.99.113.103 in nixos/services/pm-apps/default.nix:100-104, and the container port mappings and ready-for-agent socket use it directly. A repository-wide search of Nix files found no override. Add an explicit step to configure the destination address; following the replacement instructions unchanged leaves these services trying to bind the old host's address.

Useful? React with 👍 / 👎.

`PM_STACK_TAILNET_IP` when used for bootstrap, but they are not the
live manager. The tunnel is
host-agnostic (token-based); only one
connector should run at a time.

Expand All @@ -462,14 +487,14 @@ pm-stack/
├── systemd/
│ └── pm-tunnel.service # Cloudflare Tunnel connector (user unit)
├── pad/ # Phase 2 planning layer (Pad 0.18.1)
│ ├── compose.yml # pinned image + digest, loopback + tailnet
│ ├── deploy.sh # same deploy contract as the top level
│ ├── compose.yml # bootstrap/fallback compose definition
│ ├── deploy.sh # bootstrap/fallback env + compose helper
│ ├── .env.example
│ ├── seed.sh # idempotent REST seed
│ └── seed/ # Plan item content (Markdown)
├── grist/ # Phase 2 table layer (Grist 1.7.21)
│ ├── compose.yml # pinned grist-oss image + digest
│ ├── deploy.sh
│ ├── compose.yml # bootstrap/fallback compose definition
│ ├── deploy.sh # bootstrap/fallback env + compose helper
│ ├── .env.example
│ ├── seed.sh # idempotent seed via the REST API
│ ├── reload-doc.sh # force-reload + API read-back verification
Expand Down