···11-{ lib, ... }:
11+{ den, ... }:
22let
33-43 description = ''
55- WIP: Creates a class-forwarding aspect.
66- '';
44+ An aspect that imports all modules defined for `from` class
55+ into a target `into` submodule.
7688- forward =
99- cb:
1010- { class, aspect-chain }:
1111- let
1212- fwd = cb { inherit class aspect-chain; };
1313- include =
1414- item:
1515- let
1616- from = fwd.from item;
1717- into = fwd.into item;
1818- aspect = fwd.aspect item;
1919- module = aspect.resolve { class = from; };
2020- in
2121- lib.setAttrByPath into { imports = [ module ]; };
2222- in
2323- {
2424- includes = map include fwd.each;
2525- };
77+ This can be used to create custom Nix classes that help
88+ people separating concerns on huge module hierarchies.
2691010+ For example, using a new `user` class that forwards all its
1111+ settings into `users.users.<userName>` allows:
1212+1313+ den.aspects.alice.nixos.users.users.alice.isNormalUser = true;
1414+1515+ to become:
1616+1717+ den.aspects.alice.user.isNormalUser = true;
1818+1919+2020+ This is exactly how `homeManager` class support is implemented in Den.
2121+ See home-manager/hm-integration.nix.
2222+2323+ Den also provides the mentioned `user` class (`den._.os-user`) for setting
2424+ NixOS/Darwin options under `users.users.<userName>` at os-level.
2525+2626+ Any other user-environments like `nix-maid` or `hjem` or user-custom classes
2727+ are easily implemented using `den._.forward`.
2828+2929+ Note: `den._.forward` is a high-level aspect, its result
3030+ is another aspect that needs to be included for the new class to exist.
3131+3232+ See templates/ci/modules/forward.nix for usage example.
3333+ See also: https://github.com/vic/den/issues/160, https://github.com/vic/flake-aspects/pull/31
3434+ '';
2735in
2836{
2937 den.provides.forward = {
3038 inherit description;
3131- __functor = _self: forward;
3939+ __functor = _self: den.lib.aspects.forward;
3240 };
3341}