forked from
oeiuwq.com/den
Modular, context-aware and aspect-oriented dendritic Nix configurations.
Discussions: https://oeiuwq.zulipchat.com/join/nqp26cd4kngon6mo3ncgnuap/
1{
2 config,
3 lib,
4 withSystem,
5 ...
6}:
7let
8
9 build =
10 builder: cfg:
11 let
12 items = map builtins.attrValues (builtins.attrValues cfg);
13 buildItem = item: {
14 inherit (item) name intoAttr;
15 value = builder item;
16 };
17 in
18 map buildItem (lib.flatten items);
19
20 osConfiguration =
21 host:
22 host.instantiate {
23 modules = [
24 host.mainModule
25 { nixpkgs.hostPlatform = lib.mkDefault host.system; }
26 ];
27 };
28
29 homeConfiguration =
30 home:
31 withSystem home.system (
32 { pkgs, ... }:
33 home.instantiate {
34 inherit pkgs;
35 modules = [ home.mainModule ];
36 }
37 );
38
39 cfgs = (build osConfiguration config.den.hosts) ++ (build homeConfiguration config.den.homes);
40
41 outputs =
42 acc: item:
43 acc
44 // {
45 ${item.intoAttr} = (acc.${item.intoAttr} or { }) // {
46 ${item.name} = item.value;
47 };
48 };
49
50in
51{
52 flake = lib.foldl outputs { } cfgs;
53}