Overview
All NixOS configurations are stored in thesystems/ directory. Each subdirectory with a default.nix file is automatically discovered and exposed as a nixosConfiguration.
Understanding Flake References
The deployment commands use flake references in the format:.refers to the current directory (your flake root)#separates the flake reference from the output attribute<hostname>is the name of the directory insystems/
Local Deployment
Deploy to the current machine you’re working on.Deployment Commands
Different deployment modes for various scenarios:Remote Deployment
Deploy to a remote NixOS system over SSH.Ensure SSH access
Verify you can SSH to the target system:Or configure SSH with appropriate user and sudo access.
Building from Remote Host
For systems with limited resources, build on a more powerful machine:Dynamic Discovery
The flake automatically discovers all system configurations:systems/ containing default.nix is automatically available for deployment.
System Configuration Structure
Each system directory should contain:Rollback and Recovery
Rollback to Previous Generation
If a deployment causes issues:List Available Generations
Switch to Specific Generation
Home Manager Integration
Systems automatically include Home Manager configurations for users. The system will look for:homes/<user>- Base user configurationhomes/<user>@<hostname>- Machine-specific overrides
Troubleshooting
Build Failures
If the build fails:- Check validation output:
nix flake check - Review error messages for missing options or syntax errors
- Verify all required inputs are accessible
- Check disk space:
df -h /nix
Activation Failures
If activation fails after successful build:- System remains on previous generation (safe)
- Check systemd journal:
journalctl -xe - Review activation script output
- Test configuration:
nixos-rebuild test --flake .#<hostname>
SSH Deployment Issues
- Verify SSH key authentication is configured
- Check firewall rules on target system
- Ensure Nix is installed on target system
- Verify network connectivity
Advanced Options
Updating Flake Inputs
Update all dependencies before deploying:Update Specific Input
Show Configuration Diff
See what will change:Best Practices
- Test changes on non-critical systems first
- Keep your flake inputs updated regularly
- Document custom configurations in comments
- Use
nixos-rebuild bootfor major changes - Maintain backup configurations
- Version control all changes with git
Next Steps
- Deploying Home Manager - User-level configurations
- Validating Changes - Pre-deployment validation
- Nix-on-Droid - Android device deployment