-
-
Notifications
You must be signed in to change notification settings - Fork 326
lib/lua-types: init #3213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
lib/lua-types: init #3213
Conversation
An initial set of option types for representing values serialisable into lua.
`defaultNullOpts` is generally used for representing lua-options. We should probably a) rename it something like `luaOptions` and switch out the primitive types to use the new `lua-types`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM overall.
I have a question about your (ab)use of laziness. (I'm not saying 'abuse' in a negative way here).
Why not relying on lib.fix
? Is this approach (importing it back in and changing it in place) preferable? Would lib.fix
(or rec
) work at all?
anything = types.either lua-types.primitive (lua-types.tableOf lua-types.anything) // { | ||
description = "lua value"; | ||
descriptionClass = "noun"; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sure you thought about priorities, but I think adding parentheses would greatly help with readability.
I assume you mean the self-referencing recursive As far as recursive laziness goes, both approaches are exactly the same. No matter how you write it, all self-referencing values do the same thing... I originally wrote it with "local" recursion using lib.fix (self: types.oneOf [
# ...
(tableOf self)
])
// {
description = "lua value";
# ...
} Then I realised that was unnecessary; we don't need |
Ok this makes sense. I was wondering if there was any fundamental difference. |
The types in
lua-types
are inspired bypkgs.formats
, allowing for a more appropriate option type thantypes.anything
.The intention is that we will replace usage of
types.anything
in 90% of cases treewide withlua-types.anything
(see #3208). Currently there are ~270 instances ofanything
treewide.All types in
lua-types
support inline-lua and raw-lua.lua-types.tableOf
will also serve as a good place to implement merging lists defs and attrs defs into a mixed table, at some point in the future. Ideally we can upstream something similar to nixpkgs too. Again, see #3208 and also NixOS/nixpkgs@master...MattSturgeon:nixpkgs:table.TODO
types.rawLua
tolua-types
lua-types.anything
inmkNvimPkugin
'ssettings
optionlua-types
indefaultNullOpts
(?)