- Replace stale ~/Sites references with ~/Workloads across README.md, AGENTS.md, docs/architecture.md, docs/operations.md, and ROADMAP.md (ADR-0004) - Document homelab.workloadGrants, /etc/homelab/grants.json, scripts/workload_grants.py, and nixos/instance.example.nix (ADR-0005) - Link ADR-0004 and ADR-0005 in ROADMAP.md and record Milestone P4.5 completion in nixos-core
8.5 KiB
Canopy NixOS Core — Agent Guidelines
1. Project Overview & Architectural Boundaries
Canopy NixOS Core (canopy-homelab/nixos-core) defines the declarative NixOS host foundation, shared platform infrastructure services, security boundaries, and the appctl operational control plane for the Canopy ecosystem. Independent application workloads live in ~/Workloads/<app> and integrate through declarative app.yaml manifests and workload-scoped Docker Compose files.
Core vs. ~/Workloads Ownership
- Core owns: NixOS host configuration (
nixos/instance.example.nixtemplate for/etc/nixos/homelab-instance.nix), shared platform services (edge ingress, SSO/LDAP, mail, log/update monitors), platform-level ports and security policy (includinghomelab.workloadGrants->/etc/homelab/grants.json), and orchestration/deployment mechanics (appctl,gitops_dispatcher.py,workload_grants.py). ~/Workloadsowns: Independently deployed application workloads, workload-specificdocker-compose.ymltopologies, workload intent (app.yaml), anddeployments.yaml.- Boundary Rule: Never hardcode workload-specific domains, ports, containers, environment variables, or deployment policies in Core (
scripts/appctl*, GitOps, or Coredocker-compose.yml), and never move Core platform services into~/Workloads. When ownership is ambiguous, consultdocs/architecture.mdbefore changing the boundary.
Context Discovery Hierarchy
Before proposing or implementing changes, establish context in this order:
- Architectural Decisions (
docs/decisions/): Checkdocs/decisions/README.mdand local ADRs for binding design commitments. - Runtime Contracts (
docs/): Consultdocs/architecture.md,docs/appctl.md,docs/gitops.md, anddocs/secrets-and-state.mdfor current behavior. - Trajectory & Active Work (
ROADMAP.md,todo.txt,git log): Verify whether a capability belongs to the current baseline or a planned milestone before modifying code.
When a requested change conflicts with an architectural invariant or accepted ADR, stop and surface the conflict before implementing a workaround.
2. Build, Lint & Verification Commands
The Python environment (python3, pytest, pydantic, pyyaml, types-pyyaml) and static analysis tools (ruff, pyright) are provisioned hermetically by flake.nix and automatically symlinked to .venv via the Nix devShell hook (.envrc). Do not create separate uv or pip virtual environments that split from the Nix store environment.
Every implementation step must close with the automated verification gate before proposing a commit:
# Full verification gate: Ruff + Pyright + Pytest (124+ tests) + nix flake check + NixOS drv eval
./scripts/run-tests
# Targeted fast iteration commands (inside direnv / nix develop, or via .venv)
ruff check .
pyright
.venv/bin/pytest tests/
When modifying container or Compose definitions, also validate Compose syntax:
docker compose config -q
3. Code Style & Contract Guidelines
- Fail-Closed Validation (
scripts/core_manifest.py): All external inputs (app.yamlmanifests, webhook payloads, CLI arguments, daemon payloads) must be validated through strict Pydantic v2 models (ConfigDict(extra="forbid")). - Explicit Error Handling: Never swallow diagnostic
stderrsilently (e.g., avoid blind2>/dev/nullon engine or manifest commands). Surface actionable validation errors while redacting sensitive material. - Platform Genericism: Keep all code, templates, tests, and documentation strictly instance-agnostic:
- Inject routing and service identities at runtime via environment variables (
HOMELAB_DOMAIN,DOMAIN_SUFFIX). - Use RFC 2606 placeholders (
example.com,example.org,example.test) in tests and configuration examples—never personal domains or operator usernames. - In historical documentation or milestone records, use descriptive phrasing (e.g., "the configured
smtp.<domain>endpoint") rather than fabricating placeholder domains as historical facts.
- Inject routing and service identities at runtime via environment variables (
4. Testing Instructions (TDD)
- TDD-First: Write or update failing unit, structural, or security tests in
tests/before or alongside implementation changes. - No Tautological Tests: Every test must import and execute real production modules or scripts (
core_manifest,appctl_engine,gitops_dispatcher,scripts/appctl) and assert on observable outcomes. Never write tests that only inspect local mock strings, hardcode expected outputs into the fixture under test, or continue passing when the production invariant is broken. - Protect Invariants: Do not bypass failing tests by weakening or deleting an invariant assertion unless the architecture itself has intentionally changed via an approved ADR.
5. Security & State Invariants
- Workload Manifests (
app.yaml): Describe declarative workload identity, routing metadata, and deployment intent only. Never introduce arbitrary command execution, host filesystem paths, privileged flags, or Docker control capabilities intoapp.yaml. - GitOps Trust Boundary (
scripts/gitops_dispatcher.py):- Webhook admission requires cryptographic authentication (HMAC-SHA256).
- Repository identity and filesystem paths must be resolved strictly through the trusted workloads registry (
~/Workloads/deployments.yamlorHOMELAB_DEPLOYMENTS_FILE, templated byconfig/deployments.yaml)—never directly from webhook payloads. - Execution must remain allowlisted, serialized (
flock), pre-validated by the Compose AST security checker, and free of shell interpolation (shell=False, noeval).
- Docker & Privilege Isolation:
socket-proxyis the only service permitted to mount/var/run/docker.sock(strictly:ro, read-only API capabilities only;POST=0,DELETE=0,BUILD=0,EXEC=0).- Never add
privileged: true, host namespace sharing, or direct Docker socket mounts to workload or control-plane containers.
- Declarative Configuration vs. Secrets & Runtime State:
- Git stores declarative configuration and reproducible definitions only. Never commit plaintext secrets, keys, password hashes, certificates, or runtime databases.
- Host secrets are managed via SOPS (
sops-nix) and projected to/run/secrets/. - Persistent mutable runtime state belongs in dedicated host state directories (
~/var/lib/homelab/<app>/) or Docker volumes excluded from version control.
6. Documentation, Task Tracking & Git Workflow
- Synchronize Documentation (
docs/): Update repository documentation alongside code changes that alter behavior, contracts, or operations. Keep all Markdown formatted in GitHub-Flavored Markdown compatible with both Obsidian and the live documentation viewer. - Architecture Decision Records (
docs/decisions/): Record binding repository-level architectural decisions in MADR 4.0 format (NNNN-slug.md) and register them indocs/decisions/README.md. - Live Task Tracking (
todo.txt): Maintain a comment-free roottodo.txtformatted fortuxedo/todo.sh((A)–(C)priorities,+<project>,@<context>) reflecting the current milestone. Mark verified deliverables completed (x YYYY-MM-DD ...) immediately. - Git & Commits:
- Never commit directly to
main/master. - Never run destructive Git commands (
reset --hard,restore,clean -fd,push --force) without explicit user confirmation. - Stage atomic changes and use Conventional Commits (
feat,fix,refactor,test,docs,chore), waiting for user approval before committing. - Preserve The Unlicense across the repository.
- Never commit directly to
Organization Planning Sync Contract
- Ecosystem Hub: Master roadmap and cross-repo plans live in
canopy-homelab/.profile(ROADMAP.md,docs/plans/,todo.txt). - Organization Kanban Board: Canopy Platform (
https://gitea.<domain>/canopy-homelab/-/projects/7, Project ID:7). - Column IDs (Deep Signal):
Backlog->30(default),Ready->31,Work in Progress->32,Review->33,Completed->34. - Mirror Policy: Primary sovereign Gitea forge (
canopy-homelab/nixos-core); GitHub (canopy-homelab/nixos-core) is an automatedsync_on_commitpush mirror. - Re-sync Trigger: Re-run
/gitea-planon scope shifts or before decomposing the next rolling milestone (P5/P6/P7).