Use Batteries
What are Batteries
Section titled “What are Batteries”Batteries are reusable aspects shipped with Den under den.batteries.*
(the option is also aliased as den.provides.* and den._.*). They handle
common cross-platform configuration patterns so you do not have to rewrite them.
Available Batteries
Section titled “Available Batteries”den.batteries.define-user
Section titled “den.batteries.define-user”Creates OS and home-level user account definitions:
den.default.includes = [ den.batteries.define-user ];Sets users.users.<name> on NixOS/Darwin and home.username/home.homeDirectory
for Home Manager. Works in both host-user and standalone home contexts.
den.batteries.hostname
Section titled “den.batteries.hostname”Sets the system hostname as defined in den.hosts.<name>.hostName:
den.default.includes = [ den.batteries.hostname ];Mutual providers (hosts and users configuring each other)
Section titled “Mutual providers (hosts and users configuring each other)”Hosts and users can contribute configuration to each other through the
aspect’s provides namespace (aliased _). This routing is built into the
pipeline — no battery is required.
# host contributes to ALL its usersden.aspects.my-host.provides.to-users.homeManager = { ... };
# user contributes to ALL hosts it lives onden.aspects.my-user.provides.to-hosts.nixos = { ... };A tux user providing config to the specific host igloo:
den.aspects.tux = { provides.igloo.nixos.programs.nh.enable = true;};A host providing config to the specific user alice:
den.aspects.igloo = { provides.alice.homeManager.programs.helix.enable = true;};A named target (provides.igloo, provides.alice) only fires when the matching
host or user is in scope, so the value can be a plain attrset. See
Host<->User Mutual Providers for the full mechanism.
den.batteries.primary-user
Section titled “den.batteries.primary-user”Marks a user as the primary user of the system:
den.aspects.alice.includes = [ den.batteries.primary-user ];- NixOS: adds
wheelandnetworkmanagergroups, setsisNormalUser. - Darwin: sets
system.primaryUser. - WSL: sets
defaultUser(if WSL is enabled).
den.batteries.user-shell
Section titled “den.batteries.user-shell”Sets the default login shell at both OS and Home Manager levels:
den.aspects.alice.includes = [ (den.batteries.user-shell "fish") ];Enables programs.<shell>.enable on the OS and in Home Manager,
and sets users.users.<name>.shell.
den.batteries.forward
Section titled “den.batteries.forward”Creates custom Nix classes by forwarding module contents into target submodule paths. See Custom Nix Classes for details.
den.batteries.import-tree
Section titled “den.batteries.import-tree”Recursively imports plain .nix files, auto-detecting class from
directory names (_nixos/, _darwin/, _homeManager/):
# Import per host (loads ./hosts/<host>/_nixos, etc.)den.schema.host.includes = [ (den.batteries.import-tree.provides.host ./hosts) ];
# Import per user (loads ./users/<user>/_homeManager, etc.)den.schema.user.includes = [ (den.batteries.import-tree.provides.user ./users) ];
# Import for a specific aspectden.aspects.laptop.includes = [ (den.batteries.import-tree ./disko) ];Requires inputs.import-tree.
den.batteries.unfree
Section titled “den.batteries.unfree”Enables specific unfree packages by name:
den.aspects.laptop.includes = [ (den.batteries.unfree [ "nvidia-x11" "steam" ])];Works for any class (nixos, darwin, homeManager). The unfree predicate
builder is automatically included via den.default.
den.batteries.insecure
Section titled “den.batteries.insecure”Enables specific insecure packages by name:
den.aspects.laptop.includes = [ (den.batteries.insecure [ "foo-1.2.3" ])];Works for any class (nixos, darwin, homeManager). The insecure predicate
builder is automatically included via den.default.
den.batteries.tty-autologin
Section titled “den.batteries.tty-autologin”Enables automatic TTY1 login on NixOS:
den.aspects.laptop.includes = [ (den.batteries.tty-autologin "alice") ];den.batteries.vm-autologin
Section titled “den.batteries.vm-autologin”Enables automatic TTY1 login on NixOS VMs:
den.aspects.laptop.includes = [ (den.batteries.vm-autologin "alice") ];den.batteries.inputs'
Section titled “den.batteries.inputs'”Provides flake-parts inputs' (system-specialized inputs) as a module argument:
den.default.includes = [ den.batteries.inputs' ];Requires flake-parts. Works in host, user, and home contexts.
den.batteries.self'
Section titled “den.batteries.self'”Provides flake-parts self' (system-specialized self) as a module argument:
den.default.includes = [ den.batteries.self' ];Requires flake-parts. Works in host, user, and home contexts.
Usage Patterns
Section titled “Usage Patterns”Global Batteries
Section titled “Global Batteries”Apply to all entities via den.default:
den.default.includes = [ den.batteries.define-user den.batteries.inputs'];Per-Aspect Batteries
Section titled “Per-Aspect Batteries”Apply to specific aspects:
den.aspects.alice.includes = [ den.batteries.primary-user (den.batteries.user-shell "zsh") (den.batteries.unfree [ "vscode" ])];Battery Composition
Section titled “Battery Composition”Batteries compose with regular aspects:
den.aspects.my-admin = { includes = [ den.batteries.primary-user (den.batteries.user-shell "fish") { nixos.security.sudo.wheelNeedsPassword = false; } ];};