Repository navigation
feat(template): author repo configuration in Nix (ADR 0013 prototype) - #44
Draft
cooper (czxtm) wants to merge 1 commit into
Draft
cooper (czxtm) wants to merge 1 commit into
cooper (czxtm) wants to merge 1 commit into
Conversation
Prototype for ADR 0013 (proposed): configuration the repo controls is written in Nix, and the files tools read are rendered outputs committed where each tool looks for them. `x files` (nix run .#write-files) writes them; `nix flake check` gets one check per file and fails on drift. - Add the mightyiam/files flake-parts module and nix/files/, with pure JSON/YAML/lines renderers evaluated by Nix. - Render tsconfig.json, .gitignore, .gitattributes, the CI workflow, .config/dependency-cruiser.json (was .cjs), .github/renovate.json, and .sops.yaml. Rendered outputs are semantically identical to the files they replace, except the two fixes below. - Keep operational sources under ops/: ops/secrets/sops.nix renders the root .sops.yaml, ops/policies/dependencies/renovate.nix renders .github/renovate.json. - Fix sops rule selection: sops reads the nearest .sops.yaml above the working directory, so ops/secrets/.sops.yaml was skipped when sops ran from the repo root. Its rule now lives in the root config. - Fix Renovate discovery: it never read ops/policies/dependencies/. Rendered files are disabled for Renovate, and a regex manager updates action versions in the Nix source instead. - oxfmt skips files marked linguist-generated in .gitattributes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prototype for ADR 0013 (proposed): author configuration in Nix.
Every config file in the repo is written in Nix. The files tools actually read are rendered from that source and committed wherever each tool looks for them. JSON is only hand-written for data.
How it works
nix/files/uses thefilesflake-parts module. Each source declaresfiles.file."<path>".text.x files(nix run .#write-files) writes the outputs.nix flake checkgets onefiles:<path>check per output and fails if the committed copy differs. I tested this: a hand edit totsconfig.jsonfails the check.nix/files/render.nixrenders JSON, YAML and line-based files as pure Nix functions with no build step, sonix evalshows exactly what gets written.run:steps..gitattributesmarks every output aslinguist-generated. GitHub collapses them in diffs, andvite.config.tsreads that list so oxfmt doesn't reformat them.ops/secrets/sops.nix→.sops.yamlops/policies/dependencies/renovate.nix→.github/renovate.jsonnix/files/*→ repo plumbingtsconfig.jsonnix/files/tsconfig.nix.config/dependency-cruiser.json(was.cjs)nix/files/dependency-cruiser.nixrequire()of the old.cjs.github/workflows/ci.yamlnix/files/ci-workflow.nix.gitignorenix/files/gitignore.nixgit check-ignoreresult on 26 paths.sops.yamlops/secrets/sops.nix.github/renovate.jsonops/policies/dependencies/renovate.nix.gitattributesnix/files/default.nixTwo fixes this makes
.sops.yamlstarting from the directory it runs in and moving up, not from the file's location. Sosops ops/secrets/x.sops.yamlrun from the repo root used the root rules: the CI, keyservice and cooper keys, encrypting every field. It never usedops/secrets/.sops.yaml(the deploy key, encrypting onlydata/stringData). I reproduced this. Theops/secrets/rule now lives in the root config, and I confirmed it applies whether sops runs from the repo root or from insideops/secrets.ops/policies/dependencies/renovate.jsonisn't one of the paths Renovate checks. It's now rendered to.github/renovate.json.What to watch when this merges
pinDigestsfor Dockerfiles and compose files starts applying and Renovate will open pin PRs.uses = "…";lines innix/files/*.nixinstead. I confirmed with a localrenovate --platform=localextract that it finds all four actions. Expect chore(deps): update actions/checkout action to v7 #11 (actions/checkoutv7) to be recreated against the Nix source.nix/files/, so they ship the rendered files as ordinary files.Left out on purpose (stacked follow-ups if you like this)
ops/composeandops/config/*.conf: move to services-flake (Postgres/Redis/nginx/Prometheus/Grafana configured in Nix, no Docker needed locally).ops/deploy/kubernetesandops/environments: render with nixidy (CI generates plain manifests for the GitOps controller).ops/deploy/terraform: these are only variables/outputs stubs, so delete them in favor of Alchemy (ADR 0004).ops/policies/repo-root/allowedand the Prometheus/OTel/Loki YAML.Verification
bun install --frozen-lockfile,bun run prepare,check,test(12/12),lint(exit 0; 3 new advisory Effect-style warnings invite.config.ts),fmt:check,lint:root,lint:boundaries.smokelocally: allfiles:*checks,template-slices,treefmt,bun-version. CI runssmokeand the fullnix flake check.ops/secrets.renovate-config-validatorand a local Renovate extract.The
flake.lockentry forfileswas computed from a git fetch of the locked rev, because GitHub tarball downloads are blocked where this was built. CI fetches the tarball and checks the hash.Generated by Claude Code