WIP: feat: Namespaced includes #3

Closed
austreelis wants to merge 6 commits from austreelis/feat/namespaced-includes into main AGit
Showing only changes of commit 4b9b9c3506 - Show all commits

View file

@ -205,52 +205,57 @@ in
let let
# Simple backtracking algorithm to generate all combinations of a list's # Simple backtracking algorithm to generate all combinations of a list's
# elements without ordering, in . # elements without ordering, in .
combinations = set: combinations =
set:
let let
n = builtins.length set; n = builtins.length set;
genIndices = combinations': genIndices =
combinations':
let let
prev = builtins.head combinations'; prev = builtins.head combinations';
k = builtins.length prev; k = builtins.length prev;
first = builtins.head prev; first = builtins.head prev;
next' = next' =
# Generate the next combination of length k # Generate the next combination of length k
if k > 0 && first+1 < n then [(first+1)] ++ (builtins.tail prev) if k > 0 && first + 1 < n then
[ (first + 1) ] ++ (builtins.tail prev)
# We have generated all combinations of length k, generate the first # We have generated all combinations of length k, generate the first
# (trivial) combination of length k+1 # (trivial) combination of length k+1
else builtins.genList (i: i) (k+1); else
builtins.genList (i: i) (k + 1);
next = builtins.deepSeq next' next'; next = builtins.deepSeq next' next';
in in
# Generate the very first (trivial) combination # Generate the very first (trivial) combination
if combinations' == [ ] then genIndices [ [ ] ] if combinations' == [ ] then
genIndices [ [ ] ]
# We have generated all combinations of length 0 to n, return # We have generated all combinations of length 0 to n, return
else if k >= n then combinations' else if k >= n then
combinations'
# Generate the next combination and continue # Generate the next combination and continue
else genIndices ([next] ++ combinations'); else
genIndices ([ next ] ++ combinations');
select = indices: builtins.map (builtins.elemAt set) indices; select = indices: builtins.map (builtins.elemAt set) indices;
in in
if set == [ ] then [ ] if set == [ ] then [ ] else builtins.map select (genIndices [ ]);
else builtins.map select (genIndices []);
keys = combinations (lib.modules.VALID_KEYS ++ lib.modules.VALID_INCLUDE_KEYS); keys = combinations (lib.modules.VALID_KEYS ++ lib.modules.VALID_INCLUDE_KEYS);
sets = sets = builtins.map (
builtins.map names:
(names: builtins.listToAttrs (
builtins.listToAttrs builtins.map (name: {
(builtins.map (name: { value = null; inherit name; }) names) value = null;
inherit name;
}) names
) )
keys; ) keys;
validated = validated = builtins.map (set: {
builtins.map inherit set;
(set: { include = lib.modules.validate.include set;
inherit set; module = lib.modules.validate.keys set;
include = lib.modules.validate.include set; }) sets;
module = lib.modules.validate.keys set; bothValid = { include, module, ... }: include && module;
})
sets;
bothValid = {include, module, ...}: include && module;
in in
! builtins.any bothValid validated; !builtins.any bothValid validated;
}; };
"normalize" = { "normalize" = {