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 lib,
3 inputs,
4 config,
5 ...
6}:
7let
8 den.lib = inputs.target.lib { inherit lib inputs config; };
9
10 inherit (den.lib) parametric canTake;
11
12 aspect-example = parametric.atLeast {
13 nixos.foo = 99;
14 includes = [
15 { nixos.static = 100; }
16 (
17 { host, ... }:
18 {
19 nixos.host = host;
20 }
21 )
22 (
23 { host, user, ... }:
24 {
25 nixos.host-user = [
26 host
27 user
28 ];
29 }
30 )
31 (
32 {
33 OS,
34 user,
35 host,
36 ...
37 }:
38 {
39 nixos.os-user-host = [
40 OS
41 user
42 host
43 ];
44 }
45 )
46 (
47 { user, ... }:
48 {
49 nixos.user = user;
50 }
51 )
52 (
53 { user, ... }@ctx:
54 if canTake.exactly ctx ({ user }: user) then
55 {
56 nixos.user-only = user;
57 }
58 else
59 { nixos.user-only = false; }
60 )
61 (
62 { home, ... }:
63 {
64 nixos.home = home;
65 }
66 )
67 (_any: {
68 nixos.any = 10;
69 })
70 ];
71 };
72
73 flake.tests."test functor applied with empty attrs" = {
74 expr = (aspect-example { });
75 expected = {
76 includes = [
77 { nixos.any = 10; }
78 ];
79 };
80 };
81
82 flake.tests."test functor applied with host only" = {
83 expr = (
84 aspect-example {
85 host = 2;
86 }
87 );
88 expected = {
89 includes = [
90 { nixos.host = 2; } # host
91 { nixos.any = 10; }
92 ];
93 };
94 };
95
96 flake.tests."test functor applied with home only" = {
97 expr = (
98 aspect-example {
99 home = 2;
100 }
101 );
102 expected = {
103 includes = [
104 { nixos.home = 2; } # home
105 { nixos.any = 10; }
106 ];
107 };
108 };
109
110 flake.tests."test functor applied with home and unknown" = {
111 expr = (
112 aspect-example {
113 home = 2;
114 unknown = 1;
115 }
116 );
117 expected = {
118 includes = [
119 { nixos.home = 2; }
120 { nixos.any = 10; }
121 ];
122 };
123 };
124
125 flake.tests."test functor applied with user only" = {
126 expr = (
127 aspect-example {
128 user = 2;
129 }
130 );
131 expected = {
132 includes = [
133 { nixos.user = 2; } # user
134 { nixos.user-only = 2; } # user-only
135 { nixos.any = 10; }
136 ];
137 };
138 };
139
140 flake.tests."test functor applied with user and host" = {
141 expr = (
142 aspect-example {
143 user = 2;
144 host = 1;
145 }
146 );
147 expected = {
148 includes = [
149 { nixos.host = 1; }
150 {
151 nixos.host-user = [
152 1
153 2
154 ];
155 }
156 { nixos.user = 2; }
157 { nixos.user-only = false; }
158 { nixos.any = 10; }
159 ];
160 };
161 };
162
163 flake.tests."test functor applied with host/user/OS" = {
164 expr = (
165 aspect-example {
166 OS = 0;
167 user = 2;
168 host = 1;
169 }
170 );
171 expected = {
172 includes = [
173 { nixos.host = 1; }
174 {
175 nixos.host-user = [
176 1
177 2
178 ];
179 }
180 {
181 nixos.os-user-host = [
182 0
183 2
184 1
185 ];
186 }
187 { nixos.user = 2; }
188 { nixos.user-only = false; }
189 { nixos.any = 10; }
190 ];
191 };
192 };
193
194in
195{
196 inherit flake;
197}