lib/lua: support nixpkg's "lua-inline" type

See #1935
This commit is contained in:
Matt Sturgeon 2024-08-11 21:17:45 +01:00
parent dbf6f7bc99
commit 4eb2ad7db7
No known key found for this signature in database
GPG key ID: 4F91844CED1A8299
3 changed files with 24 additions and 1 deletions

View file

@ -32,6 +32,13 @@ rec {
# and contain only letters, digits, and underscores.
isIdentifier = s: !(isKeyword s) && (builtins.match "[A-Za-z_][0-9A-Za-z_]*" s) == [ ];
# Alias for nixpkgs lib's `mkLuaInline`,
# but can also convert rawLua to lua-inline
mkInline = v: lib.generators.mkLuaInline (v.__raw or v);
# Whether the value is a lua-inline type
isInline = v: v._type or null == "lua-inline";
# toLua' with default options, aliased as toLuaObject at the top-level
toLua = toLua' { };
@ -141,6 +148,8 @@ rec {
value
else if allowRawValues && value ? __raw then
value
else if isInline value then
value
else if isDerivation value then
value
else if isList value then
@ -227,8 +236,11 @@ rec {
v.__pretty v.val
# apply raw values if allowed
else if allowRawValues && v ? __raw then
# TODO: apply indentation to multiline raw values
# TODO: deprecate in favour of inline-lua
v.__raw
else if isInline v then
# TODO: apply indentation to multiline raw values?
"(${v.expr})"
else
"{"
+ introSpace