9.0 KiB
type, status, project, tags
| type | status | project | tags | ||||||
|---|---|---|---|---|---|---|---|---|---|
| plan | completed | homelab |
|
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:
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
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-unstablechannel 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;(stockCtrl+bprefix, 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
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
- Create a dedicated branch in
~/Projects/active/homelab/homelab-core:feat/nixos-appliance - Create directory
nixos/with subdirectoriesnixos/modules/andnixos/scripts/. - Create
.sops.yamlinhomelab-corecontaining the server's age key (*server) and user's key (*kiskaadee).
Phase 2: Module Migration & Cleansing
- 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.nixandtraefik-deployments.nix→homelab-core/nixos/modules/
- Copy
- Clean Up
configuration.nix:- Eliminate desktop inheritance: Remove import of
modules/system/base.nix. - Eliminate
lib.mkForce falsehacks: 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).
- Timezone (
- Eliminate desktop inheritance: Remove import of
- Draft Minimal
flake.nixinhomelab-core:{ 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
- Run
nix flake checkinsidehomelab-core. - Execute dry system build:
nix build .#nixosConfigurations.server.config.system.build.toplevel --no-link - Verify evaluation completes with zero errors and matches the production server environment.
Phase 4: Live Server Cutover
- Push branch
feat/nixos-applianceto Gitea. - On the server host (
server):cd ~/Core git fetch && git checkout feat/nixos-appliance sudo nixos-rebuild switch --flake .#server - Validate services:
systemctl status homeserver-core.servicesystemctl status dynu-monitor.timersystemctl status homelab-gitops.service- Docker containers running via
docker ps.
- Merge
feat/nixos-applianceintomaininhomelab-core.
Phase 5: Deprecate & Purge hosts/server/ from Config
- On
Config, create branchrefactor/purge-server-to-homelab-core. - Remove
nixosConfigurations.serverfromConfig/flake.nix. - Delete
hosts/server/directory completely. - Remove
serverage key fromConfig/.sops.yaml. - Update
Config/README.mdandConfig/architecture.mdto establishConfigas the dedicated Workstation/Laptop repository. - Verify
laptopdry build and commit.
Disaster Recovery & New Machine Runbook
Document this exact runbook in homelab-core/docs/disaster-recovery.md:
# ==============================================================================
# 🚨 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~/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~/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~/Core#server
# 8. Reboot: The entire homelab, Traefik, Docker services, and GitOps wake up automatically!
reboot
Verification Plan
Automated Tests
nix flake checkinhomelab-core.- Dry system build:
nix build .#nixosConfigurations.server.config.system.build.toplevel --no-link - Verification of systemd services declared:
nix eval .#nixosConfigurations.server.config.systemd.services --apply builtins.attrNamesEnsurehomeserver-core,dynu-monitor, andhomelab-gitopsare registered.
Manual Verification
- Inspect decrypted
/run/secrets/on server post-switch. - Confirm container reachability across
https://roadtotech.me,https://gitea.roadtotech.me, etc.