Files
nixos-core/docs/decisions
kiskaadee 37d529848a docs(adr): resolve Stage 7 critic findings in ADR-0005 and README
- Close user: primary GID, device_cgroup_rules:, and network_mode: container:* bypasses
- Specify post-interpolation validation, long/short volume syntax, :ro, and :rwm mknod ban
- Reconcile absent vs unreadable/malformed grants.json behavior and permissions checks
- Add Consequences and More Information sections; sync docs/decisions/README.md
2026-11-21 00:26:44 -05:00
..

🏛️ Homelab Core & Appctl Architecture Decision Index

This document serves as the authoritative repository index for Architectural Decision Records (ADRs) governing Homelab Core and the appctl Operational Control Plane.

Repository-level architectural decisions are recorded in docs/decisions/ using the MADR 4.0 specification (NNNN-slug.md).


📋 Active Architectural Decisions

Decision Record Status Date Scope & One-Line Purpose
ADR-0005: Host-Granted Workload Capabilities accepted 2026-11-20 Amends ADR-0002 to introduce homelab.workloadGrants (/etc/homelab/grants.json) and nixos/instance.example.nix so NixOS hosts explicitly authorize devices, groups, and readOnlyPaths per workload while keeping host/container networking prohibited.
ADR-0004: Unified ~/Workloads Monorepo & State Isolation accepted 2026-11-16 Amends ADR-0001 to adopt the unified ~/Workloads Tier 2 monorepo (canopy-workloads), rename ~/Sites to ~/Workloads with WORKLOADS_DIR fallback, and enforce ~/var/lib/homelab/<app>/ state isolation.
ADR-0003: Centralized Runtime Validation & Serialization via Pydantic v2 accepted 2026-10-15 Adopts Pydantic v2 as the single runtime schema and validation authority across workload manifests and daemon API to enforce fail-closed type safety, strict schema-based boundaries, and secret-safe serialization.
ADR-0002: Homelab Operational Control Plane & Deployment Model Architecture accepted 2026-10-07 Establishes homelab-appctl.service as the central operational control plane daemon, one logical command API (POST /v1/operations) across dual transports (UDS and HTTP), mandatory token auth with UDS SO_PEERCRED viewer fallback, dedicated service isolation, fail-closed audit logging, GitOps worker unification, and deterministic Git-backed declarative deployment state.
ADR-0001: Homelab 3-Tier Architecture & Deployment Provenance Model accepted 2026-09-28 Establishes 3-tier separation (Software, OCI Artifact, Sites Deployment, Core Platform), two workload classes (Source-Backed vs. Image-Only), isolated state root (~/var/lib/homelab/<app>/), and two operational inspection axes.

🧭 Summaries of Governing Decisions

ADR-0005: Host-Granted Workload Capabilities ("Compose Requests, Nix Grants")

  • Canonical Document: 0005-workload-capability-grants.md
  • Status: accepted (Active — Amends ADR-0002)
  • Core Commitments:
    1. Typed Host Grant Schema (homelab.workloadGrants): NixOS exposes per-workload devices, groups, and readOnlyPaths grants while keeping privileged: true, docker.sock, cap_add, device_cgroup_rules, and host/container namespace sharing permanently forbidden.
    2. Immutable Host Projection (/etc/homelab/grants.json): Projected root-owned at rebuild time; absent file defaults to zero grants, malformed file fails closed.
    3. Exact-Match Pre-Flight Enforcement: validate_compose_security() allows requested capabilities only when canonically matched against the workload's Nix grant (and :ro for readOnlyPaths).
    4. Tracked Instance Template (nixos/instance.example.nix): Documents homelab.domain, homelab.operatorUser, and homelab.workloadGrants for /etc/nixos/homelab-instance.nix.

