gunk-dev/the-valley

valley.cue

sourcee01c23ce7dd3main's published tip history
4.3 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 // Push-mirror URLs. Every push to the primary replicates all branches
38 // and tags to each URL, force-updating and propagating deletions —
39 // the correct semantic for a mirror. Remote-only namespaces (e.g.
40 // GitHub's refs/pull/*) are never touched. Replication is best-effort:
41 // a dead mirror never rejects the primary push. Credentials are the
42 // host's concern (the installer documents how); they are not declared
43 // here.
44 mirrors: [...string] | *[]
45}
46
47// #Backup is the durability policy for the host's data: that an offsite
48// backup exists, how often it runs, and how long snapshots are kept. It is
49// deliberately host-level — one data directory, one repository — because
50// that is the host's reality today; per-project backup is a possible
51// growth path (a `backup` on #Project), not a present need. Only policy
52// is declared here: the repository URL, credentials, and host-key pinning
53// are machine integration and live with the installer, never here.
54#Backup: {
55 // Whether offsite backup runs for the host's data. Disabling never
56 // deletes anything: an existing backup repository is left untouched,
57 // merely no longer written to or pruned.
58 enable: bool | *true
59
60 // The backup target kind. restic over sftp (a Hetzner Storage Box,
61 // dcr-d7952bc) is the only target today; an object-store target
62 // would widen this to a disjunction ("restic-s3") — deliberately not
63 // before an implementation exists.
64 target: "restic-sftp"
65
66 // How often a snapshot is taken. "nightly" is the only cadence
67 // today; its exact wall-clock rendering is the installer's choice.
68 cadence: "nightly"
69
70 // How many snapshots to keep per tier when pruning (restic
71 // --keep-daily/--keep-weekly/--keep-monthly semantics). Every tier
72 // keeps at least one snapshot — a zero tier would silently thin
73 // history, so it is rejected rather than rendered.
74 retention: {
75 daily: int & >0 | *7
76 weekly: int & >0 | *4
77 monthly: int & >0 | *6
78 }
79}
80
81// The top level of this package is itself a host declaration: a config
82// file evaluated together with this schema is validated against #Host —
83// unknown fields and unsafe project names are rejected.
84//
85// cue vet -c schema/valley.cue <config>.cue
86// cue export schema/valley.cue <config>.cue
87projects: #Host.projects
88
89// Mirrors #Host.backup. CUE cannot reference an optional field, so the
90// constraint is restated against the same definition.
91backup?: #Backup
92
93// A file's top level cannot be closed (embedding #Host would open it
94// instead — embedding lifts closedness), so reject stray top-level fields
95// explicitly: anything but the #Host fields — a `project:` typo, a
96// deployment concern like `user:` — conflicts with this sentinel and
97// fails vet with an error naming the field.
98[!="projects" & !="backup"]: "INVALID: unknown top-level field; only \"projects\" and \"backup\" are allowed"