Here is my personal nix flake configuration for managing multiple systems with reproducible, declarative configurations.
This repository contains my Nix flake that provides system configurations, modules, and home manager related fun. It uses the power of nix flakes to ensure reproducible builds and easy system management. The is something I truly enjoy working in, and like some of you, find myself crafting my flake more than working on my other projects.....
- Multi-system support: Configurations for different machines and architectures
- Reproducible environments: Locked dependencies ensure consistent builds
- Modular configuration: Reusable modules and shared configurations
- Home Manager integration: User-specific configurations alongside system configs
If you haven't enabled flakes yet, add the following to your Nix configuration:
# Add this in your configuration.nix
nix.settings.experimental-features = [ "nix-command" "flakes" ];# Run after updating your configuration.nix
sudo nixos-rebuild switch# Build a specific system configuration
sudo nixos-rebuild switch --flake /path/to/this/flake#hostname.
├── home/ # Home Manager configurations
│ ├── programs/ # Nix Packages and configurations
│ └── shell/ # Shell related configurations
├── hosts/ # System-specific configurations
│ ├── hostname1/
│ └── hostname2/
├── modules/ # Reusable NixOS modules
└── users/ # User configurations
├── flake.nix # Main flake configuration
├── flake.lock # Locked dependency versions
- Create a new directory under
hosts/with your hostname - Add the system configuration files
- Reference the new system in
flake.nix - Build and switch to the new configuration
nixosConfigurations = {
new-hostname = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
./hosts/new-hostname/configuration.nix
# Add other modules as needed
];
};
};# Update system packages
nix flake update
# Update and upgrade
nix flake update && sudo nixos-rebuild switch --flake .#hostnameFlake not recognized:
- Ensure flakes are enabled in your Nix configuration
- Use
nix --extra-experimental-features "nix-command flakes"for one-time usage
Build failures:
- Check flake.lock for dependency conflicts
- Try
nix flake updateto resolve version conflicts - Use
nix build --show-tracefor detailed error information
Permission issues:
- Ensure proper ownership of configuration files
- Use
sudofor system-level operations
# Check flake evaluation
nix flake check
# Show flake outputs
nix flake show
# Debug build with traces
sudo nixos-rebuild switch --flake /path/to/this/flake#hostname --show-trace --print-build-logs