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{ lib, targetLib, ... }:
2{
3 # This test verifies that we can define aspects inside
4 # an scope and then merge them in another scope.
5 #
6 # This is important for Den social aspects, since people will
7 # try to merge aspects from different sources, local, and remote flakes.
8 flake.tests."test-assign-aspects-on-scopes" =
9 let
10 flake-aspects-lib = import targetLib lib;
11
12 first = lib.evalModules {
13 modules = [
14 # each scope creates a new <name>.aspects tree.
15 (flake-aspects-lib.new-scope "foo")
16 (flake-aspects-lib.new-scope "bar")
17 (flake-aspects-lib.new-scope "baz")
18 # create a._.b._.c aspect on each namespace
19 # we will be trying to merge them for this test.
20 {
21 foo.aspects.a._.b._.c.nixos.x = [ "foo" ];
22 }
23 {
24 bar.aspects.a._.b._.c.nixos.x = [ "bar" ];
25 }
26 {
27 baz.aspects.a._.b._.c.nixos.x = [ "baz" ];
28 }
29 (
30 { config, ... }:
31 {
32 bar = config.foo; # bar merges all of foo
33 }
34 )
35 (
36 { config, ... }:
37 {
38 baz = config.bar; # baz merges all of baz
39 }
40 )
41 ];
42 };
43
44 second = lib.evalModules {
45 modules = [
46 # We evaluate the abc nixos module from baz
47 first.config.baz.aspects.a._.b._.c.modules.nixos
48 # create the options to merge all different values
49 { options.x = lib.mkOption { type = lib.types.listOf lib.types.str; }; }
50 ];
51 };
52
53 # Sort and dedupe for deterministic comparison - merged modules may
54 # produce duplicates and order is not guaranteed across merges.
55 expr = lib.sort (a: b: a < b) (lib.unique second.config.x);
56 expected = [
57 "bar"
58 "baz"
59 "foo"
60 ];
61 in
62 {
63 inherit expected expr;
64 };
65
66}