A real store's infrastructure, declared in Nix and proven in Bend
directo is a parts store (Reflex-DOM on GHC's JavaScript back end, a Servant backend, Postgres) that runs in production on NixOS. This deck is its infrastructure work: an OVH lab declared with terranix and OpenTofu, installed by nixos-anywhere, deployed by deploy-rs, with secrets in agenix, and a spec in Bend whose laws are proven and rechecked by a kernel with a Lean proof.
doneDeclared, built and checked: the OpenTofu configs, the lab's NixOS system, the spec and its proofs, every gate and its must-fail test.directo, branch plan-terranix at b60ae73 (local, not pushed), infra/ and spec/
openNot run yet: the OVH lab itself, paused by the owner on 2026-11-26. Nothing is rented; the apply, the install, the lab's drill and the drift test wait for the owner's OK.directo, branch plan-terranix at b60ae73 (local, not pushed), infra/README.md, "The lab, in order"
measuredRun: directo's production backups on xty, a nightly dump pulled to olimpo and restored into a drill database every time (slide 12).enc (hhefesto's NixOS machines), commit cfd6ef1, directo-backup.bend
Each claim is marked: done (built, in a branch), proved (Bend's checker and the BendTT kernel accept it), tested (a check that runs), measured, claimed (a document says so), open, lead (proposed), decided. Keys: → or space for the next slide, ← back, Home and End, a for the whole deck on one page.
One source of truth, four tools that read it
infra/topology.nix ──┬── terranix ──► OpenTofu JSON ──► OVH instance, DNS, buckets, S3 users
│ │ tofu output
│ ▼
│ infra/hosts.json (reviewed, committed)
├── nixosConfigurations.lab ◄────────┘ (the address)
├── deploy.nodes.lab (deploy-rs)
└── infra/facts.nix ──► Facts.bend ──► spec/Check.bend (the rules, by the kernel)| host | environment | production | OpenTofu | deploy-rs | CI |
|---|---|---|---|---|---|
| xty | prod | yes | no | no | no |
| olimpo | dev | no | no | no | no |
| lab (OVH BHS5, d2-4) | lab | no | yes | yes | yes |
doneNo address is typed by hand: the provider assigns it, nix run .#tf-hosts writes it to hosts.json from tofu output, and the flake reads it. Production is declared only so a check can prove nothing here acts on it.directo, branch plan-terranix at b60ae73 (local, not pushed), infra/topology.nix, infra/default.nix
OpenTofu makes things; Nix decides what runs on them
| concern | tool | why |
|---|---|---|
| machines, DNS records, buckets, S3 users | OpenTofu (JSON from terranix) | a reviewed plan instead of a console click; drift is visible |
| the OS install | nixos-anywhere | an apply can never reinstall a box: boot_from is ignored after creation |
| what runs on the machine | NixOS | one closure, built and evaluated before any deploy |
| deploying it | deploy-rs | auto-rollback off, as oasis-infra since an outage it caused |
| secrets | agenix | OpenTofu's state holds plain values; secrets never go there |
decidedOpenTofu runs the configs, through terranix; Terraform itself is one line away, since terranix's JSON is the same for both.the owner's answer of 2026-11-26 (terranix, OpenTofu or Terraform)
testedBoth configs validate offline against the providers' own schemas (ovh/ovh 2.15.0, cloudflare 5.21.1, OpenTofu 1.12.3): tofu validate, with the providers from the Nix store.directo, branch plan-terranix at b60ae73 (local, not pushed), checks.tf-validate
Encrypted by OpenTofu, locked, versioned, bootstrapped once
- The lab's state lives in an OVH bucket (S3 API), locked with a lock object beside it (
use_lockfile, no DynamoDB), in a bucket with versioning on: a bad apply can be rolled back. - OpenTofu encrypts state and plans itself (pbkdf2 key, AES-GCM),
enforced = true: an unencrypted state or plan is refused. The passphrase is an agenix secret, decrypted only at a person's terminal. - A tiny bootstrap config makes that bucket and a credential limited to it; its own state is local, encrypted, and committed.
- Kept resources carry
prevent_destroy, and a Bend check refuses any saved plan that deletes one (slide 8).
doneConfigured as above; not applied yet.directo, branch plan-terranix at b60ae73 (local, not pushed), infra/tf/state.nix, infra/tf/lab.nix, infra/default.nix (the tf app)
Each thing gets a meaning first; operations are defined by what they do to it
| thing | meaning | law |
|---|---|---|
| pre-deploy checks | config → list of failures | building checks is a monoid homomorphism: Both ↦ ++, Pass ↦ []; passing both ⇔ passing each |
| scope | what the tools act on | the scope rule is silent ⇔ (tofu ++ deploy ++ ci) ∩ production = ∅, and that splits per tool |
| promotion | environment → commits it ran | nothing reaches production; a move happens ⇔ it is dev → lab and the commit ran on dev |
| OpenTofu plans | resource → attributes | applying plan(desired, state) gives the desired state, except a kept resource is never deleted |
| ssh access | a set of keys | the guard is silent ⇔ every live key survives |
| backups | snapshots (age, paths) | freshness distributes over more snapshots (or) and more paths (and) |
claimedThe method is Conal Elliott's: a type's meaning is a mathematical object, and each instance must agree with its meaning's ("type class morphisms").Conal Elliott, "Denotational design with type class morphisms" (2009)
Fourteen laws, by Bend's checker and again by the BendTT kernel
$ nix build .#checks.x86_64-linux.spec
directo-spec> ALL PROOFS CHECKprovedAmong them: check_assoc, passes_both, scope_meaning, scope_split, never_prod, promote_iff, plan_converges, plan_safe, access_silent, fresh_app, covers_app.directo, branch plan-terranix at b60ae73 (local, not pushed), spec/LAWS.bend
tested--check-only alone is not validity: the gate runs --verdict, and a law false on purpose (FALSE.bend) must be refused, or CI fails.directo, branch plan-terranix at b60ae73 (local, not pushed), checks.spec, checks.spec-must-fail
The rules run on facts pulled out of the flake
infra/facts.nix reads what the tools would act on (OpenTofu's instances, deploy-rs's nodes, the nixosConfigurations CI builds, the records OpenTofu made) and writes Facts.bend. spec/Check.bend then claims M.Check.run(M.Check.all(), facts) == [], and the kernel computes it.
testedOn the flake's facts: ALL PROOFS CHECK. On deliberately bad facts it fails, and the failure is the list of what broke:directo, branch plan-terranix at b60ae73 (local, not pushed), checks.facts, checks.facts-must-fail
- expected : ["scope: production host in tofu, deploy or ci: xty",
"scope: production host in tofu, deploy or ci: xty",
"topology: address used twice: 192.0.2.10",
"topology: DNS record off its host's address: directo-lab.hhefesto.dev",
"topology: tofu has undeclared host: xty"]
- observed : []testedAnd that exact list is itself a checked claim, so a rule that stops naming its failures fails CI.directo, branch plan-terranix at b60ae73 (local, not pushed), spec/BadNamed.bend, checks.facts-bad-named
No saved plan deletes what is kept
nix run .#tf -- lab plan saves the plan, has OpenTofu print it as JSON, and Bend checks that no deleted or replaced address is marked prevent_destroy. apply refuses a plan that has not passed, or that changed since.
plan-check: deletes ["ovh_cloud_project_storage.state"]; kept ["ovh_cloud_project_storage.state"]
SOME PROOFS FAIL
- expected : ["plan: deletes a kept resource: ovh_cloud_project_storage.state"]
- observed : []testedA plan that replaces the kept state bucket is refused; one that replaces the lab instance passes.directo, branch plan-terranix at b60ae73 (local, not pushed), checks.plan-check-must-fail, checks.plan-check
provedThe model's version, for every plan: plan_safe and plan_converges.directo, branch plan-terranix at b60ae73 (local, not pushed), spec/LAWS.bend
A gate that cannot fail proves nothing
| gate | must pass | must fail |
|---|---|---|
| the laws | spec/PROOF.bend --verdict | spec/FALSE.bend, a false law |
| scope and topology | the flake's facts | production in OpenTofu and deploy-rs, a shared address, a record off its host |
| the failures are named | spec/BadNamed.bend | (any rule that stops reporting) |
| plans | a plan replacing the lab | a plan replacing the kept state bucket |
| OpenTofu configs | tofu validate, both | (a schema error) |
| NixOS | every nixosConfiguration evaluates | (an evaluation error) |
claimedWhy: in oasis-infra, master failed to evaluate twice while CI stayed green, because CI built only one host; and a test suite did not compile for 111 commits.oasis-infra HANDOFF.md (2026-09-10), incidents
CI checks; only a person applies, installs or deploys
| command | who | guard |
|---|---|---|
checks, nix run .#spec | anyone, CI | none needed |
tf <cfg> plan | a person | credentials in mode-600 files on one machine |
tf <cfg> apply | a person at a terminal | refused under CI; needs a checked, unchanged plan and a typed confirmation |
lab-install | a person | typing "install lab": nixos-anywhere erases the disk |
lab-deploy | a person | deploy-rs, no auto-rollback |
cache-push | a person | signs with a key only agenix holds |
doneCI holds no provider token, no agenix identity and no ssh key; the scope rule proves no production host is a CI target.directo, branch plan-terranix at b60ae73 (local, not pushed), .github/workflows/infra.yml
Object lock, a narrow key, and a restore drill
- A nightly
pg_dump, then restic to an OVH bucket with versioning and object lock (governance mode). - The lab's S3 user may read, add and delete objects, but not erase a version or lift the lock: what the lab wrote stays for the lock's period, whatever happens to the lab.
- The drill: a fresh dump and snapshot, a restore into a scratch database, and every table's row count compared with the live one.
doneWritten and built into the lab's system.directo, branch plan-terranix at b60ae73 (local, not pushed), infra/tf/lab.nix, infra/hosts/lab.nix
openThe drill has not run: it needs the lab.directo, branch plan-terranix at b60ae73 (local, not pushed), infra/README.md
directo in production on xty: a nightly dump pulled out, and restored every time
olimpo ── ssh, pg_dump ──► xty's PostgreSQL 16 (directo, live)
│ ▲
▼ │ restore, count, md5, drop
restic repo (olimpo) ─────────┘ into directo_drill, next to directo
│
└── restic copy ──► delfos (when it is up)- The drill restores the newest snapshot into its own database on the live server, reads every table of both (row count and an md5 of all rows), and drops its copy. Verdicts: pass, differ (written since the dump), fail.
- It never writes the live database: restoring over it would erase what was written since the dump. Twelve laws pin that and the verdict.
- Nothing is pruned; forgetting old snapshots deletes backups, which waits for the owner.
measuredRun by hand on 2026-11-26: snapshot 176eca4c (32.4 KiB of SQL), drill pass on all 9 tables, about 23 s end to end; with a wrong password the drill fails and exits 1.enc (hhefesto's NixOS machines), commit cfd6ef1, directo-backup.bend; the run's log
provedThe twelve laws: the drill's database is never the live one, the dump only reads it, and the verdict fails on a missing, extra or renamed table or on nothing restored.enc (hhefesto's NixOS machines), commit cfd6ef1, directo-backup.bend, --verdict
openThe 02:15 timer is built into olimpo's system, not switched in yet; the copy to delfos has not run (delfos was off).enc (hhefesto's NixOS machines), commit cfd6ef1, olimpo.nix
So CI and the lab stop rebuilding Lean and the ghcjs frontend
- An OVH bucket of signed store paths;
nix run .#cache-pushsigns withdirecto-cache-1(the key is an agenix secret) and uploads the kernel, Lean, OpenTofu with its providers, and the lab's whole system. - Two S3 users: a writer, used from one machine, and a read-only one, the only one CI could ever get.
openWithout it, every CI run builds Lean v4.34.0 for the kernel before the first check; how long that takes on GitHub's runners is not timed yet.directo, branch plan-terranix at b60ae73 (local, not pushed), .github/workflows/infra.yml
openNot pushed yet: the bucket comes with the lab.directo, branch plan-terranix at b60ae73 (local, not pushed), infra/tf/lab.nix
From running xpsoasis's infrastructure
| incident | what it left |
|---|---|
| an automatic rollback that fired on a slow ssh reconnect and caused an outage (2026-07-07) | deploy-rs auto-rollback off; a person watches each deploy |
| two deploy targets pointing at one machine | a nodes-distinct check; here, the Distinct rule |
| a stale checkout deleted an account, then fail2ban locked the owner out | an access guard; here, access_silent: silent ⇔ live ⊆ new |
| a BIOS snapshot that would not boot on a UEFI server | a disk that boots either way |
| green CI, broken master | every host evaluated; a must-fail test per gate |
What the role asks, and where this deck shows it
| the role asks | shown here |
|---|---|
| Terraform | terranix + OpenTofu: state, locking, encryption, prevent_destroy, ignore_changes, drift (tf lab drift), import |
| Nix builders and binary caches | a signed S3 cache with a writer/reader split; closures built once |
| AWS | the S3 API (OVH's), IAM-style bucket policies, least privilege per user |
| reliability | a restore drill that runs on production (xty), object-locked backups for the lab, no auto-rollback, a gate per incident |
| security | agenix, encrypted state, credentials outside the repo and the store, CI with no keys |
| Cloudflare, bare metal (nice to have) | DNS in OpenTofu; OVH as the next host for xpsoasis's builder |
claimedFlox builds an AI release-engineering agent; this work also puts limits on an AI agent in code (CI without keys, person-only applies), after an agent overstepped them in practice.flox.dev; the owner's notes, 2026-11
xty first; the lab when the owner resumes it, then xpsoasis
leadOn xty: switch the backup timer in, see the first copy reach delfos, and keep the drill's verdicts.enc (hhefesto's NixOS machines), commit cfd6ef1, olimpo.nix
leadWhen the owner resumes it, run the lab: bootstrap, apply, install, deploy, drill, drift, cache, destroy. A d2-4 in Beauharnois is about US$0.024 an hour; two days cost under US$3 with storage.OVHcloud price list (prices from 2026-10-01); sparecores.com, d2-4
leadBring it to xpsoasis's oasis-infra, with the owner's approval: CI evaluating every host, the spec in CI, a scope check, dev and builder under OpenTofu by import, a binary cache, staging on OVH. Production is never touched.the owner's rule of 2026-11-26
leadA second deck, xpsoasis-devops.hhefesto.dev, for that work.the owner's request of 2026-11-26
What the proofs do not cover
- The proofs cover the model and the facts handed to it. The Nix that extracts the facts (infra/facts.nix), OpenTofu, the providers and NixOS are trusted, not verified.
- Bend's parser and its translation into the kernel are not proven (the guide says so).
- The lab has not run: every claim about it is done or open, none measured.
- The backup's laws cover its commands and its verdict; ssh, restic, PostgreSQL and the md5 are trusted.
claimed"--verdict checks the translated terms; the parser and translation into the kernel are not proven."Bend 2.0.39 README
Made with bend-frp
The slides are data in Bend (Deck.bend); bend-frp runs the page, and the navigation is a small pure machine (Nav.bend), the same as telomare.hhefesto.dev's.
provedIts laws: moving never changes the number of slides, next then back returns where you were, going to slide k lands on k, the keys and addresses mean what this page says, and every claim, table and card names a source. bend PROOF.bend --verdict prints ALL PROOFS CHECK.directo-devops-site's LAWS.bend and PROOF.bend