···11+{ lib, targetLib, ... }:
22+{
33+ # This test verifies that we can define aspects inside
44+ # an scope and then merge them in another scope.
55+ #
66+ # This is important for Den social aspects, since people will
77+ # try to merge aspects from different sources, local, and remote flakes.
88+ flake.tests."test-assign-aspects-on-scopes" =
99+ let
1010+ flake-aspects-lib = import targetLib lib;
1111+1212+ first = lib.evalModules {
1313+ modules = [
1414+ # each scope creates a new <name>.aspects tree.
1515+ (flake-aspects-lib.new-scope "foo")
1616+ (flake-aspects-lib.new-scope "bar")
1717+ (flake-aspects-lib.new-scope "baz")
1818+ # create a._.b._.c aspect on each namespace
1919+ # we will be trying to merge them for this test.
2020+ {
2121+ foo.aspects.a._.b._.c.nixos.x = [ "foo" ];
2222+ }
2323+ {
2424+ bar.aspects.a._.b._.c.nixos.x = [ "bar" ];
2525+ }
2626+ {
2727+ baz.aspects.a._.b._.c.nixos.x = [ "baz" ];
2828+ }
2929+ (
3030+ { config, ... }:
3131+ {
3232+ bar = config.foo; # bar merges all of foo
3333+ }
3434+ )
3535+ (
3636+ { config, ... }:
3737+ {
3838+ baz = config.bar; # baz merges all of baz
3939+ }
4040+ )
4141+ ];
4242+ };
4343+4444+ second = lib.evalModules {
4545+ modules = [
4646+ # We evaluate the abc nixos module from baz
4747+ first.config.baz.aspects.a._.b._.c.modules.nixos
4848+ # create the options to merge all different values
4949+ { options.x = lib.mkOption { type = lib.types.listOf lib.types.str; }; }
5050+ ];
5151+ };
5252+5353+ expr = second.config.x;
5454+ expected = [
5555+ "foo"
5656+ "bar"
5757+ "baz"
5858+ ];
5959+ in
6060+ {
6161+ inherit expected expr;
6262+ };
6363+6464+}