mirror of
https://github.com/nix-community/nixvim.git
synced 2025-07-04 14:24:29 +02:00
helpers: Allow to set raw lua code in more places (#837)
With this change a user should be able to set raw lua code in more places than before. The `mkStr` helper was _not_ changed as a large number of places in nixvim are using this helper to directly implement raw lua code. Also note that types of the form `oneOf [submodule <something else>` are not well rendered in the documentation, and should be avoided (this includes `listOf [submodule <something else>`, so the helpers should be avoided in this case)
This commit is contained in:
parent
2871dc94b4
commit
e0521dde87
1 changed files with 19 additions and 7 deletions
|
@ -119,7 +119,9 @@ with lib; rec {
|
|||
mkCompositeOption = desc: options:
|
||||
mkNullOrOption (types.submodule {inherit options;}) desc;
|
||||
|
||||
defaultNullOpts = rec {
|
||||
defaultNullOpts = let
|
||||
maybeRaw = t: lib.types.either t rawType;
|
||||
in rec {
|
||||
mkNullable = type: default: desc:
|
||||
mkNullOrOption type (
|
||||
let
|
||||
|
@ -134,21 +136,31 @@ with lib; rec {
|
|||
''
|
||||
);
|
||||
|
||||
mkNum = default: mkNullable lib.types.number (toString default);
|
||||
mkInt = default: mkNullable lib.types.int (toString default);
|
||||
# Note that this function is _not_ to be used with submodule elements, as it may obstruct the
|
||||
# documentation
|
||||
mkNullableWithRaw = type: mkNullable (maybeRaw type);
|
||||
|
||||
mkNum = default: mkNullable (maybeRaw lib.types.number) (toString default);
|
||||
mkInt = default: mkNullable (maybeRaw lib.types.int) (toString default);
|
||||
# Positive: >0
|
||||
mkPositiveInt = default: mkNullable lib.types.ints.positive (toString default);
|
||||
mkPositiveInt = default: mkNullable (maybeRaw lib.types.ints.positive) (toString default);
|
||||
# Unsigned: >=0
|
||||
mkUnsignedInt = default: mkNullable lib.types.ints.unsigned (toString default);
|
||||
mkUnsignedInt = default: mkNullable (maybeRaw lib.types.ints.unsigned) (toString default);
|
||||
mkBool = default:
|
||||
mkNullable lib.types.bool (
|
||||
mkNullable (maybeRaw lib.types.bool) (
|
||||
if default
|
||||
then "true"
|
||||
else "false"
|
||||
);
|
||||
mkStr = default: mkNullable lib.types.str ''${builtins.toString default}'';
|
||||
mkAttributeSet = default: mkNullable lib.types.attrs ''${default}'';
|
||||
mkEnum = enum: default: mkNullable (lib.types.enum enum) ''"${default}"'';
|
||||
# Note that this function is _not_ to be used with submodule elements, as it may obstruct the
|
||||
# documentation
|
||||
mkListOf = ty: default: mkNullable (lib.types.listOf (maybeRaw ty)) default;
|
||||
# Note that this function is _not_ to be used with submodule elements, as it may obstruct the
|
||||
# documentation
|
||||
mkAttrsOf = ty: default: mkNullable (lib.types.attrsOf (maybeRaw ty)) default;
|
||||
mkEnum = enum: default: mkNullable (maybeRaw (lib.types.enum enum)) ''"${default}"'';
|
||||
mkEnumFirstDefault = enum: mkEnum enum (head enum);
|
||||
mkBorder = default: name: desc:
|
||||
mkNullable
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue