Context Pipeline
Pipeline Overview
Section titled “Pipeline Overview”When Den evaluates a host, it walks a pipeline of context transformations:
flowchart TD
start["den.hosts.x86_64-linux.laptop"] --> host["den.ctx.host {host}"]
host -->|"_.host"| owned["Owned config: fixedTo {host} aspects.laptop"]
host -->|"_.user"| userctx["atLeast aspects.laptop {host, user}"]
host -->|"into.user"| user["den.ctx.user {host, user} (per user)"]
user -->|"_.user"| userown["fixedTo {host,user} aspects.alice"]
host -->|"into.hm-host"| hmhost["den.ctx.hm-host {host}"]
hmhost -->|"import HM module"| hmmod["home-manager OS module"]
hmhost -->|"into.hm-user"| hmuser["den.ctx.hm-user {host, user}"]
hmuser -->|"forward homeManager class"| fwd["home-manager.users.alice"]
-
Host Context
For each entry in
den.hosts.<system>.<name>, Den creates a{host}context. The host context type (den.ctx.host) contributes:_.host— Applies the host’s own aspect withfixedTo { host }, making all owned configs available for the host’s class._.user— For each user, applies the host’s aspect withatLeast { host, user }, activating parametric includes that need both host and user.
-
User Context
into.usermaps eachhost.usersentry into a{host, user}context. The user context type (den.ctx.user) contributes:_.user— Applies the user’s own aspect withfixedTo { host, user }.
-
Derived Contexts
Batteries register additional
into.*transformations on the host context:Transition Condition Produces into.hm-hosthost.home-manager.enable && hasHmUsers{host}hm-hostinto.hm-userPer HM-class user on hm-host {host, user}hm-userinto.wsl-hosthost.class == "nixos" && host.wsl.enable{host}wsl-hostinto.hjem-hosthost.hjem.enable && hasHjemUsers{host}hjem-hostinto.hjem-userPer hjem-class user {host, user}hjem-userinto.maid-hosthost.nix-maid.enable && hasMaidUsers{host}maid-hostinto.maid-userPer maid-class user {host, user}maid-userEach derived context can contribute its own aspect definitions and import the necessary OS-level modules (e.g.,
home-manager.nixosModules.home-manager). -
Deduplication
dedupIncludesinmodules/context/types.nixensures:- First occurrence of a context type uses
parametric.fixedTo, which includes owned configs + statics + parametric matches. - Subsequent occurrences use
parametric.atLeast, which only includes parametric matches (owned/statics already applied).
This prevents
den.defaultconfigs from being applied twice when the same aspect appears at multiple pipeline stages. - First occurrence of a context type uses
-
Home Configurations
Standalone
den.homesentries go through a separate path:flowchart TD home["den.homes.x86_64-linux.alice"] --> homectx["den.ctx.home {home}"] homectx --> resolve["fixedTo {home} aspects.alice"] resolve --> hmc["homeConfigurations.alice"]Home contexts have no host, so functions requiring
{ host }are not activated. Functions requiring{ home }run instead. -
Output
modules/config.nixcollects all hosts and homes, callshost.instantiate(defaults tolib.nixosSystem,darwinSystem, orhomeManagerConfigurationdepending on class), and places results intoflake.nixosConfigurations,flake.darwinConfigurations, orflake.homeConfigurations.