gunk-dev/the-valley

valley.cue

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