Forward Across Classes
What forward does
Section titled “What forward does”forward resolves an aspect for one class and injects the result into a submodule path of another class. This enables cross-class configuration routing.
The canonical use case: forward homeManager modules into nixos.home-manager.users.<name>.
Arguments
Section titled “Arguments”forward { each = [ items ]; # list of items to iterate over fromClass = item: "sourceClass"; # class to resolve from intoClass = item: "targetClass"; # class to inject into intoPath = item: [ "path" ]; # submodule path in targetClass fromAspect = item: aspect; # aspect to resolve}| Parameter | Signature | Purpose |
|---|---|---|
each | listOf any | Items to iterate. One forward per item. |
fromClass | item → string | Source class name to resolve |
intoClass | item → string | Target class name to inject into |
intoPath | item → listOf string | Attribute path for the submodule in target |
fromAspect | item → aspect | The aspect to resolve for fromClass |
Return value
Section titled “Return value”forward returns { includes = [ ... ]; } — an aspect with one include per item. Each include:
- Resolves
fromAspect itemforfromClass item - Wraps the resolved module as
{ imports = [ module ]; }atintoPath item - Places the result under
intoClass item
Example
Section titled “Example”flake.aspects = { aspects, ... }: { my-host = { targetClass = { imports = [ targetSubmodule ]; targetMod.names = [ "from-target" ]; }; sourceClass.names = [ "from-source" ]; includes = [ ({ class, aspect-chain }: forward { each = [ "source" ]; fromClass = item: "${item}Class"; intoClass = _: "targetClass"; intoPath = _: [ "targetMod" ]; fromAspect = _: lib.head aspect-chain; }) ]; };};Resolving for "targetClass" merges ["from-target", "from-source"].
Real-world: Home-Manager into NixOS
Section titled “Real-world: Home-Manager into NixOS”This is how Den forwards user home-manager configs into host NixOS:
hmSupport = { host }: forward { each = host.users; fromClass = _user: "homeManager"; intoClass = _user: "nixos"; intoPath = user: [ "home-manager" "users" user.userName ]; fromAspect = user: den.aspects.${user.userName};};Each user’s homeManager aspect gets resolved and placed at nixos.home-manager.users.<name>.