From 9ac44d0baab0f24a608603d3cc4c4d044da27edd Mon Sep 17 00:00:00 2001 From: kiskaadee Date: Mon, 16 Nov 2026 13:57:54 -0500 Subject: [PATCH] docs(adr): add ADR-0004 for unified ~/Workloads monorepo and state isolation (#33) - Author MADR 4.0 ADR-0004 amending ADR-0001 to adopt the unified ~/Workloads Tier 2 monorepo (canopy-workloads), rename ~/Sites to ~/Workloads with WORKLOADS_DIR -> SITES_DIR fallback, and enforce ~/var/lib/homelab// state isolation - Register ADR-0004 in docs/decisions/README.md active decisions table and summaries --- .../0004-unified-workloads-monorepo.md | 91 +++++++++++++++++++ docs/decisions/README.md | 10 ++ 2 files changed, 101 insertions(+) create mode 100644 docs/decisions/0004-unified-workloads-monorepo.md diff --git a/docs/decisions/0004-unified-workloads-monorepo.md b/docs/decisions/0004-unified-workloads-monorepo.md new file mode 100644 index 0000000..26e519a --- /dev/null +++ b/docs/decisions/0004-unified-workloads-monorepo.md @@ -0,0 +1,91 @@ +--- +type: decision +status: accepted +project: homelab-core +date: 2026-11-16 +tags: [architecture, workloads, monorepo, gitops, state, nixos] +amends: 0001-3tier-architecture-and-provenance.md +--- + +# ADR 0004: Unified ~/Workloads Monorepo & State Isolation + +## Context and Problem Statement + +Under [ADR-0001](0001-3tier-architecture-and-provenance.md), Tier 2 deployment descriptors (`app.yaml` and `docker-compose.yml`) were hosted in `~/Sites/` as one standalone Git repository per application. In practice, operating a fleet of 9+ Tier 2 workloads (including both Class A source-backed services and Class B off-the-shelf image-only tools) revealed structural friction: + +1. **Per-App Repository Sprawl**: Every third-party tool (`jellyfin`, `snappymail`, `excalidraw`, `mermaid`) required its own Gitea repository, webhook configuration, and clone lifecycle just to version 2–3 declarative files. +2. **Naming Coupling (`~/Sites`)**: The directory name `~/Sites` implied web-only sites rather than general self-hosted workloads (mail, media, diagrams, internal tools). +3. **Cross-Workload Drift & Webhook Overhead**: Coordinating shared network, label, or manifest conventions across N separate deployment repositories required N separate commits and N separate Gitea webhook registrations. +4. **State Co-location Risk**: Moving to a unified monorepo increases the blast radius if any workload stores mutable runtime state inside its deployment directory instead of the isolated host state root (`~/var/lib/homelab//`). + +The central architectural question is: **How should Canopy NixOS Core organize Tier 2 deployment descriptors to eliminate per-app repository sprawl while preserving independent per-workload deployment, backward-compatible migration, and strict runtime state isolation?** + +## Decision Drivers + +* **Eliminate Tier 2 Repository Sprawl**: Consolidate Tier 2 deployment descriptors (`/app.yaml`, `/docker-compose.yml`) into a single unified `canopy-workloads` monorepo at `~/Workloads`. +* **Preserve Per-Workload Independence**: Pushing to `canopy-workloads` must selectively deploy only the workload subdirectories modified in that push, without restarting unaffected services. +* **Zero-Downtime Migration Compatibility**: Support `WORKLOADS_DIR` as the canonical configuration variable with a clean `SITES_DIR` fallback, and support hybrid per-app `.git` checkouts alongside monorepo subdirectories during transition. +* **Strict State Isolation**: Enforce `~/var/lib/homelab//` as the sole persistent runtime state root so the `~/Workloads` Git working tree remains 100% declarative and clean. +* **Preserve 3-Tier & Security Boundaries**: Keep Tier 1 application source repositories independent, keep Core platform services in `~/Core`, and maintain `deployments.yaml` allowlisting and Compose AST security validation. + +## Considered Options + +* **Option 1: Keep Per-App Tier 2 Repositories in `~/Sites/` (Status Quo)**: Maintain one Git repository per workload under `~/Sites`. +* **Option 2: Merge Tier 2 Workloads into `~/Core`**: Place all workload `app.yaml` and `docker-compose.yml` files directly inside `canopy-homelab/nixos-core`. +* **Option 3: Unified `~/Workloads` Monorepo (`canopy-workloads`) with Isolated Host State (Adopted)**: Amend ADR-0001 to rename Tier 2 from `~/Sites` to `~/Workloads`, consolidate Tier 2 manifests into `canopy-workloads`, and enforce `~/var/lib/homelab//` state isolation. + +## Decision Outcome + +Chosen option: **Option 3: Unified `~/Workloads` Monorepo (`canopy-workloads`) with Isolated Host State**, because it eliminates Tier 2 repository and webhook sprawl while preserving the 3-tier boundary between Tier 1 application source, Tier 2 deployment intent, and Tier 3 NixOS Core platform infrastructure. + +### Summary of Architectural Commitments + +This ADR formally amends [ADR-0001](0001-3tier-architecture-and-provenance.md) with the following commitments: + +1. **Tier 2 Rename (`~/Sites` $\rightarrow$ `~/Workloads`)**: + * The canonical Tier 2 deployment root is `~/Workloads` (configured via `homelab.workloadsDir` / `homelab.sitesDir` in NixOS and `WORKLOADS_DIR` in Core services). + * Core Python modules (`appctl_engine.py`, `appctl_daemon.py`, `appctl_router.py`, `gitops_dispatcher.py`) default to `~/Workloads`, honoring `WORKLOADS_DIR` first and falling back to `SITES_DIR` for backward compatibility. +2. **Unified `canopy-workloads` Monorepo**: + * Tier 2 workloads reside as subdirectories `~/Workloads//` inside the `canopy-workloads` monorepo, each owning its own `app.yaml` and `docker-compose.yml`. + * During migration, `~/Workloads/` may operate either as a monorepo subdirectory (sharing `~/Workloads/.git`) or as a standalone checkout (`~/Workloads//.git`). +3. **Mandatory State Isolation (`~/var/lib/homelab//`)**: + * All mutable application data (databases, caches, uploads, dynamic configs) must reside under `~/var/lib/homelab//` (or named Docker volumes) and never inside `~/Workloads//`. + * NixOS `systemd.tmpfiles.rules` provisions `~/Workloads` and `~/var/lib/homelab` with recursive `A+` POSIX ACLs for `homelab-appctl`. +4. **Core Registry & Safe Directory Containment**: + * `config/deployments.yaml` maps admitted workload identities to canonical `~/Workloads/` paths, enforced by strict containment inside `WORKLOADS_DIR`. + * Host Git `safe.directory` configuration includes `~/Workloads` and `~/Workloads/*` (alongside `~/Core`). + +## Pros and Cons of the Options + +### Option 1: Keep Per-App Tier 2 Repositories in `~/Sites/` +* Good, because each workload has an isolated Git history and independent webhook. +* Bad, because adding or updating a simple third-party service requires creating and maintaining a full Git repository. +* Bad, because fleet-wide manifest or Compose conventions require N separate PRs and commits. + +### Option 2: Merge Tier 2 Workloads into `~/Core` +* Good, because only one repository exists for Core and Workloads. +* Bad, because it violates the 3-tier boundary (ADR-0001), mixing NixOS host/platform configuration with application deployment topologies. +* Bad, because `~/Core` changes would trigger NixOS evaluation/rebuild concerns alongside routine app updates. + +### Option 3: Unified `~/Workloads` Monorepo (`canopy-workloads`) with Isolated Host State (Adopted) +* Good, because Tier 2 deployment descriptors are managed in one repository with atomic cross-workload changes and a single GitOps webhook. +* Good, because Tier 1 software repositories and Tier 3 NixOS Core remain strictly decoupled. +* Good, because `WORKLOADS_DIR` $\rightarrow$ `SITES_DIR` fallback allows incremental host cutover without breaking existing environments. +* Bad, because GitOps webhook dispatch and provenance inspection must distinguish monorepo-root `.git` from per-app `.git` checkouts (addressed in follow-up slices). +* Bad, because monorepo commits touching multiple subdirectories require changed-path filtering to avoid redeploying unaffected workloads. + +## Consequences + +### Positive Consequences +* **Single Tier 2 Control Surface**: One `canopy-workloads` repository versions all workload manifests and Compose topologies. +* **Clean Git Working Tree**: Enforcing `~/var/lib/homelab//` ensures runtime state never dirties the monorepo checkout. +* **Smooth Cutover**: Dual `WORKLOADS_DIR` / `SITES_DIR` environment support and `homelab.sitesDir` NixOS option compatibility prevent abrupt breakage. + +### Negative Consequences & Accepted Trade-offs +* **Hybrid Provenance & Subpath Dispatch Complexity**: Core tooling (`provenance.py`, `gitops_dispatcher.py`) must handle both monorepo-level `.git` and legacy per-app `.git` directories, as well as selective changed-directory deployment on monorepo pushes. + +## More Information + +* **Amended Decision**: [`0001-3tier-architecture-and-provenance.md`](0001-3tier-architecture-and-provenance.md) +* **Architecture Specification**: [`docs/architecture.md`](../architecture.md) +* **Secrets & State Contract**: [`docs/secrets-and-state.md`](../secrets-and-state.md) diff --git a/docs/decisions/README.md b/docs/decisions/README.md index 1bb0446..4bc6ed3 100644 --- a/docs/decisions/README.md +++ b/docs/decisions/README.md @@ -10,6 +10,7 @@ Repository-level architectural decisions are recorded in `docs/decisions/` using | Decision Record | Status | Date | Scope & One-Line Purpose | | :--- | :--- | :--- | :--- | +| [**ADR-0004: Unified ~/Workloads Monorepo & State Isolation**](0004-unified-workloads-monorepo.md) | `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//` state isolation. | | [**ADR-0003: Centralized Runtime Validation & Serialization via Pydantic v2**](0003-pydantic-v2-runtime-validation.md) | `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**](0002-appctl-control-plane-architecture.md) | `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**](0001-3tier-architecture-and-provenance.md) | `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//`), and two operational inspection axes. | @@ -18,6 +19,15 @@ Repository-level architectural decisions are recorded in `docs/decisions/` using ## 🧭 Summaries of Governing Decisions +### [ADR-0004: Unified ~/Workloads Monorepo & State Isolation](0004-unified-workloads-monorepo.md) +* **Canonical Document**: [`0004-unified-workloads-monorepo.md`](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//`, supporting hybrid per-app `.git` checkouts during migration. + 3. **Mandatory State Isolation**: All mutable application data resides strictly under `~/var/lib/homelab//` (or named Docker volumes), never inside `~/Workloads`. + 4. **Core Registry & Safe Directory Containment**: `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](0003-pydantic-v2-runtime-validation.md) * **Canonical Document**: [`0003-pydantic-v2-runtime-validation.md`](0003-pydantic-v2-runtime-validation.md) * **Status**: `accepted` (Active)