diff options
author | Robert Hensing <robert@roberthensing.nl> | 2024-04-04 10:29:56 +0200 |
---|---|---|
committer | Robert Hensing <robert@roberthensing.nl> | 2024-04-04 12:00:54 +0200 |
commit | 47e4a18d018be9efaa93a199e24fbeedc80f14be (patch) | |
tree | b28f1ba748adbcaed1e509701a691ce1bea4ff30 /lib/types.nix | |
parent | 1465777b63d38988d5ecd81683d2975321e59d1a (diff) |
types.attrTagWith: remove
Keep it simple for now.
Diffstat (limited to 'lib/types.nix')
-rw-r--r-- | lib/types.nix | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/lib/types.nix b/lib/types.nix index a77a8ef112440..2e44dd5472ee6 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 |