Skip to content

Commit

Permalink
Change settings schemas to line up with frontend better
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasjm committed Sep 24, 2024
1 parent ecad21d commit 63d5744
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
18 changes: 9 additions & 9 deletions modules/base/convert-type.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@

let
convertType = target: type:
if (type.name == "str") then "string"
else if (type.name == "anything") then "any"
else if (type.name == "bool") then "boolean"
if (type.name == "str") then { type = "string"; }
else if (type.name == "anything") then { type = "any"; }
else if (type.name == "bool") then { type = "boolean"; }
else if (type.name == "attrs") then {
tag = "attrs";
type = "attrs";
}
else if (type.name == "listOf") then {
tag = "list";
value = convertType target type.nestedTypes.elemType;
type = "list";
listType = convertType target type.nestedTypes.elemType;
}
else if (type.name == "enum") then {
tag = "enum";
type = "enum";
values = type.functor.payload;
}
else if (type.name == "either") then {
tag = "either";
type = "either";
left = convertType target type.nestedTypes.left;
right = convertType target type.nestedTypes.right;
}
else if (type.name == "submodule") then {
tag = "submodule";
type = "submodule";
keys = lib.mapAttrsRecursiveCond
(x: !(x ? _type))
(path: value: convertType target value.type)
Expand Down
5 changes: 3 additions & 2 deletions modules/base/nixos-options-to-settings-schema.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ let

convert = v: let
defaultItem = { type = { name = "unknown"; }; };
loc = lib.drop componentsToDrop v.loc;
in
{
target = v.name;
type = convertType v.name (lib.attrByPath (lib.drop componentsToDrop v.loc) defaultItem options).type;
loc = v.loc;
inherit loc;
}
// convertType v.name (lib.attrByPath loc defaultItem options).type
// lib.optionalAttrs (lib.hasAttr "default" v) { defaultValue = convertDefaultValue v.default; }
// lib.optionalAttrs (lib.hasAttr "description" v && builtins.typeOf v.description == "string") { inherit (v) description; }
// lib.optionalAttrs (lib.hasAttr "visible" v && v.visible == false) { hidden = true; }
Expand Down

0 comments on commit 63d5744

Please sign in to comment.