Architecture Overview
The homelab uses a modern Flake-based architecture with automatic discovery logic, enabling a truly declarative infrastructure-as-code approach.Flake Structure
The repository is organized around Nix Flakes with intelligent automatic discovery:Core Philosophy
The architecture is built on four key principles:Declarative Everything
All infrastructure is defined in code. No imperative configuration steps.
Single Command Invocation
Deploy with one command. Updates are atomic and rollback-safe.
Dynamic Discovery
Configurations are automatically discovered. No manual imports needed.
Stability
nix flake check validates everything before deployment.Directory Roles
Systems Directory
Location:systems/
Purpose: Top-level NixOS configurations for physical and virtual machines.
Each subdirectory in
systems/ with a default.nix is automatically exposed as a nixosConfigurations output.systems/zephyrus/default.nix
Homes Directory
Location:homes/
Purpose: Home Manager configurations for user environments.
Discovery Pattern:
The flake scans for three naming patterns:
1
Base Configuration
Pattern:
homes/username/Base user configuration used everywhere.homes/soriphoono/default.nix
2
Global Override
Pattern:
homes/username@global/Supplementary config for standalone (non-NixOS) installs. Combined with base and exported as homeConfigurations.username.3
Host-Specific Override
Pattern:
homes/username@hostname/Machine-specific overrides imported by the NixOS system. Not exported as standalone homeConfiguration.homes/soriphoono@zephyrus/default.nix
Droids Directory
Location:droids/
Purpose: Nix-on-Droid configurations for Android devices.
Each directory in
droids/ is automatically exposed as a nixOnDroidConfigurations output.droids/soriphoono/default.nix
Modules Directory
Location:modules/
Purpose: Reusable, composable configuration modules organized by scope.
modules/nixos/default.nix
Automatic Discovery Logic
The heart of the architecture is the automatic discovery system defined inlib/default.nix:
lib/default.nix
How Discovery Works
1
Scan Directory
The
discover function scans a directory for:- Subdirectories containing
default.nix - Standalone
.nixfiles (excludingdefault.nix)
2
Map to Attribute Set
Each discovered path is mapped to an attribute:
3
Build Configuration
The flake uses builder functions to construct configurations:
flake.nix
Flake Inputs
The homelab leverages a curated set of flake inputs:Core
nixpkgs-weekly- Rolling NixOS packagesflake-parts- Modular flake structurehome-manager- User environment management
Secrets
agenix- Age-encrypted secretssops-nix- SOPS secrets management
System
disko- Declarative disk partitioninglanzaboote- Secure Boot with TPMnixos-facter-modules- Hardware detection
Deployment
comin- GitOps continuous deploymentnix-on-droid- Android support
flake.nix
System Builders
The flake defines specialized builder functions for each configuration type:NixOS System Builder
flake.nix
Home Manager Builder
flake.nix
Nix-on-Droid Builder
flake.nix
Validation and Checks
The flake includes comprehensive validation:flake.nix
Run
nix flake check to validate all configurations before deploying.Secrets Management
Secrets are managed using agenix with encryption based on host SSH keys:systems/zephyrus/default.nix
Development Workflow
1
Make Changes
Edit configurations in their respective directories.
2
Validate
Run
nix flake check to validate all configurations.3
Test Locally
Build and test changes:
4
Deploy
Apply changes:
5
Commit
Commit to Git for GitOps deployment (if using Comin).
Next Steps
Quick Start
Deploy your first configuration
Module Reference
Explore available modules and options