The code is the contract

Why a coding agent can change this cluster safely: every change is a diff to a typed description, every diff passes the same gates, and no secret is ever part of what the agent reads or writes.

Code is quoted from the repository and shortened. Addresses, keys, account identifiers, user names and domain names are replaced by <placeholders>.

What "contract" means here

A machine is not configured; it is described, and the description is checked before it is used. Three things make the description strict enough to trust.

Options have types

A service module declares what it accepts. A value outside the type is rejected when the configuration is evaluated, with the option's name and description in the message, so the mistake is caught at the desk.

# services/artifact-sharing/default.nix
scopes = lib.mkOption {
  type = lib.types.listOf scopeType;      # an enum: upload, read_private, delete, publish_public
  default = [ "upload" "read_private" "delete" "publish_public" ];
  description = "Scopes registered for this machine's token.";
};

Modules assert what must hold between machines

A role can refuse a cluster that makes no sense. These are checked for all five machines at once, which no per-host script can do.

assertions = [
  {
    assertion = lib.length servers == 1;
    message = "artifact-sharing: the client role needs exactly one server machine";
  }
];

# clan.nix: a feature flag that cannot be half-enabled
assert !featureFlags.buzzAgents || featureFlags.buzz;

The repository states its own rules

The file an agent reads first is short and checked in. It names the commands, the layout and three rules; everything else is discoverable from the code, and where a document and the code disagree the code wins.

# AGENTS.md
## Rules
- Never hardcode secrets — use Clan vars (SOPS)
- Build a machine before you deploy it (`clan machines build`)
- Custom services use `@rasyidanaf/<name>` naming

The change line

Every change, whoever wrote it, rides the same line. The gates get slower and stricter from left to right, and a change that fails one never reaches the next.

difflintevalbuildmachine
The change: one cardThree gates: lint, evaluate, buildHandwheel: a person runs the update

Send a change down the line

A valid change passes all three arches, waits at the handwheel, and is seated in the machine's free slot. An unused binding stops at the first arch, a wrong option type at the second, a package that does not compile at the third; each goes back to the cradle and the machine never sees it. The handwheel is turned by a person: the agent prepares the change, the operator account deploys it.

Gate 1 · format and lint, at commit

The dev shell installs the hooks. Formatting is not a matter of taste and dead code does not accumulate.

nix fmt                              # nixfmt
nix develop --command git push       # pre-commit hooks: statix, deadnix, shellcheck

Gate 2 · evaluate everything, offline

One command builds every offline check and evaluates every machine, package and module. It needs no access to any host, so an agent can run it as often as it likes. CI runs the same script on the staging VM's runner.

scripts/verify            # mode review: all offline Nix checks, every output evaluated
scripts/verify safety     # operator safety and publisher integration checks
scripts/verify full       # the above, plus a build of all five machines

# .forgejo/workflows/ci.yml
jobs.verify:
  runs-on: lab-nix
  steps:
    - uses: actions/checkout@v4
    - run: ./scripts/verify review

Gate 3 · build without deploying

A build produces the complete system closure for a machine. If it succeeds, the update that follows is a copy and a switch.

clan machines build hermes-vm      # nothing on hermes-vm changes

The handwheel · a person deploys

Deploying is a separate account with its own keys. The update copies the closure over the tailnet and activates it; the previous generation stays on the machine as the way back.

clan machines update hermes-vm     # run by the operator, from the control plane

Working with a coding agent

The same line is what makes it comfortable to hand the keyboard to an agent. The request is a sentence; the result is a diff that either passes the gates or says why not.

A request becomes a diff

Asked to try a service on staging, the agent adds one instance to the inventory. The whole change is reviewable in a few lines, and removing it later is the reverse diff.

# "put the pikpak gateway on lab-vm, read-write, loopback only"
+ pikpak-s3 = {
+   module = { name = "@rasyidanaf/pikpak-s3"; input = "self"; };
+   roles.server.machines."lab-vm".settings = {
+     rootFolderId = "<folder id>";
+     readOnly = false;
+   };
+ };

The loop the agent runs

