User configuration structure
Users are configured in three places:/modules/base/users/options.nix- Declares available users/modules/base/users/<user>.nix- SSH keys and base configuration/modules/nixos/users/<user>.nix- System-level settings (passwords, groups)/home/<user>/- Home-manager configuration (optional)systems/<hostname>/users.nix- Per-system user assignments
Creating a new user
Add user to options.nix
Edit
/modules/base/users/options.nix to include your new user in the default list:modules/base/users/options.nix
Create base user configuration
Create
/modules/base/users/<user>.nix for SSH keys and basic settings:modules/base/users/newuser.nix
Add system-level configuration
Create Generate a hashed password:
/modules/nixos/users/<user>.nix for password and system settings:modules/nixos/users/newuser.nix
Assign user to systems
In each system’s
users.nix file, add the user:systems/yoursystem/users.nix
Main user vs regular users
Main user vs regular users
The
mainUser is treated as the primary user on the system and may receive additional permissions or default configurations. If not specified, the first user in the users list becomes the main user.Create home-manager configuration (optional)
For user-specific applications and settings, create See the Adding Packages guide for package configuration.
/home/<user>/:home/newuser/default.nix
How user creation works
Themkuser.nix module automatically creates users declared in garden.system.users with sensible defaults:
modules/base/users/mkuser.nix
- Home directory location
- Whether the user is a normal user
- Basic group memberships
- Shell configuration
Example user configurations
User template structure
Here’s the recommended structure for a complete user setup:Managing user groups
Users automatically get added to common groups viamkuser.nix. To add additional groups:
systems/yoursystem/users.nix
ifTheyExist helper).
Next steps
Add packages
Install packages for your user
Secrets management
Set up user-level secrets
Adding systems
Create systems for your users
Troubleshooting
Fix common user issues