fake.modules transposition for aspect-oriented Dendritic Nix. with cross-aspect dependencies. Discussions: https://oeiuwq.zulipchat.com/join/nqp26cd4kngon6mo3ncgnuap/
dendrix.oeiuwq.com/Dendritic.html
dendritic
nix
aspect
oriented
1# An utility for creating new aspect configuration classes that
2# help with separation of concerns.
3#
4# `forward` is a function that generates an aspect
5# that imports configurations from an originClass into
6# an scoped submodule of another targetClass.
7#
8# It takes te following arguments:
9#
10# - each: listOf items.
11# - fromClass: item -> originClassName.
12# - intoClass: item -> targetClassName.
13# - intoPath: item -> [ submoduleAttrPath ].
14# - fromAspect: item -> aspect. An aspect to resolve origin class modules from.
15#
16# This is particularly useful for per-user homeManager like
17# configurations.
18#
19# The following pseudo-code snippet is used by [den](https://github.com/vic/den)
20# to support homeManager classes on NixOS.
21#
22# hmSupport = { host }: forward {
23# each = host.users;
24# fromClass = _user: "homeManager"; # originClass could have depended on user.
25# intoClass = _user: "nixos"
26# intoPath = user: [ "home-manager" "users" user.userName ] # HM users submodule.
27# fromAspect = user: den.aspects.${user.userName}; # resolve originClass from user aspect.
28# }
29#
30#
31# den.aspects.my-host.includes = [ hmSupport ];
32# den.aspects.my-user = {
33# homeManager = { }; # settings for nixos.home-manager.users.my-user submodule.
34# }
35#
36# However usage is not limited to HM, and this settings forwarding ability
37# can be used for other use cases.
38#
39# See checkmate/modules/tests/forward.nix for working example.
40#
41lib:
42{
43 each,
44 fromClass,
45 intoClass,
46 intoPath,
47 fromAspect,
48}:
49let
50 resolve = import ./resolve.nix lib;
51 include =
52 item:
53 let
54 from = fromClass item;
55 into = intoClass item;
56 path = intoPath item;
57 aspect = fromAspect item;
58 module = resolve from [ ] aspect;
59 config = lib.setAttrByPath path (
60 { ... }:
61 {
62 imports = [ module ];
63 }
64 );
65 in
66 {
67 ${into} = config;
68 };
69in
70{
71 includes = map include each;
72}