From a9c08fb6a542137ea327659d95c4ea4a5bc5d5be Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Sun, 29 Sep 2024 15:10:50 +0100 Subject: [PATCH] lib/types: make `strLua` coerce strings to rawLua Instead of relying on option `apply` functions to coerce the value to rawLua, this can be done in the type's merge function. Inspired by `types.coercedTo` in nixpkgs. --- lib/types.nix | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/types.nix b/lib/types.nix index de89141c..150a6604 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -8,14 +8,21 @@ let mkNullOrOption ; - strLikeType = + mkStrLuaType = description: lib.mkOptionType { - name = "str"; + name = "strLua"; inherit description; descriptionClass = "noun"; check = v: lib.isString v || isRawType v; - merge = lib.options.mergeEqualOption; + merge = + loc: defs: + lib.pipe defs [ + # Coerce strings to rawLua + # TODO: consider deprecating this behaviour + (lib.map (def: def // { value = lib.nixvim.mkRaw def.value; })) + (lib.options.mergeEqualOption loc) + ]; }; isRawType = v: v ? __raw && lib.isString v.__raw; in @@ -107,8 +114,8 @@ rec { }; }; - strLua = strLikeType "lua code string"; - strLuaFn = strLikeType "lua function string"; + strLua = mkStrLuaType "lua code string"; + strLuaFn = mkStrLuaType "lua function string"; # When building the documentation `either` is extended to return the nestedType's sub-options # This type can be used to avoid infinite recursion when evaluating the docs