Adding New Hosts
This guide explains how to add a new machine configuration to the NixOS/Darwin system configuration.
Prerequisites
- Access to the target machine
- Hardware information (if adding a NixOS system)
- Understanding of the machine's intended purpose and configuration needs
Step-by-Step Process
1. Create Machine Directory
Create a new directory for your machine under machines/
:
mkdir machines/[machine-name]
cd machines/[machine-name]
2. Generate Hardware Configuration (NixOS Only)
For NixOS systems, generate the initial hardware configuration:
# On the target machine
nixos-generate-config --show-hardware-config > hardware-configuration.nix
Copy this file to your machines/[machine-name]/
directory.
3. Create Machine Configuration
Create a default.nix
file in your machine directory:
{
inputs,
outputs,
lib,
config,
pkgs,
...
}: {
imports = [
# Include hardware configuration (NixOS only)
./hardware-configuration.nix
# Add any machine-specific modules
# ./custom-module.nix
];
# Set state version
dc-tec.stateVersion = "24.05";
# Configure user settings
dc-tec.user = {
name = "your-username";
fullName = "Your Full Name";
email = "your@email.com";
};
# Enable desired modules
dc-tec = {
# Add your specific module configurations here
};
# System-specific configuration
networking.hostName = "machine-name";
# Add any additional system configuration
}
4. Add to Flake Configuration
Edit flake.nix
and add your new machine to the appropriate outputs section:
For NixOS machines:
nixosConfigurations = {
# ... existing machines ...
your-machine = nixpkgs.lib.nixosSystem {
specialArgs = {
inherit inputs outputs;
lib = lib "x86_64-linux"; # or "aarch64-linux"
};
modules = sharedModules ++ nixosModules ++ [ ./machines/your-machine/default.nix ];
};
};
For Darwin machines:
darwinConfigurations = {
# ... existing machines ...
your-machine = darwin.lib.darwinSystem {
specialArgs = {
inherit inputs outputs;
lib = lib "aarch64-darwin"; # or "x86_64-darwin"
};
modules = sharedModules ++ darwinModules ++ [ ./machines/your-machine/default.nix ];
};
};
5. Configure Machine-Specific Settings
Customize your machine configuration based on its intended use:
Development Workstation
dc-tec.development = {
enable = true;
languages = {
go.enable = true;
python.enable = true;
nodejs.enable = true;
};
};
Server System
dc-tec.services = {
ssh.enable = true;
# Add other server services
};
Desktop System
dc-tec.desktop = {
enable = true;
# Configure desktop environment
};
6. Build and Test
Test your configuration:
# For NixOS
sudo nixos-rebuild test --flake .#your-machine
# For Darwin
darwin-rebuild check --flake .#your-machine
7. Deploy Configuration
Once tested, deploy the configuration:
# For NixOS
sudo nixos-rebuild switch --flake .#your-machine
# For Darwin
darwin-rebuild switch --flake .#your-machine
8. Document Your Machine
Create documentation for your new machine in docs/machines/your-machine.md
following the format of existing machine documentation.
Common Configuration Patterns
Laptop Configuration
- Enable power management
- Configure display settings
- Set up wireless networking
Server Configuration
- Disable desktop environment
- Enable SSH and remote access
- Configure firewall rules
- Set up monitoring and logging
Development Machine
- Enable development tools
- Configure container support
- Set up language toolchains
- Enable virtualization
Troubleshooting
Build Failures
- Check syntax in your
default.nix
- Ensure all imported modules exist
- Verify hardware configuration is correct
Module Conflicts
- Review enabled modules for conflicts
- Check module documentation for requirements
- Use
lib.mkForce
to override conflicting options
Hardware Issues
- Regenerate hardware configuration
- Check hardware-specific module requirements
- Review kernel and driver settings
Next Steps
After successfully adding your machine:
- Update the documentation index
- Test the configuration thoroughly
- Add any machine-specific secrets to SOPS
- Configure backups and maintenance schedules