From 555035ef798183ce384078c20cd7d3383541fdfd Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Mon, 8 Jul 2024 10:29:31 +0100 Subject: [PATCH] lib: add `types.flagInt` + `defaultNullOpts.mkIntFlag` Either `0` or `1`, but can be coerced from a boolean definition to support legacy definitions. When coerced, a warning is printed --- lib/options.nix | 2 ++ lib/types.nix | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/options.nix b/lib/options.nix index 43eaaf60..47e60ed8 100644 --- a/lib/options.nix +++ b/lib/options.nix @@ -187,6 +187,8 @@ rec { # Unsigned: >=0 mkUnsignedInt' = args: mkNullableWithRaw' (args // { type = types.ints.unsigned; }); mkUnsignedInt = pluginDefault: description: mkUnsignedInt' { inherit pluginDefault description; }; + mkFlagInt = pluginDefault: description: mkFlagInt' { inherit pluginDefault description; }; + mkFlagInt' = args: mkNullableWithRaw' (args // { type = types.intFlag; }); mkBool' = args: mkNullableWithRaw' (args // { type = types.bool; }); mkBool = pluginDefault: description: mkBool' { inherit pluginDefault description; }; mkStr' = args: mkNullableWithRaw' (args // { type = types.str; }); diff --git a/lib/types.nix b/lib/types.nix index 4f256e2f..55f3b13d 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -1,8 +1,12 @@ # Custom types to be included in `lib.types` -{ lib, helpers }: +{ lib }: let inherit (lib) types; - inherit (lib.nixvim) mkNullOrStr mkNullOrOption; + inherit (lib.nixvim) + deprecation + mkNullOrStr + mkNullOrOption + ; strLikeType = description: @@ -30,6 +34,15 @@ rec { maybeRaw = type: types.either type rawLua; + # Describes an boolean-like integer flag that is either 0 or 1 + # Has legacy support for boolean definitions, added 2024-09-08 + intFlag = + with types; + deprecation.transitionType bool (v: if v then 1 else 0) (enum [ + 0 + 1 + ]); + border = with types; oneOf [