Sovereign infrastructure from one typed specification: a server, its websites, DNS, git, backups and recovery
sov docs design.md
4.6 kB 72 lines
Markdown
at main

sov: design #

sov turns one typed specification (an instance repository) into a running server and keeps it that way. This file is the design; the code in this repository is the implementation.

Goal #

From "a VPS was just ordered" to "everything works" with one command, every time, with no step that only exists in someone's memory.

  • Configuration (OS, services, sites) comes from the instance repository.
  • State (git repositories, statistics, server-only secrets) comes from the source bucket and is restored by the starter before the server first starts.
  • Secrets that are typed in or shared with outside services live encrypted in the instance repository; the owner's key unlocks them.

Three places #

Place Holds
The instance repository the specification (spec/), the sites, the shared secrets
sov (this repository) how everything is derived from a specification
The server's disk the running system and the state
The source bucket (Hetzner Storage Box) the system of record for the state: encrypted restic snapshots every 5 minutes, box snapshots on top

Nothing else holds anything that matters. Certificates, DNS zones, healthchecks.io checks and the like are derived: the server recreates them from the description.

Layers #

Layer Tool Lives in
Server OS, services, firewall, users NixOS 26.05 (flake, pinned by flake.lock) modules/ (the machine: modules/machine.nix, from spec.server)
Disk layout / first install disko / nixos-anywhere (the starter) modules/machine.nix, engine/starter.nix
Updates the reconciler realizes the server from the graph (versions accepted by one who may accept them) engine/reconcile.py, modules/reconcile.nix
HTTPS Caddy, automatic certificates (Let's Encrypt, ZeroSSL fallback) modules/caddy.nix, modules/sites.nix
DNS Knot as hidden primary; Hetzner's three nameservers as secondaries (signed transfers and NOTIFY); CAA limits certificate issuers modules/dns.nix
Git hosting Tangled knot, the git lens: each repository a tree of the graph at its familiar paths modules/knot.nix, lens/git
Statistics GoatCounter, fed from Caddy's access logs (no script on the pages) modules/stats.nix
Backups restic → Storage Box (5 min), daily prune + partial read check + test restore; restore on fresh install modules/backup.nix
The server's own key created once on the server, kept as state: it opens the graph's sealed values modules/secrets.nix
Shared secrets sealed values of the graph (the owners' keys and the server's), opened for the units at start modules/graph-secrets.nix
Alarms healthchecks.io (synced from spec.heartbeats), email + ntfy push modules/heartbeats.nix
Recovery drill monthly, by the owner: the server installs the starter on a temporary Hetzner VM; the owner's operator key (over SSH) opens the bucket and the host key, the starter realizes the copy from the graph (cut off from the outside); compared with the server, the VM deleted engine/starter.nix, modules/drill.nix, modules/drill-target.nix
Live checks invariants, hourly: sites, certificates, redirects, DNS serials and delegation, knot, stats, disk modules/checks.nix

The instance's tree #

sites/<name>/          each website's source with a package.nix (may use sov.staticSite, sov.fonts)
secrets/host_key.pub   the server's SSH host key's public half (the key itself: a secret of the graph)
host/                  optional: anything about the machine the description does not cover

The description itself (what spec/schema.nix checks) is values of the graph: the server's, each site's, each zone's records.

Every module declares the folders it keeps (sov.state); together they are what the source bucket holds and what a fresh install restores. Users owning such folders have fixed ids, because restic stores owners as numbers.

Domains #

Registrar: INWX, nameservers from spec.dns.nameservers. The parent zones' delegation is checked by invariants; changing it is one of the steps in operations.md.

Verification #

  • nix flake check: evaluates the spec, builds everything, boots the base config in a VM test.
  • On the server: invariants (hourly, and on demand with systemctl start invariants).
  • Recovery: daily, a restore into a scratch directory with database and repository checks; monthly, a full recovery drill onto a temporary VM (systemctl start recovery-drill runs one now).