This repository organizes my NixOS configurations using the following structure.
└── root/
├── flake/ # Flake output definitions
├── roles/ # System compositions
├── packages/ # Custom package definitions
└── modules/ # Configuration components
├── infrastructure/ # Infrastructure definitions
├── services/ # Custom service implementations
├── database/ # Database configurations
├── media/ # Media service configurations
├── networking/ # Network configurations
└── [other domains]/ # Other domain-specific modules
flake/
Contains the implementation of flake outputs, split into multiple files for better organization. This uses flake-parts
to modularize the flake.nix functionality, making it easier to maintain. These files define packages, NixOS modules,
and other outputs used within this project.
roles/
Contains composite system configurations that define specific functionality by integrating multiple modules. Roles serve
as the integration layer that connects various services and resources together.
Roles are responsible for enabling the services required for a specific function, managing resource dependencies like
storage mounts and hardware requirements or listing used SOPS secrets.
The idea of a role is to provide an overview of what functionality is provided and used without requiring deep dives into service implementations.
A machine can have multiple roles, but a role is not tied to a specific machine. Roles define state and functionality rather than machines themselves.
packages/
Contains definitions for custom packages that aren't available in nixpkgs or require modifications.
modules/[domain]/
Contains configurations organized by functional domains. Each domain directory groups related functionality based on
purpose rather than technical classification:
database/
: Database service configurationsmedia/
: Media-related servicesnetworking/
: Network configurationsshell/
: Shell tools and configurationsstorage/
: Storage solutionshardware/
: Hardware-specific configurations
Modules define service capabilities, options, and detailed implementations. They handle their own internal configuration, including service-specific secret management and firewall rules (with toggle options), but don't enable themselves by default.
modules/services/
Contains custom service implementations that aren't provided by nixpkgs.
modules/infrastructure/
Contains definitions of my environment's structure, primarily focusing on nodes and their associated roles. This defines
which machines exist in my environment, what roles they have, and whether they should be proxied. The infrastructure
module serves as the registry of machines that forms the foundation of my homelab.
- Domain-based organization: Group related functionality by purpose
- Separation of implementation and activation::
- Modules implement services and their configuration options
- Roles composite modules and set specific configuration values
- Service encapsulation: Services handle their own implementation details, including detailed configuration, how to integrate secrets, and firewall rules (with toggle options)
- Role integration: Roles enable required services, manage storage mounts and hardware requirements, connect services to required resources, and should provide an overview of functionality.
- Flat hierarchies: Keep directory structures flat. Create subdirectories only when there are several related files (3+) or when the organization significantly improves clarity. For domains with just 1-2 files, prefer keeping them as direct files in the domain directory rather than creating additional subdirectories.
This structure creates a clean separation between implementation (modules) and activation (roles).
The flake offers packages that generate Proxmox VM templates using nixos-generators.
The resulting vma
files can be directly imported into Proxmox and used, eliminating the need to manually configure a VM and install NixOS.
Please note the EFI secure boot complications that need to be handled when not using the deploy-image script.
The templates use an enhanced format based on the Nixpkgs Proxmox image. This enhanced template enables the creation of SCSI disks and other smaller improvements.
Optimized VM template for x86_64 systems that aligns with the hardware of my main Proxmox host.
- Machine: q35 (PCIe-based architecture)
- Storage: SCSI with optimizations (discard, I/O thread, SSD) for optimal M.2 storage usage
- Cloud-init enabled
- UEFI boot
- Extended kernel modules like ...
- Storage: virtio_scsi, scsi_mod, sd_mod
- Memory: virtio_balloon (dynamic memory allocation)
- Random: virtio_rng (entropy from host)
- USB: Full stack (1.1 through 3.0) support
Default VM template for x86_64 systems, provides highest compatibility. I started with the template, so a few of my VMs are still running on it.
- Machine: i440fx
- Storage: VirtIO-based
- Cloud-init enabled
Specialized template for Nix remote builders.
- Based on proxmox-x86-optimized
- Includes builder-specific configurations
- Includes remote builder role configuration
- Supports building ARM packages, but it is very slow. Helpful for getting started with ARM systems until a host-specific ARM builder can be booted.
Template used for virtual machines running on my Raspberry Pi using Proxmox-Port.
- Based on standard nixpkgs image
- Configured according to Proxmox ARM port specifications
- Suitable for ARM-based Proxmox installations
Templates can be built using the standard Nix commands:
nix build .#proxmox-x86-optimized
deploy-image automates the VM creation process inside proxmox:
- Uploads template to Proxmox host
- Creates/Restores the created VMA file with specified ID
- Recreates the EFI disk to prevent secure boot issues.
The build VM can be used immediately after deployment.
1-99
: Reserved for cluster/system use100-999
: Production VMs1000-1999
: Templates2000-2999
: Development/Test VMs9000-9999
: Temporary/Clone VMs
100-109
: DNS/DHCP110-119
: Authentication/Directory (LDAP, AD)120-129
: Monitoring/Logging130-139
: Build/CI Services140-149
: Backup Services150-159
: Storage Services160-169
: Network Services170-179
: Security Services180-189
: Management Tools190-199
: Other Infrastructure
200-219
: Web Services220-239
: Database Servers240-259
: Mail Services260-279
: Media Services280-299
: Home Automation300-319
: Documentation/Wiki320-339
: Communication Services340-359
: File Sharing360-379
: Development Tools380-399
: Other Applications
400-419
: Kubernetes Nodes420-439
: Docker Hosts440-459
: Container Management460-479
: Container Registry480-499
: Other Container Services
500-519
: Primary Storage520-539
: Backup Storage540-559
: Archive Storage560-579
: Object Storage580-599
: Other Storage
600-619
: Firewalls/Routers620-639
: VPN Services640-659
: Load Balancers660-679
: Proxy Services680-699
: Other Network Services
700-749
: Analytics/Metrics750-799
: AI/ML Services800-849
: IoT Services850-899
: Custom Solutions
900-999
: Future Use/Expansion
1000-1099
: Linux Distribution Templates1100-1199
: Windows Templates1200-1299
: Application Templates1300-1399
: Container Templates1400-1499
: Custom Templates1500-1999
: Reserved for Future Templates
2000-2199
: Development Environment2200-2399
: Testing Environment2400-2599
: Staging Environment2600-2799
: QA Environment2800-2999
: Experimental VMs
9000-9499
: Clones9500-9699
: Testing9700-9899
: Temporary Workloads9900-9999
: Emergency/Recovery
- Leave gaps between used IDs for future expansion
- Critical infrastructure VMs (like storage, backup) should maintain existing IDs if already established
- Document any deviations from this scheme
- Consider using tags in addition to ID ranges for better organization
{purpose}-{nn}
Example: dns-01
, k8s-01
, db-01
dns
: DNS Serversdhcp
: DHCP Servicesfw
: Firewallsproxy
: Reverse Proxiesmon
: Monitoring Servicesbackup
: Backup Servicesnfs
: File Serversgit
: Git Serversldap
: Directory Servicesvpn
: VPN Servicesbuild
: Build Servers/CI
web
: Web Serversapp
: Application Serversdb
: Database Serverscache
: Caching Servicesmail
: Mail Serversci
: CI/CD Servicesdocker
: Docker Hostsk8s
: Kubernetes Nodesmqtt
: Message Brokers
nas
: Network Attached Storagesan
: Storage Area Networkstore
: General Storagearchive
: Archive Storage
plex
: Media Serversha
: Home Assistantcam
: Camera/Surveillancemedia
: Media Servicespi
: Pi-hole/DNS Filtering
- Two-digit number starting with 01
- Example: web:01, web:02
- Use lowercase only
- No special characters except colon (:)
- Keep names short but meaningful
- Be consistent with abbreviations
- Document any exceptions
- Use sequential numbering
# Infrastructure
dns-01 # Primary DNS
proxy-01 # Main reverse proxy
build-01 # Build server
# Applications
web-01 # Primary web server
db-01 # Main database
app-01 # Application server
# Storage
nas-01 # Primary NAS
store-01 # General storage
# Media/Home
plex-01 # Media server
ha-01 # Home Assistant
- Names should be easily identifiable
- Purpose should be clear from the name
- Numbers allow for multiple instances
- Avoid environment prefixes unless needed (dev/prod)
- Consider DNS implications when naming
- Keep consistent across documentation and configurations