Personal Nix configuration repository for provisioning and maintaining Nix-powered machines across multiple platforms including NixOS, macOS (Darwin), and Windows Subsystem for Linux (WSL).
This repository manages my entire computing ecosystem using Nix flakes, providing declarative and reproducible configurations for:
- Personal devices: Desktops, laptops, and development machines
- Work machines: Both personal and company-provided equipment
- Servers: Git server, DNS server, bastion host, and development environments
- Specialized environments: Custom installer ISO and deployment configurations
- Modular Architecture: Configurations are built from reusable modules that encapsulate specific functionality
- Platform Agnostic: Support for NixOS, Darwin, and Home Manager with shared abstractions where possible
- Declarative Management: All system state is declared in code, including secrets via sops-nix
- Reproducible Builds: Every configuration can be reproduced from scratch with consistent results
- Minimal Maintenance: Automated garbage collection and optimized storage settings
- BTRFS with zstd compression enabled by default
- Centralized secret management using nix-sops
- Automated deployments with deploy-rs
- Custom NixOS installer ISO with pre-configured tools
- Comprehensive module system for easy customization
┌─────────────────────────────────────────────────────────────┐
│ Nix Config │
├─────────────────────────────────────────────────────────────┤
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────┐ │
│ │ Hosts │ │ Modules │ │ Profiles │ │
│ │ │ │ │ │ │ │
│ │ ┌─────────┐ │ │ ┌─────────┐ │ │ ┌─────────────────┐ │ │
│ │ │ NixOS │ │ │ │ NixOS │ │ │ │ NixOS │ │ │
│ │ │ Darwin │ │ │ │ Darwin │ │ │ │ Darwin │ │ │
│ │ │ HomeMgr │ │ │ │ HomeMgr │ │ │ │ HomeManager │ │ │
│ │ └─────────┘ │ │ └─────────┘ │ │ └─────────────────┘ │ │
│ └─────────────┘ └─────────────┘ └─────────────────────┘ │
│ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────┐ │
│ │ Systems │ │ Users │ │ Tools │ │
│ └─────────────┘ └─────────────┘ └─────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
├── hosts/ # Host-specific configurations
│ ├── darwin/ # macOS configurations
│ ├── homeManager/ # Home Manager only configurations
│ └── nixos/ # NixOS configurations
├── modules/ # Reusable modules organized by platform
│ ├── darwin/ # macOS modules
│ ├── homeManager/ # Home Manager modules
│ └── nixos/ # NixOS modules
├── profiles/ # Combinations of modules for specific use cases
│ ├── darwin/ # macOS profiles
│ ├── homeManager/ # Home Manager profiles
│ └── nixos/ # NixOS profiles
├── systems/ # Hardware-specific configurations
├── users/ # User-specific configurations
├── tools/ # Installation and setup tools
└── secrets/ # Encrypted secrets (managed with sops-nix)
The configuration follows a hierarchical module system:
- Modules: Reusable components that encapsulate specific functionality (e.g.,
dev-tools,gaming) - Profiles: Combinations of modules for specific use cases (e.g.,
devops,alltheway-desktop) - Hosts: Machine-specific configurations that import relevant profiles
- Systems: Hardware-specific configurations
# Check the configuration for syntax and logical errors
nix flake check
# Build a specific host configuration (without applying changes)
# For NixOS hosts:
nixos-rebuild build --flake ".#<hostname>"
# For Home Manager hosts:
home-manager build --flake ".#<hostname>"
# For Darwin hosts:
darwin-rebuild build --flake ".#<hostname>"
# Apply NixOS configuration (for NixOS hosts)
sudo nixos-rebuild switch --flake ".#<hostname>"
# Apply Home Manager configuration (for Home Manager hosts)
home-manager switch --flake ".#<hostname>"
# Apply Darwin configuration (for macOS hosts)
darwin-rebuild switch --flake ".#<hostname>"
# Deploy to remote servers (requires deploy-rs setup)
deploy
# Show available configurations
nix flake show- Always run
nix flake checkbefore committing changes - Test specific configurations before deployment:
# For NixOS hosts:
nixos-rebuild build --flake ".#<hostname>"
# For Home Manager hosts:
home-manager build --flake ".#<hostname>"
# For Darwin hosts:
darwin-rebuild build --flake ".#<hostname>"- Apply configurations only after successful testing:
# For NixOS hosts:
sudo nixos-rebuild switch --flake ".#<hostname>"
# For Home Manager hosts:
home-manager switch --flake ".#<hostname>"
# For Darwin hosts:
darwin-rebuild switch --flake ".#<hostname>"- Avoid building in production during development sessions
| Host | Type | Purpose | Platform |
|---|---|---|---|
| desktopdx | Bare-metal | Main PC desktop, gaming and development | AMD |
| workpcdx | Bare-metal | Work PC desktop | Intel |
| gitdx | Proxmox LXC | Git server running Forgejo | Container |
| guardiandx | Proxmox LXC | AdGuard Home DNS server | Container |
| bastiondx | Proxmox LXC | Bastion host, Tailscale exit node and DNS AdBlocker | Container |
| winpcdx | WSL | WSL environment in Windows PC | WSL |
| sysspcdx | WSL Tarball | WSL Tarball building for SYSS PCs | WSL |
| installer-iso | NixOS | Custom installer ISO | ISO |
| Host | Type | Purpose |
|---|---|---|
| macbookdx | MacBook Air | Development and casual entertainment |
| Host | Platform | Purpose |
|---|---|---|
| CLEA-DELL-001 | Linux | Work PC for CLEA |
| CLEA-MAC-001 | macOS | Work Mac for CLEA |
| devdx | Linux | Development environment |
| makcpu1 | Linux | GPU dev machine @ HKUST for Signify app development |
| syoi | Linux | Remote code-server at code.syoi.org |
- Create host directory in appropriate platform folder (
hosts/<platform>/<hostname>/) - Create
default.nixwith host configuration - Import appropriate profiles and system configuration
- Add host to the appropriate list in
flake.nix - Test with
nix flake check - Build and test configuration:
# For NixOS hosts:
nixos-rebuild build --flake ".#<hostname>"
# For Home Manager hosts:
home-manager build --flake ".#<hostname>"
# For Darwin hosts:
darwin-rebuild build --flake ".#<hostname>"- Make changes to appropriate modules or profiles
- Test with
nix flake check - Apply changes to specific host:
- NixOS:
sudo nixos-rebuild switch --flake ".#<hostname>" - Home Manager:
home-manager switch --flake ".#<hostname>" - Darwin:
darwin-rebuild switch --flake ".#<hostname>"
- NixOS:
- Secrets are managed using sops-nix
- Never commit actual secrets to the repository
- Only age public keys should be in
.sops.yaml - To update secrets:
sops <secret-file>
Remote deployments are configured using deploy-rs for:
- gitdx (10.101.151.229)
- guardiandx (10.101.255.22)
To deploy configurations to remote systems:
# Deploy all configured nodes
deploy
# Deploy to a specific node
deploy .#gitdx
# Deploy to a specific profile on a node
deploy .#gitdx.systemEach remote node is configured in flake.nix with:
- Hostname or IP address
- SSH user for connecting
- Target user for deployment (often root)
- Profile paths and activation methods
Deployments require proper SSH access and authentication set up beforehand.
- Build installation ISO:
nix build .#installer-iso - Burn ISO to USB and boot
- Add SSH keys to authorized_keys
- Run Ansible scripts in
toolsdirectory to prepare installation - Add public key of
/mnt/etc/sops-nix/key.txtto.sops.yamland update keys - Run
nixos-generate-config --root /mnt --show-hardware-configand copy result tohosts/nixos/$HOSTNAME/hardware-configuration.nix - Clone repo and
nixos-install --flake ".#<hostname>"
- Download and install NixOS-WSL
- Setup Nix flakes by enabling flags and install git in
/etc/nixos/configuration.nix - Install
ageand generate an age key at/etc/sops-nix/key.txt - Add public key of generated age key to
.sops.yamland update keys - Switch to configuration:
nixos-rebuild switch --flake ".#<hostname>"
Note: Ensure dotfiles/p10k.conf.d/.p10k.zsh is in LF instead of CRLF when checked out by Git for Windows.
- Build tarball:
nix build .#<hostname> - Upload tarball to Proxmox
- Create LXC container with tarball template
- Note IP and change root password if necessary
- Apply configuration:
nixos-rebuild switch --flake ".#<hostname>" - Reboot and reapply configuration if needed
- Follow Nix and Home Manager installation if not yet installed
- Clone repo and
home-manager switch --flake ".#<hostname>"
- Build Failures: Check that all inputs are properly defined in
flake.nix - Secret Decryption: Ensure age keys are properly configured and accessible
- Network Issues: Check firewall settings for deployments
- Disk Configuration: Verify disk-config.nix matches actual disk layout
- Use
nix flake checkto validate configuration syntax - Use platform-specific build commands with --verbose for detailed output:
# For NixOS hosts:
nixos-rebuild build --flake ".#<hostname>" --verbose
# For Home Manager hosts:
home-manager build --flake ".#<hostname>" --verbose
# For Darwin hosts:
darwin-rebuild build --flake ".#<hostname>" --verbose- Check journalctl for service-specific errors
- Use
nix replto debug Nix expressions
Since GRUB is configured as the bootloader, system recovery is straightforward:
Reboot and select "NixOS - All configurations" from the GRUB menu, then choose the previous working generation.
- Use
default.nixfor module and profile definitions - Host-specific configurations go in
hosts/<platform>/<hostname>/default.nix - Hardware configurations go in
hardware-configuration.nixfiles - Disk configurations go in
disk-config.nixfiles - Service-specific configurations are often split into separate files
- Modular Architecture: Chosen for reusability and maintainability across different systems
- Flakes: Adopted for reproducibility and better dependency management
- sops-nix: Selected for secret management to avoid committing sensitive data
- BTRFS with compression: Default filesystem for space efficiency and data integrity
- Consider adding more automated testing
- Explore containerization for development environments
- Investigate better backup strategies
- Evaluate additional security hardening options