move inline recursiveAttrs to lib.types

This commit is contained in:
Valentin Gagarin 2024-11-13 15:24:41 +01:00 committed by Valentin Gagarin
parent cb8363ebb5
commit 6e3bd814f1
2 changed files with 10 additions and 9 deletions

View file

@ -128,6 +128,15 @@ 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:
let
unparenthesize = class: class == "noun";

View file

@ -9,19 +9,11 @@ in
imports = lib.nixFiles ./.;
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 {
description = ''
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 {