From 27a0dd435dd3563f4cf9d788601fadfce8c59db6 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Thu, 12 Sep 2024 13:05:21 +0100 Subject: [PATCH] lib/types: simplify `eitherRecursive` by defining it only once --- docs/default.nix | 2 -- lib/extend-lib.nix | 2 +- lib/types.nix | 11 +++++++++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/docs/default.nix b/docs/default.nix index 2c6e4343..c94b6f9b 100644 --- a/docs/default.nix +++ b/docs/default.nix @@ -13,8 +13,6 @@ let // { getSubOptions = prefix: (t1.getSubOptions prefix) // (t2.getSubOptions prefix); }; - - eitherRecursive = t1: t2: (final.types.either t1 t2) // { getSubOptions = _: { }; }; }; } ); diff --git a/lib/extend-lib.nix b/lib/extend-lib.nix index 960cc0c4..2168085e 100644 --- a/lib/extend-lib.nix +++ b/lib/extend-lib.nix @@ -13,6 +13,6 @@ lib.extend ( maintainers = prev.maintainers // import ./maintainers.nix; # Merge in our custom types - types = call ./types.nix { } // prev.types; + types = prev.types // call ./types.nix { }; } ) diff --git a/lib/types.nix b/lib/types.nix index 55f3b13d..a7d57f08 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -95,8 +95,15 @@ rec { strLua = strLikeType "lua code string"; strLuaFn = strLikeType "lua function string"; - # Overridden when building the documentation - eitherRecursive = types.either; + # 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 + # TODO: consider deprecating this in favor of using `config.isDocs` in option declarations + eitherRecursive = + t1: t2: + types.either t1 t2 + // { + getSubOptions = _: { }; + }; listOfLen = elemType: len: