From 47e4a18d018be9efaa93a199e24fbeedc80f14be Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Thu, 4 Apr 2024 10:29:56 +0200 Subject: [PATCH] types.attrTagWith: remove Keep it simple for now. --- lib/tests/modules.sh | 2 +- lib/types.nix | 28 ++++++++++++++++++---------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh index f5f7e907d277..750b1d025e02 100755 --- a/lib/tests/modules.sh +++ b/lib/tests/modules.sh @@ -113,7 +113,7 @@ checkConfigError 'A definition for option .intStrings\.mergeError. is not of typ checkConfigError 'A definition for option .intStrings\.badTagError. is not of type .attribute-tagged union' config.intStrings.badTagError ./types-attrTag.nix checkConfigError 'A definition for option .intStrings\.badTagTypeError\.left. is not of type .signed integer.' config.intStrings.badTagTypeError.left ./types-attrTag.nix checkConfigError 'A definition for option .nested\.right\.left. is not of type .signed integer.' config.nested.right.left ./types-attrTag.nix -checkConfigError 'In attrTag/attrTagWith, each tag value must be an option, but tag int was a bare type, not wrapped in mkOption.' config.opt.int ./types-attrTag-wrong-decl.nix +checkConfigError 'In attrTag, each tag value must be an option, but tag int was a bare type, not wrapped in mkOption.' config.opt.int ./types-attrTag-wrong-decl.nix # types.pathInStore checkConfigOutput '".*/store/0lz9p8xhf89kb1c1kk6jxrzskaiygnlh-bash-5.2-p15.drv"' config.pathInStore.ok1 ./types.nix diff --git a/lib/types.nix b/lib/types.nix index a77a8ef11244..2e44dd5472ee 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -620,16 +620,15 @@ rec { nestedTypes.elemType = elemType; }; - attrTag = tags: attrTagWith { inherit tags; }; - - attrTagWith = args@{ tags }: + attrTag = tags: + let tags_ = tags; in let tags = mapAttrs (n: opt: - builtins.addErrorContext "while checking that attrTag tag ${lib.strings.escapeNixIdentifier n} is an option with a type${inAttrPosSuffix args.tags n}" ( + builtins.addErrorContext "while checking that attrTag tag ${lib.strings.escapeNixIdentifier n} is an option with a type${inAttrPosSuffix tags_ n}" ( throwIf (opt._type or null != "option") - "In attrTag/attrTagWith, each tag value must be an option, but tag ${lib.strings.escapeNixIdentifier n} ${ + "In attrTag, each tag value must be an option, but tag ${lib.strings.escapeNixIdentifier n} ${ if opt?_type then if opt._type == "option-type" then "was a bare type, not wrapped in mkOption." @@ -637,16 +636,16 @@ rec { else "was not."}" opt // { declarations = opt.declarations or ( - let pos = builtins.unsafeGetAttrPos n args.tags; + let pos = builtins.unsafeGetAttrPos n tags_; in if pos == null then [] else [ pos.file ] ); declarationPositions = opt.declarationPositions or ( - let pos = builtins.unsafeGetAttrPos n args.tags; + let pos = builtins.unsafeGetAttrPos n tags_; in if pos == null then [] else [ pos ] ); } )) - args.tags; + tags_; choicesStr = concatMapStringsSep ", " lib.strings.escapeNixIdentifier (attrNames tags); in mkOptionType { @@ -663,7 +662,15 @@ rec { }; }) tags; - substSubModules = m: attrTagWith { tags = mapAttrs (n: opt: opt // { type = (opt.type or types.unspecified).substSubModules m; }) tags; }; + substSubModules = m: + attrTag + (mapAttrs + (n: opt: + opt // { + type = (opt.type or types.unspecified).substSubModules m; + } + ) + tags); check = v: isAttrs v && length (attrNames v) == 1 && tags?${head (attrNames v)}; merge = loc: defs: let @@ -687,7 +694,8 @@ rec { } else throw "The option `${showOption loc}` is defined as ${lib.strings.escapeNixIdentifier choice}, but ${lib.strings.escapeNixIdentifier choice} is not among the valid choices (${choicesStr}). Value ${choice} was defined in ${showFiles (getFiles defs)}."; nestedTypes = tags; - functor = (defaultFunctor "attrTagWith") // { + functor = defaultFunctor "attrTag" // { + type = { tags, ... }: types.attrTag tags; payload = { inherit tags; }; binOp = let