Nothing here needs credentials for a production machine. The agent can iterate until the gates pass and hand over a change that is known to evaluate and build.

$EDITOR clan.nix                   # 1. change the description
nix fmt                            # 2. gate 1
scripts/verify                     # 3. gate 2: every machine still evaluates
clan machines build lab-vm         # 4. gate 3: the closure builds
git commit && git push             # 5. CI repeats gate 2 on the runner
# 6. the operator reads the diff and turns the handwheel

Promotion is a one-line move

A service proven on staging moves by changing the machine name in its role. The module, its options and its secrets declaration travel with it unchanged.

- roles.server.machines."lab-vm".settings = { … };
+ roles.server.machines."greencloud-vps".settings = { … };

Secrets stay outside the contract

The description is public to everyone who can read the repository, agents included. Secret values are not in it: the code holds names and paths, and the values travel sealed.

generatorsopsvars/ · in gitrecipientshermes-vmdecrypt/run/secretsservicesecretspeccf · pi · omp
The secret: lid up is plaintext, lid down is ciphertextKey cylinders: who can open itWall: the machine boundary

Stages

The capsule is open in only two places: where the value is first written, and on the one machine it was sealed for. Everything between, including the copy in git and the copy in transit, is closed. The rack holds one capsule per generator, 28 for this machine. Past the wall a service is handed a file path, and a command-line tool gets the value through SecretSpec, whose dial selects a scope so that one tool's token never enters another tool's environment.

Declared as a generator

A generator says what to ask for and what files result. Whether a file is secret, who owns it and whether it is deployed at all are part of the declaration.

clan.core.vars.generators.forgejo-runner-artifact-sharing = {
  files.id_ed25519 = { secret = true; owner = "gitea-runner"; mode = "0400"; };
  files."id_ed25519.pub" = { secret = false; deploy = false; };   # public half stays in the repo
  runtimeInputs = [ pkgs.openssh ];
  script = ''
    ssh-keygen -q -t ed25519 -N "" -f "$out/id_ed25519"
  '';
};

Stored as ciphertext, per recipient

Each secret file is its own directory. The recipients are visible as links, so who can decrypt a value is a fact in the tree and a change to it is a diff.

vars/per-machine/hermes-vm/hermes-openrouter/openrouter-api-key/
├── secret                    # SOPS ciphertext
├── machines/hermes-vm        # recipient: this machine's key
└── users/<admin>             # recipient: the admin's key

Consumed as a path

A module never sees the value. It refers to where the file will be at runtime, and the unit reads it there.

tokenFile = config.clan.core.vars.generators.forgejo-actions-runner.files."registration.env".path;

SecretSpec: from files to one process

Interactive tools expect environment variables. A manifest generated by Nix maps variable names to the runtime files and groups them into scopes; it contains names and paths only. SecretSpec is an injection layer here, not a second store.

# generated manifest (shown expanded)
[providers]
clan = "file:///run/secrets"

[profiles.default]
OPENROUTER_API_KEY = { providers = ["clan"], ref = { item = "vars/hermes-openrouter/openrouter-api-key" } }

[scopes.ai-tools]
secrets = ["…"]

[scopes.cloudflare]
secrets = ["CLOUDFLARE_API_TOKEN"]      # never enters an AI tool's environment

A wrapped command

The Cloudflare CLI is installed as a wrapper. A policy guard runs first, without credentials; only the command it allows is started inside the cloudflare scope, and the token exists in that child process alone.

# modules/hermes-toolbox.nix
cfRunner = "${config.services.aiSecrets.packages.bridge}/bin/with-ai-secrets cloudflare ${lib.getExe cf-cli}";
cfCommand = pkgs.writeShellScriptBin "cf" ''
  exec node cf-guard.mjs ${cfRunner} -- "$@"
'';

# what the connector does
secretspec run --file <manifest> --provider "file://$secret_root" --scope "$scope" -- "$@"

One limit worth stating: scopes prevent accidental spread, not a hostile process. Anything running as the agent's user can read that user's secret files directly, and that user is trusted by Nix.