···1-{ lib, ... }:
2let
3-4 description = ''
5- WIP: Creates a class-forwarding aspect.
6- '';
78- forward =
9- cb:
10- { class, aspect-chain }:
11- let
12- fwd = cb { inherit class aspect-chain; };
13- include =
14- item:
15- let
16- from = fwd.from item;
17- into = fwd.into item;
18- aspect = fwd.aspect item;
19- module = aspect.resolve { class = from; };
20- in
21- lib.setAttrByPath into { imports = [ module ]; };
22- in
23- {
24- includes = map include fwd.each;
25- };
26000000000000000000000000027in
28{
29 den.provides.forward = {
30 inherit description;
31- __functor = _self: forward;
32 };
33}
···1+{ den, ... }:
2let
03 description = ''
4+ An aspect that imports all modules defined for `from` class
5+ into a target `into` submodule.
67+ This can be used to create custom Nix classes that help
8+ people separating concerns on huge module hierarchies.
0000000000000000910+ For example, using a new `user` class that forwards all its
11+ settings into `users.users.<userName>` allows:
12+13+ den.aspects.alice.nixos.users.users.alice.isNormalUser = true;
14+15+ to become:
16+17+ den.aspects.alice.user.isNormalUser = true;
18+19+20+ This is exactly how `homeManager` class support is implemented in Den.
21+ See home-manager/hm-integration.nix.
22+23+ Den also provides the mentioned `user` class (`den._.os-user`) for setting
24+ NixOS/Darwin options under `users.users.<userName>` at os-level.
25+26+ Any other user-environments like `nix-maid` or `hjem` or user-custom classes
27+ are easily implemented using `den._.forward`.
28+29+ Note: `den._.forward` is a high-level aspect, its result
30+ is another aspect that needs to be included for the new class to exist.
31+32+ See templates/ci/modules/forward.nix for usage example.
33+ See also: https://github.com/vic/den/issues/160, https://github.com/vic/flake-aspects/pull/31
34+ '';
35in
36{
37 den.provides.forward = {
38 inherit description;
39+ __functor = _self: den.lib.aspects.forward;
40 };
41}