ADR-0004: Unified ~/Workloads Monorepo & State Isolation

  • Canonical Document: 0004-unified-workloads-monorepo.md
  • Status: accepted (Active — Amends ADR-0001)
  • Core Commitments:
    1. Tier 2 Rename (~/Sites -> ~/Workloads): Canonical Tier 2 deployment root is ~/Workloads, with WORKLOADS_DIR -> SITES_DIR environment fallback.
    2. Unified canopy-workloads Monorepo: Tier 2 workload manifests (app.yaml, docker-compose.yml) consolidate under ~/Workloads/<app>/, supporting hybrid per-app .git checkouts during migration.
    3. Mandatory State Isolation: All mutable application data resides strictly under ~/var/lib/homelab/<app>/ (or named Docker volumes), never inside ~/Workloads.
    4. Workloads Registry & Safe Directory Containment: ~/Workloads/deployments.yaml (templated by config/deployments.yaml) resolves admitted workloads within WORKLOADS_DIR; NixOS safe.directory includes ~/Workloads and ~/Workloads/*.

ADR-0003: Centralized Runtime Validation & Serialization via Pydantic v2

  • Canonical Document: 0003-pydantic-v2-runtime-validation.md
  • Status: accepted (Active)
  • Governing Implementation Plan: ROADMAP.md (Milestone P4)
  • Core Commitments:
    1. Single Schema & Validation Layer: Workload manifests (core_manifest.py) and API command models inherit from pydantic.BaseModel.
    2. Fail-Closed Extra Fields (extra="forbid"): Immediate rejection of unexpected or undocumented payload properties.
    3. Strict Typing Policy (strict=True): Coercion forbidden on operations, targets, identifiers, and flags.
    4. Secret-Safe Error Transformation: Transport-level conversion of ValidationError into standard ERR_VALIDATION_FAILED (400) with raw input values redacted.
    5. Dual-Transport Parity: Identical validated models across Unix domain socket and HTTP transports.

ADR-0002: Homelab Operational Control Plane & Deployment Model Architecture

  • Canonical Document: 0002-appctl-control-plane-architecture.md
  • Status: accepted (Active — Reconciled with Pre-P4 Locked Decisions DEC-01–DEC-05)
  • Governing Implementation Plan: ROADMAP.md (Roadmap v6)
  • Core Commitments:
    1. One Logical Command API Across Dual Transports (DEC-01): homelab-appctl.service exposes POST /v1/operations (13 canonical domain operations) and GET /v1/health over HTTP/1.1 on /run/homelab/appctl.sock and 127.0.0.1:9001.
    2. Host Access Does Not Confer Mutation Authority (DEC-02): Every mutating operation and sensitive read (workload.config, workload.logs) requires an authenticated SHA-256 Bearer token (/run/secrets/appctl/tokens.json); tokenless UDS calls fall back via SO_PEERCRED strictly to homelab-viewer read-only inspection.
    3. Dedicated Service Identity & Fail-Closed Audit Guard (DEC-03): Daemon executes as homelab-appctl:homelab-operators with mode 0600 append-only /var/log/homelab/appctl/audit.jsonl and a pre-execution DISPATCHED disk guard.
    4. GitOps Worker Unification & Pure-Python Pre-Flight (DEC-04, DEC-05): gitops_dispatcher.py worker delegates workload.update to the daemon; shell source/eval are replaced with pure-Python .env parsing and mandatory validate_compose_security() pre-flight checks.
    5. Git Truth, Model Context Protocol (MCP) Gateway & AI Boundary (P5–P7): Git remains authoritative deployment state; on-server AI proposal compilers deprecated in favor of a decoupled Model Context Protocol (MCP) tool gateway with human confirmation gating; resolves workload secrets via SecretProvider (secretKeyRef).

ADR-0001: Homelab 3-Tier Architecture & Deployment Provenance Model

  • Canonical Document: 0001-3tier-architecture-and-provenance.md
  • Status: accepted (Active)
  • Governing Implementation Plan: ROADMAP.md (Roadmap v6)
  • Core Commitments:
    1. 3-Tier Separation of Concerns:
      • Tier 1 (Software Layer): Upstream application repositories owning code, tests, and CI. Zero Homelab infrastructure coupling.
      • Intermediate Provenance Artifact: OCI container images produced by CI carrying commit provenance in metadata labels and content-addressed digests.
      • Tier 2 (Sites Deployment Layer): Declarative manifests (app.yaml) and Compose specs in ~/Sites.
      • Tier 3 (Platform Core Appliance): NixOS host foundation, edge routing, SSO, and operational controllers.
    2. Two Workload Deployment Classes:
      • Class A (Source-Backed): Declares upstream Git source and ref (source.url, source.ref); tracks upstream Git revisions against container labels.
      • Class B (Image-Only): Standard third-party tools; tracks container registry image tags and digests.
    3. Isolated Persistent State Root: Mutable data lives strictly under ~/var/lib/homelab/<app>/, isolated from Git repositories.
    4. Two Operational Inspection Axes: Local deployment checkout state evaluated independently of upstream software provenance (resolved via git ls-remote).

📜 Superseded Historical Decisions & Lineage

The following historical plans and design iterations have been formally superseded by the active ADRs and Roadmap v6:

  • Roadmap v5 (architecture-consolidation-roadmap-v5.md): Superseded by Roadmap v6 (DEC-01–DEC-05 pre-P4 boundary lock).
  • Roadmap v4, v3, v2 & v1 (architecture-consolidation-roadmap-v4.md): Superseded by Roadmap v5/v6.
  • appctl-v2 Modernization Plan (appctl-engine-v2-refactoring.md): Scaffolded and absorbed into Roadmap Phases P0 and P3.
  • Smart Selective Deployment Pipeline Plan (smart-deployment-pipeline.md): Absorbed into Phase P4 control-plane reconciliation.
  • Architecture Implementation Guide v3 & v2 (architecture-consolidation-implementation-guide-v3.md): Superseded by unified Roadmap v4–v6.