Skip to content

Batteries

Den ships reusable aspect providers under den.batteries (also accessible via the aliases den.provides and den._). Each battery contributes NixOS/Darwin/home-manager modules to hosts and users that include them.

Batteries fall into two categories:

  • Opt-in — you include them explicitly in den.default.includes, den.aspects.<name>.includes, or den.schema.<kind>.includes.
  • Auto-activated — Den activates them via built-in policies. They define new classes or integration layers that work without explicit inclusion.

Creates OS-level user accounts (users.users.<name>) with isNormalUser and home directory. Also sets home.username and home.homeDirectory for Home Manager. Works on NixOS, Darwin, and standalone Home Manager.

Opt-in.

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

Sets the system hostname from den.hosts.<name>.hostName. Works on NixOS and Darwin.

Opt-in.

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

Provides an os convenience class that forwards its contents into both nixos and darwin classes. This lets you write platform-agnostic host configuration without duplicating it across classes.

Auto-activated for both host and user entity kinds.

den.aspects.my-host = {
os.networking.hostName = "foo";
};

Provides a user class that forwards settings into the host’s users.users.<userName> at OS level. Instead of writing the full nixos.users.users.alice path, you write directly into the user class.

Auto-activated for the user entity kind.

den.aspects.alice.user = { pkgs, ... }: {
packages = [ pkgs.hello ];
extraGroups = [ "wheel" ];
};

Marks a user as the primary (admin-level) user. On NixOS, adds wheel and networkmanager groups. On Darwin, sets system.primaryUser. On WSL, sets defaultUser.

Opt-in.

den.aspects.alice.includes = [ den.batteries.primary-user ];

Sets the user’s login shell at both OS and Home Manager levels. Enables programs.<shell>.enable and sets users.users.<name>.shell.

Opt-in. Takes a shell name as argument.

den.aspects.alice.includes = [
(den.batteries.user-shell "fish")
];

Projects user-relevant classes (like homeManager) from the host’s aspect tree onto users who opt in. Any homeManager key defined in the host aspect is forwarded to the user’s home-manager evaluation.

Opt-in.

den.aspects.tux.includes = [ den.batteries.host-aspects ];

Configures automatic TTY1 login on NixOS via a systemd getty override. NixOS only.

Opt-in. Takes a username as argument.

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

Configures automatic TTY1 login on NixOS VMs via a systemd getty override. NixOS VMs only.

Opt-in. Takes a username as argument.

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

Enables WSL support on NixOS using the NixOS-WSL project. Adds a wsl-host entity kind and forwards the wsl class into the host’s NixOS configuration.

Auto-activated when host.wsl.enable = true. Requires inputs.nixos-wsl.

den.hosts.x86_64-linux.igloo.wsl.enable = true;

A generic forwarding primitive that creates custom Nix classes by routing module contents from one class into a target submodule path. This is how os-user, homeManager, hjem, and maid integrations are implemented internally.

Opt-in. Used when building custom classes. See the Custom Classes guide.

den.batteries.forward {
each = lib.singleton user;
fromClass = _: "myClass";
intoClass = _: host.class;
intoPath = _: [ "some" "path" ];
fromAspect = _: user.aspect;
};

Recursively imports plain .nix files, auto-detecting class from directory name conventions (_nixos/, _darwin/, _homeManager/). Useful for migrating existing configurations.

Opt-in. Requires inputs.import-tree.

# Import per host
den.schema.host.includes = [
(den.batteries.import-tree.provides.host ./hosts)
];
# Import per user
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)
];

Integrates home-manager as a user environment class. Defines the hm-host entity kind, imports the appropriate home-manager NixOS or Darwin module, and merges home-manager.users.<name> from each user’s homeManager class.

Auto-activated when users have homeManager classes. Requires inputs.home-manager.

den.aspects.alice.homeManager = {
programs.git.enable = true;
};

Integrates hjem as an alternative home environment. Imports hjem’s NixOS or Darwin module and merges hjem.users.<name> from each user’s hjem class.

Auto-activated when users have hjem classes. Requires inputs.hjem.

den.aspects.alice.hjem = {
packages = [ pkgs.ripgrep ];
};

Integrates maid as an alternative home environment. NixOS only. Merges configuration into users.users.<name>.maid for each user’s maid class.

Auto-activated when users have maid classes. Requires inputs.nix-maid.

den.aspects.alice.maid = {
programs.helix.enable = true;
};

Allows specific unfree packages by name via nixpkgs.config.allowUnfreePredicate. Works for any class (nixos, darwin, homeManager). The predicate builder is automatically included in den.default.

Opt-in. Takes a list of package names as argument.

den.aspects.laptop.includes = [
(den.batteries.unfree [ "nvidia-x11" "steam" ])
];

Allows specific insecure packages by name and version via nixpkgs.config.permittedInsecurePackages. Works for any class (nixos, darwin, homeManager). The predicate builder is automatically included in den.default.

Opt-in. Takes a list of package name-version strings as argument.

den.aspects.laptop.includes = [
(den.batteries.insecure [ "openssl-1.1.1w" ])
];

These batteries require flake-parts as the module system.

Provides inputs' (the flake’s inputs with system pre-selected) as a top-level module argument. Contextual: configures the appropriate class depending on whether it is included in a host, user, or home aspect.

Opt-in.

den.default.includes = [ den.batteries.inputs' ];

Provides self' (the flake’s self outputs with system pre-selected) as a top-level module argument. Contextual: configures the appropriate class depending on whether it is included in a host, user, or home aspect.

Opt-in.

den.default.includes = [ den.batteries.self' ];

Apply batteries to all hosts, users, and homes:

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

Apply batteries to specific aspects:

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

Apply batteries to all entities of a kind:

den.schema.user.includes = [
den.batteries.define-user
];

Batteries compose freely with inline configuration:

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