-
Notifications
You must be signed in to change notification settings - Fork 0
4.Extending Your Configuration
Now that you have a working Nucleus setup, this page explains how to scale your configuration by adding more hosts, users, and features beyond the starter template.
Expanding to multiple machines is straightforward with Nucleus. Each host is independent but can share common configuration.
-
Create a new host directory in
modules/hosts/:mkdir -p modules/hosts/SECOND_HOSTNAME
-
Add host definition to
flake.nixin theletblock underhosts:hosts = { laptop = { ... }; SECOND_HOSTNAME = { hostName = "SECOND_HOSTNAME"; stateVersion = "YEAR.RELEASE OF THE ISO YOU ARE INSTALLING FROM"; timeZone = "REGION/CITY"; disko = { storageDevice = "/dev/DEVICE"; swapSize = "8G"; }; }; };
-
Generate hardware report for the second machine during installation. Save the
hardware_report.jsonfile inmodules/hosts/SECOND_HOSTNAME/. -
Create host-specific configuration at
modules/hosts/SECOND_HOSTNAME/default.nixwith hardware settings specific to that machine. -
Add a disko configuration in
flake.nixoutputs:diskoConfigurations.${hosts.SECOND_HOSTNAME.hostName} = import ./modules/common/disko/bare-ext4.nix hosts.SECOND_HOSTNAME.disko;
-
Add nixosConfiguration to
flake.nixoutputs. Use the same pattern as the first host but referencehosts.SECOND_HOSTNAMEand the second hostname's path. -
Optionally customize features by enabling or disabling entries in the host's
moduleslist to select which features frommodules/features/apply to this host.
Nucleus supports multiple users per host. Users are defined centrally but can be customized per host.
-
Add to
usersdefinition inflake.nix:users = { primary = { ... }; secondary = { userName = "SECONDARY_USERNAME"; realName = "REAL NAME"; hashedPassword = "OUTPUT OF mkpasswd"; emailAddress = "secondary@mailbox.com"; gpgKey = "KEY_ID"; }; };
-
Register The User: Register the user with the host or a feature using the following snippet
users = { ${users.secondary.userName} = { isNormalUser = true; description = users.secondary.realName; extraGroups = [ /* specify groups here */ ]; inherit (users.secondary) hashedPassword; }; };
-
(optional, as per need) Pass user to Home Manager by adding them to
specialArgsin the host'snixosConfigurations:inherit (users.secondary) userName realName hashedPassword emailAddress gpgKey;
-
(optional, as per need) Create user-specific home configuration if needed at
modules/features/home-manager/SECONDARY_USERNAME_HOME.nix, and then include the file indecl.nixasusers.${hmArgs.secondary} = import ./SECONDARY_USERNAME_HOME.nix. -
Each user can have independent dotfiles, packages, and shell configurations managed declaratively.
Features in modules/features/ are reusable components. You can enable or disable them per host.
-
Create feature directory:
mkdir -p modules/features/my-feature
-
Write feature module at
modules/features/my-feature/default.nix:{ pkgs, ... }: { # Your configuration here environment.systemPackages = with pkgs; [ package1 package2 ]; }
-
Enable per-host by importing it in the host's
moduleslist:modules = [ ./modules/common/nixos-core/core.nix ./modules/features/workstation/workstation.nix ./modules/features/my-feature/default.nix # Add this ./modules/hosts/${hosts.laptop.hostName}/default.nix ... ];
The default bare-ext4.nix is suitable for most setups. For other layouts (encrypted, LVM, Btrfs, etc.), refer to the disko examples.
To use a different layout:
-
Select an example from the disko repository that matches your needs.
-
Save it to
modules/common/disko/(e.g.,encrypted-ext4.nix). -
Update the import in
flake.nix:diskoConfigurations.${hosts.laptop.hostName} = import ./modules/common/disko/encrypted-ext4.nix hosts.laptop.disko;
-
Update the disko module reference in your host's
nixosConfigurations.
Disko configuration is beyond the scope of this guide. Refer to the disko documentation for layout-specific details.
Keep common configuration DRY by placing shared settings in modules/common/ rather than duplicating per host.
Use clear naming so host names and feature names reflect their purpose. Note that host names cannot contain hyphens.
Test incrementally with nh os test to preview changes before committing them to the bootloader.
Track changes in git to version control your flake.nix and module changes for easy rollback if needed.
Isolate host-specific logic by putting hardware, drivers, and host-only options in modules/hosts/HOSTNAME/default.nix.
Document custom features by adding comments to custom modules that explain their purpose and configuration options.
- Explore the Nucleus repository examples for additional feature implementations.
- Refer to the NixOS manual for detailed option documentation.
- Use
nix flake showto verify all defined configurations and outputs. - Consult
nh os infoto inspect installed generations and rollback if needed.