Skip to content

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

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.

Sets the system hostname as defined in den.hosts.<name>.hostName:

den.default.includes = [ den.provides.hostname ];

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 host
den.aspects.my-host.provides.to-users.homeManager = { ... }
# contributes to ALL hosts of where my-user exist
den.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";
};
};

Marks a user as the primary user of the system:

den.aspects.alice.includes = [ den.provides.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.provides.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 non-dendritic .nix files, auto-detecting class from directory names (_nixos/, _darwin/, _homeManager/):

# Import per host
den.ctx.host.includes = [ (den.provides.import-tree._.host ./hosts) ];
# Import per user
den.ctx.user.includes = [ (den.provides.import-tree._.user ./users) ];
# Import for a specific aspect
den.aspects.laptop.includes = [ (den.provides.import-tree ./disko) ];

Requires inputs.import-tree.

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.

Enables automatic TTY1 login on NixOS:

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

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.

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.

Apply to all entities via den.default:

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

Apply to specific aspects:

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

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; }
];
};
Contribute Community Sponsor