Skip to main content

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.
Structure:
Example system configuration:
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
Host-specific configurations (user@hostname) are automatically imported by NixOS systems and should not be deployed standalone with home-manager switch.

Droids Directory

Location: droids/ Purpose: Nix-on-Droid configurations for Android devices.
Each directory in droids/ is automatically exposed as a nixOnDroidConfigurations output.
Example:
droids/soriphoono/default.nix

Modules Directory

Location: modules/ Purpose: Reusable, composable configuration modules organized by scope.
Module exports:
modules/nixos/default.nix

Automatic Discovery Logic

The heart of the architecture is the automatic discovery system defined in lib/default.nix:
lib/default.nix

How Discovery Works

1

Scan Directory

The discover function scans a directory for:
  • Subdirectories containing default.nix
  • Standalone .nix files (excluding default.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 packages
  • flake-parts - Modular flake structure
  • home-manager - User environment management

Secrets

  • agenix - Age-encrypted secrets
  • sops-nix - SOPS secrets management

System

  • disko - Declarative disk partitioning
  • lanzaboote - Secure Boot with TPM
  • nixos-facter-modules - Hardware detection

Deployment

  • comin - GitOps continuous deployment
  • nix-on-droid - Android support
Input declaration:
flake.nix
All inputs follow nixpkgs-weekly to ensure consistent package versions across the entire homelab.

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
Encrypted secrets are stored in the repository and automatically decrypted during system activation using the host’s SSH key.

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