···4545}
4646```
47474848+Example: A git class that forwards to home-manager.
4949+5050+```nix
5151+gitClass =
5252+ { class, aspect-chain }:
5353+ den._.forward {
5454+ each = lib.singleton true;
5555+ fromClass = _: "git";
5656+ intoClass = _: "homeManager";
5757+ intoPath = _: [
5858+ "programs"
5959+ "git"
6060+ ];
6161+ fromAspect = _: lib.head aspect-chain;
6262+ adaptArgs =
6363+ { config, ... }:
6464+ {
6565+ osConfig = config;
6666+ };
6767+ };
6868+6969+den.aspects.tux = {
7070+ includes = [ gitClass ];
7171+ git.userEmail = "root@linux.com";
7272+};
7373+```
7474+7575+This will set at host: `igloo.home-manager.users.tux.programs.git.userEmail`
7676+48774978## Use Cases
5079
+58-49
docs/src/content/docs/guides/home-manager.mdx
···11---
22-title: Home-Manager Integration
22+title: Homes Integration (hm / hjem / nix-maid, etc)
33description: Integrate Home-Manager into NixOS/Darwin hosts or use standalone.
44---
55···8899<Aside title="Use the Source, Luke" icon="github">
1010[`hm-os.nix`](https://github.com/vic/den/blob/main/modules/aspects/provides/home-manager/hm-os.nix) · [`hm-integration.nix`](https://github.com/vic/den/blob/main/modules/aspects/provides/home-manager/hm-integration.nix)
1111+1212+[`hjem-os.nix`](https://github.com/vic/den/blob/main/modules/aspects/provides/hjem/hjem-os.nix) · [`hjem-integration.nix`](https://github.com/vic/den/blob/main/modules/aspects/provides/hjem/hjem-integration.nix)
1313+1414+[`maid-os.nix`](https://github.com/vic/den/blob/main/modules/aspects/provides/maid/maid-os.nix) · [`maid-integration.nix`](https://github.com/vic/den/blob/main/modules/aspects/provides/maid/maid-integration.nix)
1515+1116</Aside>
12171313-## Automatic HM Detection
1818+Den supports different Nix libraries for managing user home files.
1919+All of them have Nix classes implemented using `den.provides.forward`
2020+and you can create custom home-like classes following the same pattern.
14211515-Den automatically detects hosts that need Home-Manager. When a host has
1616-users with `"homeManager"` in their `classes` list (the default), Den:
2222+- `user` class. NixOS and nix-Darwin builtin `users.users.<userName>` submodule.
2323+- `homeManager` class. Enabled via `host.home-manager.enable`
2424+- `hjem` class. Enabled via `host.hjem.enable`
2525+- `maid` class. Enabled via `host.nix-maid.enable`.
17261818-1. Imports the Home-Manager NixOS/Darwin module
1919-2. Creates a `homeManager` class for each user
2020-3. Forwards `homeManager` configs into `home-manager.users.<name>`
2727+Class names follow the Nix class used by the module system of these projects
2828+not the project name, e.g: [`homeManager`](https://github.com/nix-community/home-manager/blob/f140aa04d7d14f8a50ab27f3691b5766b17ae961/modules/default.nix#L32).
21292222-No explicit opt-in needed — just declare users.
3030+Except for the `user` class which is always enabled, other home classes
3131+are opt-in features, enabled via the host configuration:
23322424-```mermaid
2525-graph LR
2626- Host["{host}"] -->|"hm-detect"| Check{"class ∈ nixos,darwin?<br/>HM users exist?<br/>HM module available?"}
2727- Check -->|"yes"| HM["ctx.hm-host<br/>imports HM module"]
2828- HM -->|"per user"| FW["forward homeManager<br/>→ home-manager.users.‹name›"]
2929- Check -->|"no"| Skip["HM pipeline skipped"]
3333+```nix
3434+# per host:
3535+den.hosts.x86_64-linux.igloo.home-manager = {
3636+ enable = true;
3737+3838+ # optionally with custom stable/unstable HM input
3939+ module = inputs.home-manager-unstable.nixosModules.default;
4040+};
4141+4242+# Globally (or conditionally on host)
4343+den.base.host = { host, ... }: {
4444+ home-manager.enable = host.name == "igloo";
4545+};
3046```
31474848+## Multi Home support.
4949+5050+User can choose to manage some files with home-manager instead or in
5151+addition to nix-maid and hjem. For example, when migrating away from home-manager into other libraries, you might want to keep your stuff working as you move progressively.
5252+5353+Users define a `<user>.classes = [ "homeManager" ]` (default) where they
5454+explicitly enable the different home libraries they use.
5555+3256## Host-Managed Users
33573458```nix
3559den.hosts.x86_64-linux.igloo.users.tux = { };
3636-den.default.homeManager.home.stateVersion = "25.11";
6060+6161+# host meta configuration (capabilities), HM always enabled.
6262+den.base.host.home-manager.enable = lib.mkDefault true;
6363+6464+# homeManager default settings
6565+den.default.homeManager.home.stateVersion = lib.mkDefault "25.11";
37666767+# NixOS/Nix-Darwin user class.
6868+den.aspects.tux.user.description = "The Penguin";
6969+7070+# homeManager class
3871den.aspects.tux.homeManager.programs.vim.enable = true;
3972```
40737474+User description forwarded into `igloo.users.users.tux.description`.
4175The vim config is forwarded into `igloo.home-manager.users.tux`.
42764377## Standalone Home-Manager
···52865387Build with `home-manager switch --flake .#vic`.
54885555-## The define-user Battery
8989+## Context types for Home enabled hosts.
56905757-Use `den._.define-user` to automatically set username and home directory:
9191+Each Home integration in Den defines a context
9292+transformation from `den.ctx.host -> den.ctx.${name}-host`.
58935959-```nix
6060-den.default.includes = [ den._.define-user ];
6161-```
9494+For example, `den.ctx.hm-host` is the aspect for Home-Manager enabled hosts.
9595+Similarly `den.ctx.maid-host` and `den.ctx.hjem-host`.
62966363-This sets `home.username`, `home.homeDirectory`, and
6464-`users.users.<name>` on both NixOS and Darwin.
9797+## useGlobalPkgs at Home Manager enabled hosts
65986666-## useGlobalPkgs
6767-6868-Configure Home-Manager to use the host's nixpkgs:
9999+Configure a NixOS option only for Home-Manager hosts
100100+so they can use the host's nixpkgs:
6910170102```nix
71103den.ctx.hm-host.nixos.home-manager.useGlobalPkgs = true;
72104```
7310574106This only activates for hosts that actually have Home-Manager users.
7575-Hosts without users are unaffected.
7676-7777-## Custom HM Module
7878-7979-Override the Home-Manager module source:
8080-8181-```nix
8282-den.hosts.x86_64-linux.igloo = {
8383- hm-module = inputs.home-manager-unstable.nixosModules.home-manager;
8484- users.tux = { };
8585-};
8686-```
107107+Hosts without Home-Manager users are unaffected.
8710888109## Standalone with osConfig
89110···104125};
105126```
106127107107-## Context Hooks
108128109109-Use `den.ctx.hm-host` to configure things only when HM is active:
110110-111111-```nix
112112-den.ctx.hm-host.nixos.home-manager.useGlobalPkgs = true;
113113-den.ctx.hm-host.includes = [
114114- { nixos.home-manager.backupFileExtension = "bak"; }
115115-];
116116-```
117117-118118-These only apply to hosts that have Home-Manager users with
119119-a supported OS (NixOS or Darwin).
···43434444in
4545{
4646- den.provides.home-manager = { };
4646+ den.provides.home-manager =
4747+ _:
4848+ throw ''
4949+ NOTICE: den.provides.home-manager aspect is not needed anymore.
5050+5151+ Enabling Home Manager is now made via the host config:
5252+5353+ Per host:
5454+5555+ den.hosts.x86_64-linux.igloo.home-manager.enable = true;
5656+5757+ On ALL hosts:
5858+5959+ den.base.host.home-manager.enable = true;
6060+6161+ See <den/home-manager/hm-os.nix>
6262+6363+ If you had includes at den._.home-manager, you can use:
6464+6565+ den.ctx.hm-host.includes = [ ... ];
6666+6767+ For attaching aspects to home-manager enabled hosts.
6868+ '';
47694870 den.ctx.home.description = "Standalone Home-Manager config provided by home aspect";
4971 den.ctx.home._.home = { home }: parametric.fixedTo { inherit home; } den.aspects.${home.aspect};
+25-12
modules/aspects/provides/home-manager/hm-os.nix
···99 Detects hosts that have an HM supported OS and
1010 that have at least one user with ${hm-class} class.
11111212- When this occurs it produces a context `den.ctx.hm-os`
1212+ When this occurs it produces a context `den.ctx.hm-host`
13131414 This `den.ctx.hm-os` context includes the OS-level
1515 homeManager module and is used by hm-integration.nix to then
1616- produce a `den.ctx.hm` for each user.
1616+ produce a `den.ctx.hm-user` for each user.
17171818 This same context can be used to include aspects
1919 ONLY for hosts having HM enabled.
20202121- den.ctx.hm-os.includes = [ den.aspects.foo ];
2121+ den.ctx.hm-host.includes = [ den.aspects.foo ];
2222 '';
23232424 hm-class = "homeManager";
···2626 "nixos"
2727 "darwin"
2828 ];
2929- hm-module = host: host.hm-module or inputs.home-manager."${host.class}Modules".home-manager;
2929+3030+ hostConf =
3131+ { host, ... }:
3232+ {
3333+ options.home-manager = {
3434+ enable = lib.mkEnableOption "Enable Home Manager integration";
3535+ module = lib.mkOption {
3636+ type = lib.types.deferredModule;
3737+ default = inputs.home-manager."${host.class}Modules".home-manager;
3838+ };
3939+ };
4040+ };
30413142 hm-detect =
3243 { host }:
3344 let
3445 is-os-supported = builtins.elem host.class hm-os-classes;
3535- has-hm-module = (host ? hm-module) || (inputs ? home-manager);
3646 hm-users = builtins.filter (u: lib.elem hm-class u.classes) (lib.attrValues host.users);
3747 has-hm-users = builtins.length hm-users > 0;
3838- is-hm-host = is-os-supported && has-hm-users && has-hm-module;
4848+ is-hm-host = host.home-manager.enable && is-os-supported && has-hm-users;
3949 in
4050 lib.optional is-hm-host { inherit host; };
41514242-in
4343-{
4444- den.ctx.host.into.hm-host = hm-detect;
5252+ ctx.host.into.hm-host = hm-detect;
45534646- den.ctx.hm-host.description = description;
4747- den.ctx.hm-host._.hm-host =
5454+ ctx.hm-host.description = description;
5555+ ctx.hm-host.provides.hm-host =
4856 { host }:
4957 {
5050- ${host.class}.imports = [ (hm-module host) ];
5858+ ${host.class}.imports = [ host.home-manager.module ];
5159 };
6060+6161+in
6262+{
6363+ den.ctx = ctx;
6464+ den.base.host.imports = [ hostConf ];
5265}