gunk-dev/the-valley

valley.cue

source88ce2e6698d0main's published tip history
4.4 KiB
1// Package valley is the canonical domain model of a valley host: what the
2// host serves, independent of any machine that serves it.
3//
4// This file is deliberately not Nix. The NixOS module in this repo is one
5// installer that consumes the model (`cue vet` + `cue export` at build
6// time); other installers and tools read the same file. Deployment concerns
7// — data directory, unix user, SSH keys — are machine integration and live
8// with the installer, never here.
9package valley
10
11// #Host is a complete valley host declaration: the set of projects the
12// host serves, and the durability policy for the data behind them.
13#Host: {
14 // projects maps a project name to its declaration. Names must be
15 // filesystem- and URL-safe because they become on-disk directory
16 // names ("<name>.git") and clone paths.
17 projects: [=~"^[a-zA-Z0-9][a-zA-Z0-9._-]*$"]: #Project
18
19 // The host's offsite-backup policy. Optional: a declaration without
20 // it is a host without offsite backup, and evaluates exactly as it
21 // did before this field existed.
22 backup?: #Backup
23}
24
25// #Project is the unit of declaration. A project *has* stores; git is the
26// only store type today, and it is nested rather than top-level on
27// purpose — the valley is not committed to being git-only.
28#Project: {
29 // The project's git store.
30 git: {
31 // Whether the host serves a git repository for this project.
32 // Disabling never deletes anything: an existing repository is
33 // left untouched on disk, merely unmanaged.
34 enable: bool | *true
35 }
36
37 // Publication-mirror URLs. Every push to the primary replicates main
38 // and the tags to each URL, force-updating and propagating deletions.
39 // Only those: a mirror publishes what has been integrated, and topic
40 // branches awaiting review are not published. Any other branch on a
41 // mirror is removed. Remote-only namespaces (e.g. GitHub's
42 // refs/pull/*) are never touched. Replication is best-effort: a dead
43 // mirror never rejects the primary push. Credentials are the host's
44 // concern (the installer documents how); they are not declared here.
45 mirrors: [...string] | *[]
46}
47
48// #Backup is the durability policy for the host's data: that an offsite
49// backup exists, how often it runs, and how long snapshots are kept. It is
50// deliberately host-level — one data directory, one repository — because
51// that is the host's reality today; per-project backup is a possible
52// growth path (a `backup` on #Project), not a present need. Only policy
53// is declared here: the repository URL, credentials, and host-key pinning
54// are machine integration and live with the installer, never here.
55#Backup: {
56 // Whether offsite backup runs for the host's data. Disabling never
57 // deletes anything: an existing backup repository is left untouched,
58 // merely no longer written to or pruned.
59 enable: bool | *true
60
61 // The backup target kind. restic over sftp (a Hetzner Storage Box,
62 // dcr-d7952bc) is the only target today; an object-store target
63 // would widen this to a disjunction ("restic-s3") — deliberately not
64 // before an implementation exists.
65 target: "restic-sftp"
66
67 // How often a snapshot is taken. "nightly" is the only cadence
68 // today; its exact wall-clock rendering is the installer's choice.
69 cadence: "nightly"
70
71 // How many snapshots to keep per tier when pruning (restic
72 // --keep-daily/--keep-weekly/--keep-monthly semantics). Every tier
73 // keeps at least one snapshot — a zero tier would silently thin
74 // history, so it is rejected rather than rendered.
75 retention: {
76 daily: int & >0 | *7
77 weekly: int & >0 | *4
78 monthly: int & >0 | *6
79 }
80}
81
82// The top level of this package is itself a host declaration: a config
83// file evaluated together with this schema is validated against #Host —
84// unknown fields and unsafe project names are rejected.
85//
86// cue vet -c schema/valley.cue <config>.cue
87// cue export schema/valley.cue <config>.cue
88projects: #Host.projects
89
90// Mirrors #Host.backup. CUE cannot reference an optional field, so the
91// constraint is restated against the same definition.
92backup?: #Backup
93
94// A file's top level cannot be closed (embedding #Host would open it
95// instead — embedding lifts closedness), so reject stray top-level fields
96// explicitly: anything but the #Host fields — a `project:` typo, a
97// deployment concern like `user:` — conflicts with this sentinel and
98// fails vet with an error naming the field.
99[!="projects" & !="backup"]: "INVALID: unknown top-level field; only \"projects\" and \"backup\" are allowed"