Use Batteries
What are Batteries
Section titled “What are Batteries”Batteries are reusable aspects shipped with Den under den.provides.*
(aliased as den._.*). They handle common cross-platform configuration
patterns so you do not have to rewrite them.
Available Batteries
Section titled “Available Batteries”den.provides.define-user
Section titled “den.provides.define-user”Creates OS and home-level user account definitions:
den.default.includes = [ den.provides.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.provides.hostname
Section titled “den.provides.hostname”Sets the system hostname as defined in den.hosts.<name>.hostName:
den.default.includes = [ den.provides.hostname ];den.provides.mutual-provider
Section titled “den.provides.mutual-provider”Allows hosts and users to contribute configuration to each other through .provides.:
den.hosts.x86_64-linux.igloo.users.tux = { };den.ctx.user.includes = [ den._.mutual-provider ];# contributes to ALL users of this hostden.aspects.my-host.provides.to-users.homeManager = { ... }
# contributes to ALL hosts of where my-user existden.aspects.my-user.provides.to-hosts.nixos = { ... }A tux user providing config to specific host igloo:
den.aspects.tux = { provides.igloo = { host, ... }: { nixos.programs.nh.enable = host.name == "igloo"; };};A host providing config to specific user tux:
den.aspects.igloo = { provides.tux = { user, ... }: { homeManager.programs.helix.enable = user.name == "alice"; };};den.provides.primary-user
Section titled “den.provides.primary-user”Marks a user as the primary user of the system:
den.aspects.alice.includes = [ den.provides.primary-user ];- NixOS: adds
wheelandnetworkmanagergroups, setsisNormalUser. - Darwin: sets
system.primaryUser. - WSL: sets
defaultUser(if WSL is enabled).
den.provides.user-shell
Section titled “den.provides.user-shell”Sets the default login shell at both OS and Home Manager levels:
den.aspects.alice.includes = [ (den.provides.user-shell "fish") ];Enables programs.<shell>.enable on the OS and in Home Manager,
and sets users.users.<name>.shell.
den.provides.forward
Section titled “den.provides.forward”Creates custom Nix classes by forwarding module contents into target submodule paths. See Custom Nix Classes for details.
den.provides.import-tree
Section titled “den.provides.import-tree”Recursively imports non-dendritic .nix files, auto-detecting class from
directory names (_nixos/, _darwin/, _homeManager/):
# Import per hostden.ctx.host.includes = [ (den.provides.import-tree._.host ./hosts) ];
# Import per userden.ctx.user.includes = [ (den.provides.import-tree._.user ./users) ];
# Import for a specific aspectden.aspects.laptop.includes = [ (den.provides.import-tree ./disko) ];Requires inputs.import-tree.
den.provides.unfree
Section titled “den.provides.unfree”Enables specific unfree packages by name:
den.aspects.laptop.includes = [ (den.provides.unfree [ "nvidia-x11" "steam" ])];Works for any class (nixos, darwin, homeManager). The unfree predicate
builder is automatically included via den.default.
den.provides.tty-autologin
Section titled “den.provides.tty-autologin”Enables automatic TTY1 login on NixOS:
den.aspects.laptop.includes = [ (den.provides.tty-autologin "alice") ];den.provides.inputs'
Section titled “den.provides.inputs'”Provides flake-parts inputs' (system-specialized inputs) as a module argument:
den.default.includes = [ den.provides.inputs' ];Requires flake-parts. Works in host, user, and home contexts.
den.provides.self'
Section titled “den.provides.self'”Provides flake-parts self' (system-specialized self) as a module argument:
den.default.includes = [ den.provides.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.provides.define-user den.provides.inputs'];Per-Aspect Batteries
Section titled “Per-Aspect Batteries”Apply to specific aspects:
den.aspects.alice.includes = [ den.provides.primary-user (den.provides.user-shell "zsh") (den.provides.unfree [ "vscode" ])];Battery Composition
Section titled “Battery Composition”Batteries compose with regular aspects:
den.aspects.my-admin = den.lib.parametric { includes = [ den.provides.primary-user (den.provides.user-shell "fish") { nixos.security.sudo.wheelNeedsPassword = false; } ];};