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