Overview
The homelab repository uses a carefully designed directory structure that separates concerns, enables automatic discovery, and scales from a single machine to dozens of systems.Root Directory Layout
Directory Details
systems/ - NixOS Hosts
Role: Top-level NixOS configurations for physical and virtual machines.
Each subdirectory represents a single host. Any directory containing a default.nix is automatically discovered and exposed as a nixosConfiguration.
Structure:
meta.json:
The
system field in meta.json determines the target architecture. If omitted, defaults to x86_64-linux.homes/ - Home Manager Users
Role: User environment configurations. Supports both standalone installations and system-bound configurations.
The discovery logic recognizes three naming patterns:
username- Base configuration used everywhereusername@global- Supplementary config for non-NixOS/standalone installsusername@hostname- Machine-specific overrides
| Pattern | Exported As | Used By |
|---|---|---|
alice | Base for all alice configs | All systems |
alice@global | homeConfigurations.alice | Standalone installs |
alice@workstation | - | NixOS system workstation only |
Machine-specific homes (
user@hostname) are imported by the NixOS system itself and are not exported as standalone home configurations.flake.nix:
droids/ - Android Devices
Role: Nix-on-Droid configurations for Android devices with Termux.
Every directory in droids/ is automatically exposed as a nixOnDroidConfiguration.
Structure:
modules/ - Reusable Modules
Role: Encapsulated functionality that can be imported by multiple configurations.
Organized by target environment:
environments/ - Non-NixOS Systems
Role: Planned support for managing non-NixOS Linux systems using System Manager.
This directory is reserved for future use and not yet implemented.
pkgs/ - Custom Packages
Role: Custom package definitions and package overrides.
Structure:
lib/ - Utility Functions
Role: Custom helper functions used throughout the flake.
Contents:
lib/ directory extends nixpkgs.lib with custom functions:
discover- Automatic configuration discoverydiscoverTests- Test file discoveryreadMeta- Metadata reader for configurations
templates/ - Scaffolding
Role: Boilerplate templates for creating new systems, modules, or configurations.
Usage:
Discovery Patterns
Systems Discovery
Fromflake.nix line 348:
discover function finds all directories in systems/ containing default.nix.
Droids Discovery
Fromflake.nix line 351:
Homes Discovery
Fromflake.nix lines 355-374:
Metadata System
Configurations can include ameta.json file to provide additional information:
Common fields:
The metadata is read by
lib.readMeta and can influence build parameters like target architecture.File Organization Best Practices
Keep Configurations Modular
Split large configuration files into logical components:Use Meta Files
Always includemeta.json for non-standard architectures:
Document Machine-Specific Overrides
When creatinguser@hostname homes, document why the override is needed:
Summary
The directory structure provides:- Clear separation between systems, users, and reusable code
- Automatic discovery eliminating manual import maintenance
- Scalability from one machine to dozens
- Flexibility with multiple deployment patterns
- Metadata support for architecture and classification