directo · devops
01directo · devops · 2026-11-26

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.

02The shape

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)
hostenvironmentproductionOpenTofudeploy-rsCI
xtyprodyesnonono
olimpodevnononono
lab (OVH BHS5, d2-4)labnoyesyesyes
directo, branch plan-terranix at b60ae73 (local, not pushed), infra/topology.nix

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

03Where Terraform, and where not

OpenTofu makes things; Nix decides what runs on them

concerntoolwhy
machines, DNS records, buckets, S3 usersOpenTofu (JSON from terranix)a reviewed plan instead of a console click; drift is visible
the OS installnixos-anywherean apply can never reinstall a box: boot_from is ignored after creation
what runs on the machineNixOSone closure, built and evaluated before any deploy
deploying itdeploy-rsauto-rollback off, as oasis-infra since an outage it caused
secretsagenixOpenTofu's state holds plain values; secrets never go there
directo, branch plan-terranix at b60ae73 (local, not pushed), infra/tf/lab.nix, infra/hosts/lab.nix

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

04State

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)

05Denotational design

Each thing gets a meaning first; operations are defined by what they do to it

thingmeaninglaw
pre-deploy checksconfig → list of failuresbuilding checks is a monoid homomorphism: Both ↦ ++, Pass ↦ []; passing both ⇔ passing each
scopewhat the tools act onthe scope rule is silent ⇔ (tofu ++ deploy ++ ci) ∩ production = ∅, and that splits per tool
promotionenvironment → commits it rannothing reaches production; a move happens ⇔ it is dev → lab and the commit ran on dev
OpenTofu plansresource → attributesapplying plan(desired, state) gives the desired state, except a kept resource is never deleted
ssh accessa set of keysthe guard is silent ⇔ every live key survives
backupssnapshots (age, paths)freshness distributes over more snapshots (or) and more paths (and)
directo, branch plan-terranix at b60ae73 (local, not pushed), spec/Model.bend, spec/LAWS.bend

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)

06Proved

Fourteen laws, by Bend's checker and again by the BendTT kernel

14laws in spec/LAWS.bend, each with its proof (and 16 lemmas)proveddirecto, branch plan-terranix at b60ae73 (local, not pushed), spec/PROOF.bend
0tactics: a proof is a Bend def; induction is recursion, rewriting is %edonedirecto, branch plan-terranix at b60ae73 (local, not pushed), spec/PROOF.bend
--verdictrechecks every proof with a kernel that has a proof in LeanclaimedBend 2.0.39 guide, "Laws and Proofs"
$ nix build .#checks.x86_64-linux.spec
directo-spec> ALL PROOFS CHECK

provedAmong 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

07The model, on the real thing

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

08Plans

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

09Every gate can fail

A gate that cannot fail proves nothing

gatemust passmust fail
the lawsspec/PROOF.bend --verdictspec/FALSE.bend, a false law
scope and topologythe flake's factsproduction in OpenTofu and deploy-rs, a shared address, a record off its host
the failures are namedspec/BadNamed.bend(any rule that stops reporting)
plansa plan replacing the laba plan replacing the kept state bucket
OpenTofu configstofu validate, both(a schema error)
NixOSevery nixosConfiguration evaluates(an evaluation error)
directo, branch plan-terranix at b60ae73 (local, not pushed), .github/workflows/infra.yml, infra/default.nix checks

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

10Who may act

CI checks; only a person applies, installs or deploys

commandwhoguard
checks, nix run .#specanyone, CInone needed
tf <cfg> plana personcredentials in mode-600 files on one machine
tf <cfg> applya person at a terminalrefused under CI; needs a checked, unchanged plan and a typed confirmation
lab-installa persontyping "install lab": nixos-anywhere erases the disk
lab-deploya persondeploy-rs, no auto-rollback
cache-pusha personsigns with a key only agenix holds
directo, branch plan-terranix at b60ae73 (local, not pushed), infra/README.md, "Who runs what"

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

11Backups the box can't erase

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

12Backups that ran

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

13A binary cache

So CI and the lab stop rebuilding Lean and the ghcjs frontend

  • An OVH bucket of signed store paths; nix run .#cache-push signs with directo-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

14Lessons carried over

From running xpsoasis's infrastructure

incidentwhat 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 machinea nodes-distinct check; here, the Distinct rule
a stale checkout deleted an account, then fail2ban locked the owner outan access guard; here, access_silent: silent ⇔ live ⊆ new
a BIOS snapshot that would not boot on a UEFI servera disk that boots either way
green CI, broken masterevery host evaluated; a must-fail test per gate
oasis-infra HANDOFF.md (2026-09-10), incidents and their fixes
15For Infrastructure & Operations at Flox

What the role asks, and where this deck shows it

the role asksshown here
Terraformterranix + OpenTofu: state, locking, encryption, prevent_destroy, ignore_changes, drift (tf lab drift), import
Nix builders and binary cachesa signed S3 cache with a writer/reader split; closures built once
AWSthe S3 API (OVH's), IAM-style bucket policies, least privilege per user
reliabilitya restore drill that runs on production (xty), object-locked backups for the lab, no auto-rollback, a gate per incident
securityagenix, 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
Flox, "Member of Technical Staff, Infrastructure & Operations" (jobs.ashbyhq.com/flox/87f6bc08)

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

16Next

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

17Limits

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

18This deck

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