docs(inbox): curate session drafts into canonical plans and records
Brain Structural Validation / Validate Markdown Structure & Links (push) Successful in 10s

- File completed nixos-appliace-migration plan in
  projects/homelab/plans/
- Add active architecture-consolidation-roadmap in
  projects/homelab/plans
- Record migration inventory discussion and cutover journal in records/
This commit is contained in:
kiskaadee committed 2026-09-11 20:39:48 -05:00
1 parent 719eda7d49
commit 310c2435c2
4 files changed
+428

No files matched your search

@@ -0,0 +1,121 @@
---
type: plan
status: active
project: homelab
tags: [homelab, architecture, gitops, security, roadmap]
---
# Architectural Discussion & Phased Implementation Plan: Homelab Core Appliance
## Executive Summary
The homelab infrastructure has evolved across several distinct design eras:
1. **Era 1 (Edge Ingress)**: Docker Compose with Traefik and Authelia.
2. **Era 2 (Multi-app Workloads)**: Decentralized apps in `~/Sites` coordinated by `appctl`.
3. **Era 3 (Dynamic GitOps)**: Webhook-driven auto-deployments via `gitops_dispatcher.py`.
4. **Era 4 (NixOS Appliance)**: Turnkey host system management encapsulated directly within `homelab-core`.
The system functions reliably, but carries architectural residue, blurred boundaries, and implicit trust assumptions. This plan formalizes the four-layer architecture, remedies the high-risk GitOps trust boundary, validates manifests through schemas, and establishes machine-enforced invariants.
---
## Part 1: Architectural Discussion & Synthesis
### 1. The Four-Tier Topology Model
The legacy documentation depicts a 2-tier system (`Control Plane -> Data Plane`). In practice, the system operates across four discrete layers:
```
┌───────────────────────────┐
│ INTERNET │
└─────────────┬─────────────┘
│
┌────────▼────────┐
│ Traefik │ Layer 1:
│ Edge / Ingress │ Edge Gateway
└────────┬────────┘
│
┌─────────────────────┴─────────────────────┐
│ │
┌────────▼────────┐ ┌────────▼─────────┐
│ Core Plane │ │ Workload Plane │
│ │ │ │
Layer 2: │ Authelia │ Layer 3: │ ~/Sites/* │
Control │ socket-proxy │ Workload │ app.yaml │
Services │ Portainer │ Apps │ Compose stacks │
│ Dozzle │ │ │
│ Watchtower/Diun │ └──────────────────┘
└────────┬────────┘
│
┌────────▼──────────────────────────────────┐
│ Host Control Plane │ Layer 4:
│ NixOS, systemd, SOPS, DDNS, appctl/GitOps │ Host Foundation
└───────────────────────────────────────────┘
```
#### Layer Responsibilities & Strict Boundaries
| Layer | Owns | Must NOT Own |
| :--- | :--- | :--- |
| **Host Foundation (NixOS)** | OS, kernel, systemd services, firewall, secret decryption, host CLI tools | Workload-specific container logic or direct compose files |
| **Control Services (Core Compose)** | Edge proxy, identity gateway, socket isolation, telemetry | Workload deployment policy or app-specific environment variables |
| **Workload Plane (`~/Sites/*`)** | Application code, compose manifest, self-describing `app.yaml` | Host configuration, direct Docker socket, root/sudo execution |
| **Orchestration (`appctl` & GitOps)** | Deployment sequencing, health checks, dashboard metadata sync | Arbitrary shell script execution |
---
### 2. Resolution of Key Architectural Issues
#### A. GitOps Dispatcher Security & Trust Boundary (Critical)
* **Problem**: `gitops_dispatcher.py` currently executes arbitrary commands when `action["custom"]` is defined in `app.yaml`. Running as user `kiskaadee` (member of `wheel` and `docker`) means write access to any repository under `~/Sites` grants arbitrary host-level execution and container compromise.
* **Resolution**:
1. **Abolish `custom` commands completely**. Deployment actions must be a closed, hardcoded enum: `git_pull`, `compose_config`, `compose_pull`, `compose_up`, `healthcheck`.
2. **Webhook Authentication**: Require Gitea HMAC-SHA256 signature verification (`X-Gitea-Signature`) using a secret token stored via SOPS.
3. **Strict Target Containment**: Validate that target paths are strictly canonicalized under `/home/kiskaadee/Sites/<allowed-repo>` with no path traversal (`..`) permitted.
#### B. Manifest Ownership & Schema Contract
* **Problem**: `app.yaml` is parsed with a lightweight, forgiving manual parser. Certain fields like `auth: false` or `networks: [proxy-net]` appear declarative, yet actual enforcement lives inside Docker Compose labels.
* **Resolution**:
* Adopt an explicit schema (e.g. JSONSchema or Pydantic/dataclass validator) defining valid keys, types, and constraints.
* Clearly split **metadata** (title, icon, group) from **enforced deployment policy** (branch, allowed actions).
#### C. Secrets & Deployment Projection
* **Problem**: `traefik-deployments.nix` acts as a monolithic repository of application environment variables, and `dynu.nix` holds `pdf_decrypt_password`.
* **Resolution**:
* Formally document `traefik-deployments.nix` as the **Host Secret Projection Layer** (injecting credentials into `/run/secrets/rendered/traefik-deployments.env`).
* Re-home miscellaneous secrets (like PDF password) into `nixos/modules/shell.nix` or a dedicated system utility block rather than the DDNS updater.
#### D. Operational State vs. Declarative Configuration
* **Problem**: `nixos-install --flake ~/Core#server` reconstructs configuration, but does not recover operational state.
* **Resolution**: Explicitly split disaster recovery documentation into **Declarative Recovery** (NixOS, Flake, Compose, manifests) and **State Recovery** (Docker volumes, Authelia SQLite DB, ACME `acme.json`, dynamic IP history).
---
## Part 2: Phased Implementation Plan
### Phase 1: GitOps Hardening & Closed Dispatcher Protocol (P0 — Urgent)
**Goal**: Neutralize the remote execution attack vector on the GitOps webhook receiver.
- [ ] Eliminate `custom` action execution in `gitops_dispatcher.py`.
- [ ] Implement closed allowlisted action dispatcher (`git_pull`, `compose_config`, `compose_pull`, `compose_up`, `healthcheck`).
- [ ] Webhook signature verification (`X-Gitea-Signature`).
- [ ] Deployment serialization lock to prevent race conditions on concurrent webhooks.
### Phase 2: Formalize `app.yaml` Schema & Validator (P1 — Core Foundation)
**Goal**: Turn `app.yaml` from an informal hint into a strict, validated API contract.
- [ ] Define rigorous schema (JSONSchema / Pydantic).
- [ ] Add pre-flight validation in both `appctl` and `gitops_dispatcher.py`.
### Phase 3: Machine-Enforced Invariant & Architecture Tests (P1 — Continuous Verification)
**Goal**: Convert written architectural invariants into automated test suites running locally and in CI.
- [ ] Automated assertions: `socket-proxy` POST=0/DELETE=0, zero direct `/var/run/docker.sock` mounts, valid firewall ports, `app.yaml` linting.
- [ ] Integrate into Gitea Actions CI workflow.
### Phase 4: Documentation Overhaul & Historical Archiving (P2 — Clarity)
**Goal**: Align repository documentation with current reality and banish legacy contradictions.
- [ ] Restructure `docs/` (`architecture/`, `operations/`, `security/`, `disaster-recovery/`, `adr/`, `archive/`).
- [ ] Move active ADRs to root `docs/adr/`.
- [ ] Correct documentation claims: Watchtower scope, firewall port inventory, wildcard TLS transparency scope.
### Phase 5: Deployment Lifecycle & Verification (P3 — Reliability)
**Goal**: Replace best-effort execution with validated, traceable deployment transactions.
- [ ] Pre-flight `docker compose config -q`.
- [ ] Post-deployment health verification.
- [ ] Append-only deployment audit log.
@@ -0,0 +1,207 @@
---
type: plan
status: completed
project: homelab
tags: [homelab, nixos, appliance, migration]
---
# Implementation Plan: Turn `homelab-core` into a Declarative NixOS Appliance
## Goal Description
Transform **`homelab-core`** from a standalone Docker Compose project into a complete, self-contained **NixOS system appliance**.
### The Primary Objective (Disaster Recovery & Turnkey Provisioning)
If the server hardware fails or is wiped tomorrow, any x86_64 machine can be transformed into the identical production homelab node immediately after a minimal NixOS base install by running:
```bash
git clone ssh://git@gitea.roadtotech.me:2223/kiskaadee/homelab-core ~/Core
sudo nixos-rebuild switch --flake ~/Core#server
```
Once `homelab-core` is established and validated, the legacy `hosts/server/` directory in `Config` will be deprecated and removed, completing the architectural separation of concerns between **personal workstation** (`Config`) and **infrastructure appliance** (`homelab-core`).
---
## Architecture of `homelab-core` as a NixOS Appliance
```text
homelab-core/
├── flake.nix # Minimal server flake (inputs: nixpkgs + sops-nix)
├── flake.lock # Pinned server channel dependencies
├── .sops.yaml # SOPS creation rules (server age key + user age key)
│
├── nixos/ # ⚙️ Declarative OS & Infrastructure Modules
│ ├── configuration.nix # Pure headless OS (Docker, SSH, user, power tuning)
│ ├── hardware-configuration.nix # Server storage, EFI, and CPU definitions
│ ├── secrets.yaml # Encrypted server secrets (Authelia, Dynu, tokens)
│ ├── modules/
│ │ ├── homeserver.nix # Systemd lifecycle for Docker Compose & runtime envs
│ │ ├── traefik.nix # Traefik deployment secrets & dynamic config bridges
│ │ ├── dynu.nix # Smart DDNS monitor service & systemd timers
│ │ └── gitops.nix # Declarative webhook dispatcher on port 9000
│ └── scripts/
│ ├── monitor.py # Smart IP rotation monitor daemon
│ └── ddclient.conf # DDNS configuration template
│
├── docker-compose.yml # Core container stack (Traefik, Authelia, Socket-Proxy, etc.)
├── config/ # Static service configs (Traefik dynamic yaml, Authelia config)
├── scripts/ # Operations & automation (appctl, gitops_dispatcher.py)
└── docs/ # Homelab operational guides & runbooks
```
---
## User Review Required
> [!IMPORTANT]
> **Channel Selection for Homelab Server**:
> - **Option A (Recommended)**: Official `nixos-unstable` channel tarball (`https://channels.nixos.org/nixos-unstable/nixexprs.tar.zst`), keeping packages identical to current server deployments.
> - **Option B**: Official `nixos-24.11` (or current stable release), maximizing stability and minimizing kernel/Docker churn for production uptime.
> [!NOTE]
> **No Home Manager on the Server**:
> In `homelab-core`, we eliminate Home Manager entirely. The server relies on native NixOS system configurations:
> - `programs.tmux.enable = true;` (stock `Ctrl+b` prefix, avoiding nested session collisions).
> - `programs.neovim = { enable = true; defaultEditor = true; };` (zero plugin lag, instant startup).
> - `environment.systemPackages = with pkgs; [ git htop iotop iftop ncdu curl jq age sops docker-compose ];`
---
## Step-by-Step Implementation Roadmap
```mermaid
flowchart TD
A[Phase 1: Scaffold in homelab-core] --> B[Phase 2: Migrate & Clean Server Modules]
B --> C[Phase 3: Validate & Test Build via nix build --no-link]
C --> D[Phase 4: Live Server Cutover to ~/Core#server]
D --> E[Phase 5: Deprecate hosts/server in Config repo]
```
### Phase 1: Repository Scaffolding in `homelab-core`
1. Create a dedicated branch in `/home/kiskaadee/Projects/active/homelab/homelab-core`:
`feat/nixos-appliance`
2. Create directory `nixos/` with subdirectories `nixos/modules/` and `nixos/scripts/`.
3. Create `.sops.yaml` in `homelab-core` containing the server's age key (`*server`) and user's key (`*kiskaadee`).
### Phase 2: Module Migration & Cleansing
1. **Transfer Files**:
- Copy `hosts/server/secrets.yaml` → `homelab-core/nixos/secrets.yaml`
- Copy `hosts/server/hardware-configuration.nix` → `homelab-core/nixos/hardware-configuration.nix`
- Copy `hosts/server/dynu.nix`, `monitor.py`, `ddclient.conf` → `homelab-core/nixos/modules/` & `nixos/scripts/`
- Copy `hosts/server/homeserver.nix` and `traefik-deployments.nix` → `homelab-core/nixos/modules/`
2. **Clean Up `configuration.nix`**:
- **Eliminate desktop inheritance**: Remove import of `modules/system/base.nix`.
- **Eliminate `lib.mkForce false` hacks**: Remove overrides disabling PipeWire, printing, Bluetooth, and greetd, since none of them are imported.
- Include pure server essentials:
- Timezone (`America/Bogota`), Locale (`en_US.UTF-8`).
- OpenSSH daemon with authorized keys.
- Docker virtualization (`virtualisation.docker.enable = true`).
- Systemd power tuning (no suspend/sleep).
- Standard CLI packages (`tmux`, `neovim`, `git`, `htop`, `iotop`, `ncdu`, `curl`, `jq`).
3. **Draft Minimal `flake.nix` in `homelab-core`**:
```nix
{
description = "Homelab Core - Turnkey Declarative NixOS Appliance";
inputs = {
nixpkgs.url = "https://channels.nixos.org/nixos-unstable/nixexprs.tar.zst";
sops-nix = {
url = "github:Mic92/sops-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, sops-nix, ... }@inputs: {
nixosConfigurations.server = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
specialArgs = { inherit inputs; };
modules = [
./nixos/configuration.nix
sops-nix.nixosModules.sops
];
};
};
}
```
### Phase 3: Dry-Build Validation
1. Run `nix flake check` inside `homelab-core`.
2. Execute dry system build:
```bash
nix build .#nixosConfigurations.server.config.system.build.toplevel --no-link
```
3. Verify evaluation completes with zero errors and matches the production server environment.
### Phase 4: Live Server Cutover
1. Push branch `feat/nixos-appliance` to Gitea.
2. On the server host (`server`):
```bash
cd ~/Core
git fetch && git checkout feat/nixos-appliance
sudo nixos-rebuild switch --flake .#server
```
3. Validate services:
- `systemctl status homeserver-core.service`
- `systemctl status dynu-monitor.timer`
- `systemctl status homelab-gitops.service`
- Docker containers running via `docker ps`.
4. Merge `feat/nixos-appliance` into `main` in `homelab-core`.
### Phase 5: Deprecate & Purge `hosts/server/` from `Config`
1. On `Config`, create branch `refactor/purge-server-to-homelab-core`.
2. Remove `nixosConfigurations.server` from `Config/flake.nix`.
3. Delete `hosts/server/` directory completely.
4. Remove `server` age key from `Config/.sops.yaml`.
5. Update `Config/README.md` and `Config/architecture.md` to establish `Config` as the dedicated Workstation/Laptop repository.
6. Verify `laptop` dry build and commit.
---
## Disaster Recovery & New Machine Runbook
Document this exact runbook in `homelab-core/docs/disaster-recovery.md`:
```bash
# ==============================================================================
# 🚨 DISASTER RECOVERY RUNBOOK: PROVISIONING A FRESH HOMELAB SERVER
# ==============================================================================
# 1. Boot any machine with standard NixOS Minimal ISO (x86_64)
# 2. Partition and format root (Btrfs or Ext4) + EFI (vfat)
# 3. Mount filesystems and generate initial hardware config:
nixos-generate-config --root /mnt
# 4. Clone homelab-core into target root:
git clone https://github.com/kiskaadee/homelab-core.git /mnt/home/kiskaadee/Core
# (or via local USB backup / Gitea)
# 5. Copy the generated hardware-configuration.nix into the repo:
cp /mnt/etc/nixos/hardware-configuration.nix /mnt/home/kiskaadee/Core/nixos/hardware-configuration.nix
# 6. Restore the server age secret key (from offline password manager/backup):
mkdir -p /mnt/var/lib/sops-nix
# Place key at /mnt/var/lib/sops-nix/key.txt or /mnt/etc/ssh/ssh_host_ed25519_key
# 7. Install system directly from homelab-core:
nixos-install --flake /mnt/home/kiskaadee/Core#server
# 8. Reboot: The entire homelab, Traefik, Docker services, and GitOps wake up automatically!
reboot
```
---
## Verification Plan
### Automated Tests
1. `nix flake check` in `homelab-core`.
2. Dry system build:
`nix build .#nixosConfigurations.server.config.system.build.toplevel --no-link`
3. Verification of systemd services declared:
`nix eval .#nixosConfigurations.server.config.systemd.services --apply builtins.attrNames`
Ensure `homeserver-core`, `dynu-monitor`, and `homelab-gitops` are registered.
### Manual Verification
1. Inspect decrypted `/run/secrets/` on server post-switch.
2. Confirm container reachability across `https://roadtotech.me`, `https://gitea.roadtotech.me`, etc.
@@ -0,0 +1,59 @@
---
type: discussion
project: homelab
date: 2026-09-11
tags: [nixos, homelab, architecture, inventory]
---
# Migration Blueprint: Splitting `nixos-config` and `homelab-core`
## Executive Summary
Transferring the server's NixOS configuration directly into `homelab-core` leaves `nixos-config` as a pure, focused workstation and dotfiles repository, while `homelab-core` becomes a completely self-contained NixOS appliance running both the operating system and containerized homelab services.
---
## 1. What Migrates to `homelab-core` (The Server Repository)
Everything that defines, secures, or automates the homelab server moves to `homelab-core`:
| Component | Files to Migrate | Purpose in `homelab-core` |
| :--- | :--- | :--- |
| **Flake Entrypoint** | *New dedicated `flake.nix`* | A clean flake with only `nixpkgs` and `sops-nix`. (No Home Manager, no Wayland/desktop inputs). |
| **System & Hardware** | `hosts/server/configuration.nix`<br>`hosts/server/hardware-configuration.nix` | Base OS, EFI bootloader, Docker daemon, user accounts, SSH keys. |
| **Homelab Services** | `hosts/server/homeserver.nix`<br>`hosts/server/traefik-deployments.nix` | Authelia, Docker service lifecycles, Traefik edge proxy secrets. |
| **Smart DDNS** | `hosts/server/dynu.nix`<br>`hosts/server/monitor.py`<br>`hosts/server/ddclient.conf` | Dedicated Dynamic DNS monitor daemon and timers. |
| **Secrets & Keys** | `hosts/server/secrets.yaml`<br>*.sops.yaml (server-scoped)* | Authelia hashes, Dynu passwords, and GitOps tokens encrypted with server's age key. |
### Major Benefit on the Server Side:
- **No Home Manager overhead**: The server can drop Home Manager entirely. Pure NixOS options like `programs.tmux.enable = true;` and `programs.neovim.enable = true;` provide instant, reliable editor and terminal multiplexing.
- **No more `lib.mkForce false`**: The server no longer imports `modules/system/base.nix` (which had printing, bluetooth, and audio), eliminating the need to force-disable them.
---
## 2. What Remains in `nixos-config` (The Workstation Repository)
This repository becomes 100% focused on being the personal workstation environment:
| Component | Files Remaining | Purpose in `nixos-config` |
| :--- | :--- | :--- |
| **Flake Entrypoint** | `flake.nix` (with `laptop` only) | Flake inputs for desktop UI: `nixpkgs`, `home-manager`, `dms`, `dank-greeter`, `zen-browser`, `antigravity`. |
| **Workstation Host** | `hosts/laptop/*` | Niri window manager, laptop hardware settings, display configs. |
| **Workstation System Modules** | `modules/system/base.nix`<br>`modules/system/graphical.nix` | Bluetooth, PipeWire audio, Epson printing & scanning, greetd, desktop session variables. |
| **Rich User Environment** | `home.nix`<br>`modules/user/*` | Full Lua Neovim (treesitter, LSP), styled Tmux, Starship prompt, Alacritty, desktop Wayland tools. |
| **Developer Toolchains** | `modules/user/apps.nix` | Rust, Go, Python/uv, Zen Browser, Antigravity, Tea, GitHub CLI. |
| **Workstation Scripts** | `modules/user/shell/*`<br>`modules/user/scripts/*` | Interactive scripts: `git.sh`, `todo.sh`, `jump.sh`, `record.sh`, `bundle_project.py`. |
| **Workstation Secrets** | `hosts/laptop/secrets.yaml` | Workstation-specific secrets only. |
---
## 3. What Gets Purged / Cleaned Up
1. **Purged from `nixos-config`**:
- `hosts/server/` directory (all 9 files).
- `server` age key from `.sops.yaml`.
- `nixosConfigurations.server` block from `flake.nix`.
2. **Simplified on the Server (`homelab-core`)**:
- Flake evaluation time drops from ~3 seconds to under 0.5 seconds.
- Server flake lockfile has only 2 inputs instead of 10.
- Zero risk of desktop package breakages blocking server builds.
@@ -0,0 +1,41 @@
---
type: journal
project: homelab
date: 2026-09-11
tags: [homelab, nixos, migration, cutover]
---
# homelab-core NixOS Appliance Merged & Documentation Audit Complete
## Overview
The transformation of `homelab-core` into a turnkey, standalone declarative NixOS appliance is fully complete, validated, merged into `main`, and deployed. All documentation drift across both `homelab-core` and `Config` repositories has been resolved.
## Summary of Completed Actions
### 1. `homelab-core` Repository
- **Merged `feat/nixos-appliance` into `main`** (Fast-forward, pushed to `origin/main`).
- **NixOS Appliance Layer**:
- `flake.nix`: 2-input flake (`nixpkgs` channel tarball + `sops-nix`).
- `flake.lock`: Pinned to `nixos-26.11pre1070770.8ce4ef6`.
- `.sops.yaml`: Scoped to `nixos/secrets.yaml` with server and laptop age keys.
- `nixos/configuration.nix`: Clean, headless NixOS profile without Home Manager or desktop inheritance.
- `nixos/modules/homeserver.nix`: Systemd services (`homeserver-core`, `homelab-gitops`), Authelia declarative user config, and secret templates.
- `nixos/modules/traefik-deployments.nix`: Traefik deployment environment templates (`traefik-deployments.env`).
- `nixos/modules/dynu.nix`: Smart dynamic IP monitor timer and ddclient credentials.
- `nixos/modules/shell.nix`: Tailored declarative bash environment via `/etc/bashrc` with `zoxide`, `starship`, `direnv`, `fastfetch`, `fzf`, `bat`, `qpdf`, and server aliases.
- **Documentation Overhaul**:
- `README.md`: Updated secrets architecture to `nixos/secrets.yaml` and `/run/secrets/rendered/`. Added comprehensive `Declarative NixOS Appliance` section detailing directory layout, rebuild commands, and disaster recovery.
- `docs/setup_guide.md`: Updated paths from `~/Config/hosts/desktop/` to `nixos/`, updated `sops nixos/secrets.yaml` workflow, and documented module roles.
- `SECURITY.md`: Removed legacy Arch Linux / `pacman -Syu` references; documented NixOS SSH and declarative immutability guidelines.
- `AGENTS.md`: Updated secrets location invariant to `nixos/secrets.yaml`.
### 2. `Config` Repository
- **Documentation Streamlining**:
- `README.md`: Replaced verbose Dynu flowchart and implementation details with a concise feature highlight linking to `docs/dynu-ip-monitor.md`. Updated `record.sh` description to reflect Niri sessions (removed legacy Hyprland reference).
- `docs/system-maintenance.md`: Fixed remaining `.desktop` build and rebuild commands, replacing them with `.laptop`.
- **Validation**:
- `nix flake check` passed cleanly.
- Both `server` and `laptop` configurations evaluate without errors.
## Next Phase (Phase 5)
Once the server running generation has been verified over an extended period, the legacy `hosts/server/` folder and server configurations can be formally deprecated and purged from the `Config` repository.