lib/introspect: seperate headType from nullable
This commit is contained in:
@@ -45,17 +45,28 @@ let
|
||||
lib.mapAttrs (
|
||||
_: opt:
|
||||
let
|
||||
headType =
|
||||
let
|
||||
typeName = opt.type.name or null;
|
||||
in
|
||||
if typeName == "nullOr" then opt.type.nestedTypes.name or null else typeName;
|
||||
nullable = opt.type.name or null == "nullOr";
|
||||
|
||||
definitionInfo = {
|
||||
__this = {
|
||||
prio = opt.highestPrio or null;
|
||||
files = opt.files or [ ];
|
||||
type = opt.type.name or null;
|
||||
inherit headType nullable;
|
||||
total = opt.type.name or null == "submodule";
|
||||
};
|
||||
};
|
||||
|
||||
# TODO: respect freeformType
|
||||
submodulePrios = getPrios { options = filterOptions opt.valueMeta.configuration.options; };
|
||||
submodulePrios = getPrios {
|
||||
options =
|
||||
filterOptions
|
||||
opt.valueMeta.configuration.options or (throw "Please use a newer nixpkgs version >=25.11");
|
||||
};
|
||||
|
||||
/**
|
||||
Maps attrsOf and lazyAttrsOf
|
||||
|
||||
@@ -13,21 +13,48 @@ let
|
||||
};
|
||||
in
|
||||
evaledConfig;
|
||||
|
||||
# Return only used attributes, for test stability
|
||||
stableView =
|
||||
set:
|
||||
let
|
||||
mapProps =
|
||||
attrs:
|
||||
lib.intersectAttrs {
|
||||
files = null;
|
||||
prio = null;
|
||||
total = null;
|
||||
} attrs;
|
||||
in
|
||||
lib.mapAttrs (
|
||||
name: value:
|
||||
if name == "__this" then
|
||||
mapProps value
|
||||
else if name == "__list" then
|
||||
[ ]
|
||||
else if lib.isAttrs value then
|
||||
stableView value
|
||||
else
|
||||
value
|
||||
) set;
|
||||
|
||||
in
|
||||
{
|
||||
test_default = {
|
||||
expr = slib.getPrios {
|
||||
options =
|
||||
(eval [
|
||||
{
|
||||
options.foo.bar = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
description = "Test Description";
|
||||
default = true;
|
||||
};
|
||||
}
|
||||
]).options;
|
||||
};
|
||||
expr = stableView (
|
||||
slib.getPrios {
|
||||
options =
|
||||
(eval [
|
||||
{
|
||||
options.foo.bar = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
description = "Test Description";
|
||||
default = true;
|
||||
};
|
||||
}
|
||||
]).options;
|
||||
}
|
||||
);
|
||||
expected = {
|
||||
foo = {
|
||||
bar = {
|
||||
@@ -35,23 +62,24 @@ in
|
||||
files = [ "<unknown-file>" ];
|
||||
prio = 1500;
|
||||
total = false;
|
||||
type = "bool";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
test_no_default = {
|
||||
expr = slib.getPrios {
|
||||
options =
|
||||
(eval [
|
||||
{
|
||||
options.foo.bar = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
};
|
||||
}
|
||||
]).options;
|
||||
};
|
||||
expr = stableView (
|
||||
slib.getPrios {
|
||||
options =
|
||||
(eval [
|
||||
{
|
||||
options.foo.bar = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
};
|
||||
}
|
||||
]).options;
|
||||
}
|
||||
);
|
||||
expected = {
|
||||
foo = {
|
||||
bar = {
|
||||
@@ -59,7 +87,6 @@ in
|
||||
files = [ ];
|
||||
prio = 9999;
|
||||
total = false;
|
||||
type = "bool";
|
||||
};
|
||||
};
|
||||
};
|
||||
@@ -67,36 +94,36 @@ in
|
||||
};
|
||||
|
||||
test_submodule = {
|
||||
expr = slib.getPrios {
|
||||
options =
|
||||
(eval [
|
||||
{
|
||||
options.foo = lib.mkOption {
|
||||
type = lib.types.submodule {
|
||||
options = {
|
||||
bar = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
expr = stableView (
|
||||
slib.getPrios {
|
||||
options =
|
||||
(eval [
|
||||
{
|
||||
options.foo = lib.mkOption {
|
||||
type = lib.types.submodule {
|
||||
options = {
|
||||
bar = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
]).options;
|
||||
};
|
||||
}
|
||||
]).options;
|
||||
}
|
||||
);
|
||||
expected = {
|
||||
foo = {
|
||||
__this = {
|
||||
files = [ ];
|
||||
prio = 9999;
|
||||
total = true;
|
||||
type = "submodule";
|
||||
};
|
||||
bar = {
|
||||
__this = {
|
||||
files = [ ];
|
||||
prio = 9999;
|
||||
total = false;
|
||||
type = "bool";
|
||||
};
|
||||
};
|
||||
};
|
||||
@@ -142,9 +169,11 @@ in
|
||||
in
|
||||
{
|
||||
inherit evaluated;
|
||||
expr = slib.getPrios {
|
||||
options = evaluated.options;
|
||||
};
|
||||
expr = stableView (
|
||||
slib.getPrios {
|
||||
options = evaluated.options;
|
||||
}
|
||||
);
|
||||
expected = {
|
||||
foo = {
|
||||
__this = {
|
||||
@@ -154,14 +183,12 @@ in
|
||||
];
|
||||
prio = 100;
|
||||
total = true;
|
||||
type = "submodule";
|
||||
};
|
||||
default = {
|
||||
__this = {
|
||||
files = [ "default" ];
|
||||
prio = 1000;
|
||||
total = false;
|
||||
type = "bool";
|
||||
};
|
||||
};
|
||||
normal = {
|
||||
@@ -169,7 +196,6 @@ in
|
||||
files = [ "normal" ];
|
||||
prio = 100;
|
||||
total = false;
|
||||
type = "bool";
|
||||
};
|
||||
};
|
||||
optionDefault = {
|
||||
@@ -177,7 +203,6 @@ in
|
||||
files = [ "option" ];
|
||||
prio = 1500;
|
||||
total = false;
|
||||
type = "bool";
|
||||
};
|
||||
};
|
||||
unset = {
|
||||
@@ -185,7 +210,6 @@ in
|
||||
files = [ ];
|
||||
prio = 9999;
|
||||
total = false;
|
||||
type = "bool";
|
||||
};
|
||||
};
|
||||
};
|
||||
@@ -217,23 +241,23 @@ in
|
||||
in
|
||||
{
|
||||
inherit evaluated;
|
||||
expr = slib.getPrios {
|
||||
options = evaluated.options;
|
||||
};
|
||||
expr = stableView (
|
||||
slib.getPrios {
|
||||
options = evaluated.options;
|
||||
}
|
||||
);
|
||||
expected = {
|
||||
foo = {
|
||||
__this = {
|
||||
files = [ "<unknown-file>" ];
|
||||
prio = 100;
|
||||
total = true;
|
||||
type = "submodule";
|
||||
};
|
||||
bar = {
|
||||
__this = {
|
||||
files = [ "<unknown-file>" ];
|
||||
prio = 100;
|
||||
total = false;
|
||||
type = "bool";
|
||||
};
|
||||
};
|
||||
};
|
||||
@@ -302,14 +326,13 @@ in
|
||||
];
|
||||
in
|
||||
{
|
||||
expr = slib.getPrios { options = evaluated.options; };
|
||||
expr = stableView (slib.getPrios { options = evaluated.options; });
|
||||
expected = {
|
||||
foo = {
|
||||
__this = {
|
||||
files = [ "<unknown-file>" ];
|
||||
prio = 100;
|
||||
total = false;
|
||||
type = "attrsOf";
|
||||
};
|
||||
nested = {
|
||||
bar = {
|
||||
@@ -317,7 +340,6 @@ in
|
||||
files = [ "<unknown-file>" ];
|
||||
prio = 100;
|
||||
total = false;
|
||||
type = "int";
|
||||
};
|
||||
};
|
||||
};
|
||||
@@ -327,7 +349,6 @@ in
|
||||
files = [ "<unknown-file>" ];
|
||||
prio = 50;
|
||||
total = false;
|
||||
type = "int";
|
||||
};
|
||||
};
|
||||
};
|
||||
@@ -371,14 +392,13 @@ in
|
||||
in
|
||||
{
|
||||
inherit evaluated;
|
||||
expr = slib.getPrios { options = evaluated.options; };
|
||||
expr = stableView (slib.getPrios { options = evaluated.options; });
|
||||
expected = {
|
||||
foo = {
|
||||
__this = {
|
||||
files = [ "<unknown-file>" ];
|
||||
prio = 100;
|
||||
total = false;
|
||||
type = "attrsOf";
|
||||
};
|
||||
a = {
|
||||
b = {
|
||||
@@ -387,7 +407,6 @@ in
|
||||
files = [ "<unknown-file>" ];
|
||||
prio = 100;
|
||||
total = false;
|
||||
type = "int";
|
||||
};
|
||||
};
|
||||
};
|
||||
@@ -397,7 +416,6 @@ in
|
||||
files = [ "<unknown-file>" ];
|
||||
prio = 100;
|
||||
total = false;
|
||||
type = "int";
|
||||
};
|
||||
};
|
||||
};
|
||||
@@ -409,7 +427,6 @@ in
|
||||
files = [ "<unknown-file>" ];
|
||||
prio = 100;
|
||||
total = false;
|
||||
type = "int";
|
||||
};
|
||||
};
|
||||
};
|
||||
@@ -419,7 +436,6 @@ in
|
||||
files = [ "<unknown-file>" ];
|
||||
prio = 100;
|
||||
total = false;
|
||||
type = "int";
|
||||
};
|
||||
};
|
||||
};
|
||||
@@ -468,7 +484,7 @@ in
|
||||
in
|
||||
{
|
||||
inherit evaluated;
|
||||
expr = slib.getPrios { options = evaluated.options; };
|
||||
expr = stableView (slib.getPrios { options = evaluated.options; });
|
||||
expected = {
|
||||
machines = {
|
||||
__this = {
|
||||
@@ -478,7 +494,6 @@ in
|
||||
];
|
||||
prio = 100;
|
||||
total = false;
|
||||
type = "attrsOf";
|
||||
};
|
||||
jon = {
|
||||
fludl = {
|
||||
@@ -486,7 +501,6 @@ in
|
||||
files = [ "<unknown-file>" ];
|
||||
prio = 1500;
|
||||
total = true;
|
||||
type = "submodule";
|
||||
};
|
||||
};
|
||||
prim = {
|
||||
@@ -494,7 +508,6 @@ in
|
||||
files = [ "inventory.json" ];
|
||||
prio = 100;
|
||||
total = false;
|
||||
type = "int";
|
||||
};
|
||||
};
|
||||
settings = {
|
||||
@@ -502,7 +515,6 @@ in
|
||||
files = [ "<unknown-file>" ];
|
||||
prio = 1500;
|
||||
total = true;
|
||||
type = "submodule";
|
||||
};
|
||||
};
|
||||
};
|
||||
@@ -554,63 +566,10 @@ in
|
||||
in
|
||||
{
|
||||
inherit evaluated;
|
||||
expr = slib.getPrios { options = evaluated.options; };
|
||||
expr = stableView (slib.getPrios { options = evaluated.options; });
|
||||
expected = {
|
||||
machines = {
|
||||
__list = [
|
||||
{
|
||||
fludl = {
|
||||
__this = {
|
||||
files = [ "<unknown-file>" ];
|
||||
prio = 1500;
|
||||
total = true;
|
||||
type = "submodule";
|
||||
};
|
||||
};
|
||||
prim = {
|
||||
__this = {
|
||||
files = [ "clan.nix" ];
|
||||
prio = 100;
|
||||
total = false;
|
||||
type = "int";
|
||||
};
|
||||
};
|
||||
settings = {
|
||||
__this = {
|
||||
files = [ "<unknown-file>" ];
|
||||
prio = 1500;
|
||||
total = true;
|
||||
type = "submodule";
|
||||
};
|
||||
};
|
||||
}
|
||||
{
|
||||
fludl = {
|
||||
__this = {
|
||||
files = [ "<unknown-file>" ];
|
||||
prio = 1500;
|
||||
total = true;
|
||||
type = "submodule";
|
||||
};
|
||||
};
|
||||
prim = {
|
||||
__this = {
|
||||
files = [ "inventory.json" ];
|
||||
prio = 100;
|
||||
total = false;
|
||||
type = "int";
|
||||
};
|
||||
};
|
||||
settings = {
|
||||
__this = {
|
||||
files = [ "<unknown-file>" ];
|
||||
prio = 1500;
|
||||
total = true;
|
||||
type = "submodule";
|
||||
};
|
||||
};
|
||||
}
|
||||
];
|
||||
__list = [ ];
|
||||
__this = {
|
||||
files = [
|
||||
"clan.nix"
|
||||
@@ -618,7 +577,6 @@ in
|
||||
];
|
||||
prio = 100;
|
||||
total = false;
|
||||
type = "listOf";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user