Modular, context-aware and aspect-oriented dendritic Nix configurations.
Discussions: https://oeiuwq.zulipchat.com/join/nqp26cd4kngon6mo3ncgnuap/
den.oeiuwq.com
configurations
den
dendritic
nix
aspect
oriented
1{
2 inputs,
3 den,
4 ...
5}:
6{
7 den.provides.import-tree.description = ''
8 Recursively imports non-dendritic .nix files depending on their Nix configuration `class`.
9
10 This can be used to help migrating from huge existing setups.
11
12
13 ```
14 # this is at <repo>/modules/non-dendritic.nix
15 den.aspects.my-laptop.includes = [
16 (den._.import-tree._.host ../non-dendritic)
17 ]
18 ```
19
20 With following structure, it will automatically load modules depending on their class.
21
22 ```
23 <repo>/
24 modules/
25 non-dendritic.nix # configures this aspect
26 non-dendritic/ # name is just an example here
27 hosts/
28 my-laptop/
29 _nixos/ # a directory for `nixos` class
30 auto-generated-hardware.nix # any nixos module
31 _darwin/
32 foo.nix
33 _homeManager/
34 me.nix
35 ```
36
37 ## Requirements
38
39 - inputs.import-tree
40
41 ## Usage
42
43 this aspect can be included explicitly on any aspect:
44
45 # example: will import ./disko/_nixos files automatically.
46 den.aspects.my-disko.includes = [ (den._.import-tree ./disko/) ];
47
48 or it can be default imported per host/user/home:
49
50 # load from ./hosts/<host>/_nixos
51 den.ctx.os.includes = [ (den._.import-tree._.host ./hosts) ];
52
53 # load from ./users/<user>/{_homeManager, _nixos}
54 den.ctx.hm.includes = [ (den._.import-tree._.user ./users) ];
55
56 # load from ./homes/<home>/_homeManager
57 den.ctx.home.includes = [ (den._.import-tree._.home ./homes) ];
58
59 you are also free to create your own auto-imports layout following the implementation of these.
60 '';
61
62 den._.import-tree.__functor =
63 _: root:
64 { class, aspect-chain }:
65 let
66 path = den.lib.take.unused aspect-chain "${toString root}/_${class}";
67 aspect.${class}.imports = [ (inputs.import-tree path) ];
68 in
69 if builtins.pathExists path then aspect else { };
70
71 den._.import-tree.provides = {
72 host = root: { host, ... }: den._.import-tree "${toString root}/${host.name}";
73 home = root: { home, ... }: den._.import-tree "${toString root}/${home.name}";
74 user = root: { user, ... }: den._.import-tree "${toString root}/${user.name}";
75 };
76}