WIP: feat: Namespaced includes #3

Closed
austreelis wants to merge 6 commits from austreelis/feat/namespaced-includes into main AGit

6 commits

Author SHA1 Message Date
Austreelis 8288e21555
Apply namespace in load rather than lib.modules.normalize 2024-06-22 20:50:07 +02:00
Austreelis 4b9b9c3506
format code 2024-06-22 20:44:33 +02:00
Austreelis 5098f7789b
Add test checking mixed module/include keys 2024-06-22 20:43:27 +02:00
Austreelis feb9987300
Use include object syntax instead of shorthand 2024-06-22 20:43:24 +02:00
Austreelis 71bc768dc1
Code cleanup and readability 2024-06-22 20:40:02 +02:00
Austreelis a6ad4027a1
feat: namespaced includes
This commit adds some logic to the modules normalization process to
allow including modules under a user-defined namespace. It achieves it
by:
- flattening any attribute sets in `includes` that are non-empty nor
  contain any of a module's valid attributes (`lib.modules.VALID_KEYS`).
- Erroring out on dupplicate namespaces.
- Mapping namespaced includes do normal modules declaring an option
  `${namespace}` of the include as a submodule.

This allows specifying includes in a module like:
```
{
  includes.mynamespace0 = ./mymodule0.nix;
  includes.mynamespace1 = ./mymodule1.nix;
}
```

and is approximatively desugared by `lib.modules.normalize` into:
```
{
  includes = [
    { options.mynamespace0 = lib.submodule mymodule0.nix; }
    { options.mynamespace1 = lib.submodule mymodule1.nix; }
  ];
}
```

This was inspired by nixpkgs' `lib.modules.doRename`.
2024-06-22 20:39:08 +02:00