move inline recursiveAttrs to lib.types

This commit is contained in:
Valentin Gagarin 2024-11-13 15:24:41 +01:00
parent 955409b71d
commit 4ec1cee08f
2 changed files with 10 additions and 9 deletions

View file

@ -128,6 +128,15 @@ rec {
); );
types = rec { types = rec {
# arbitrarily nested attribute set where the leaves are of type `type`
# NOTE: this works for anything but attribute sets!
recursiveAttrs = type: with lib.types;
# NOTE: due to how `either` works, the first match is significant,
# so if `type` happens to be an attrset, the typecheck will consider
# `type`, not `attrsOf`
attrsOf (either type (recursiveAttrs type));
# collection of unnamed items that can be added to item-wise, i.e. without wrapping the item in a list
collection = elemType: collection = elemType:
let let
unparenthesize = class: class == "noun"; unparenthesize = class: class == "noun";

View file

@ -9,19 +9,11 @@ in
imports = lib.nixFiles ./.; imports = lib.nixFiles ./.;
options.templates = options.templates =
let
# arbitrarily nested attribute set where the leaves are of type `type`
recursiveAttrs = type: with types;
# NOTE: due to how `either` works, the first match is significant,
# so if `type` happens to be an attrset, the typecheck will consider
# `type`, not `attrsOf`
attrsOf (either type (recursiveAttrs type));
in
mkOption { mkOption {
description = '' description = ''
Collection of named helper functions for conversion different structured representations which can be rendered to a string Collection of named helper functions for conversion different structured representations which can be rendered to a string
''; '';
type = recursiveAttrs (with types; functionTo (either str attrs)); type = with types; recursiveAttrs (functionTo (either str attrs));
}; };
options.files = mkOption { options.files = mkOption {