Skip to content

Use 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.

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.

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 users
den.aspects.my-host.provides.to-users.homeManager = { ... };
# user contributes to ALL hosts it lives on
den.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.

Marks a user as the primary user of the system:

den.aspects.alice.includes = [ den.batteries.primary-user ];
  • NixOS: adds wheel and networkmanager groups, sets isNormalUser.
  • Darwin: sets system.primaryUser.
  • WSL: sets defaultUser (if WSL is enabled).

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.

Creates custom Nix classes by forwarding module contents into target submodule paths. See Custom Nix Classes for details.

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 aspect
den.aspects.laptop.includes = [ (den.batteries.import-tree ./disko) ];

Requires inputs.import-tree.

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.

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.

Enables automatic TTY1 login on NixOS:

den.aspects.laptop.includes = [ (den.batteries.tty-autologin "alice") ];

Enables automatic TTY1 login on NixOS VMs:

den.aspects.laptop.includes = [ (den.batteries.vm-autologin "alice") ];

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.

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.

Apply to all entities via den.default:

den.default.includes = [
den.batteries.define-user
den.batteries.inputs'
];

Apply to specific aspects:

den.aspects.alice.includes = [
den.batteries.primary-user
(den.batteries.user-shell "zsh")
(den.batteries.unfree [ "vscode" ])
];

Batteries compose with regular aspects:

den.aspects.my-admin = {
includes = [
den.batteries.primary-user
(den.batteries.user-shell "fish")
{ nixos.security.sudo.wheelNeedsPassword = false; }
];
};
Contribute Community Sponsor