1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2024-11-17 19:21:04 +00:00

lib.types.attrTag: Provide declarations, definitions

This commit is contained in:
Robert Hensing 2024-01-29 08:54:02 +01:00
parent e090bb55f0
commit 4c7d990bad
2 changed files with 20 additions and 2 deletions

View file

@ -107,6 +107,7 @@ in
# assert lib.foldl' (a: b: builtins.trace b a) true (lib.attrNames config.docs); # assert lib.foldl' (a: b: builtins.trace b a) true (lib.attrNames config.docs);
assert config.docs."submodules.<name>.foo.bar".type == "signed integer"; assert config.docs."submodules.<name>.foo.bar".type == "signed integer";
assert config.docs."submodules.<name>.qux".type == "string"; assert config.docs."submodules.<name>.qux".type == "string";
assert lib.length config.docs."merged.<name>.extensible".declarations == 2;
true; true;
}; };
} }

View file

@ -628,7 +628,16 @@ rec {
(n: opt: (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 args.tags n}" (
assert opt._type == "option"; assert opt._type == "option";
opt opt // {
declarations = opt.declarations or (
let pos = builtins.unsafeGetAttrPos n args.tags;
in if pos == null then [] else [ pos.file ]
);
declarationPositions = opt.declarationPositions or (
let pos = builtins.unsafeGetAttrPos n args.tags;
in if pos == null then [] else [ pos ]
);
}
)) ))
args.tags; args.tags;
choicesStr = concatMapStringsSep ", " lib.strings.escapeNixIdentifier (attrNames tags); choicesStr = concatMapStringsSep ", " lib.strings.escapeNixIdentifier (attrNames tags);
@ -640,7 +649,10 @@ rec {
mapAttrs mapAttrs
(tagName: tagOption: { (tagName: tagOption: {
"${lib.showOption prefix}" = "${lib.showOption prefix}" =
tagOption // { loc = prefix ++ [ tagName ]; }; tagOption // {
loc = prefix ++ [ tagName ];
definitions = [];
};
}) })
tags; tags;
substSubModules = m: attrTagWith { tags = mapAttrs (n: opt: opt // { type = (opt.type or types.unspecified).substSubModules m; }) tags; }; substSubModules = m: attrTagWith { tags = mapAttrs (n: opt: opt // { type = (opt.type or types.unspecified).substSubModules m; }) tags; };
@ -685,6 +697,11 @@ rec {
# It is also returned though, but use of the attribute seems rare? # It is also returned though, but use of the attribute seems rare?
[tagName] [tagName]
[ (wrapOptionDecl a.tags.${tagName}) (wrapOptionDecl bOpt) ] [ (wrapOptionDecl a.tags.${tagName}) (wrapOptionDecl bOpt) ]
// {
# mergeOptionDecls is not idempotent in these attrs:
declarations = a.tags.${tagName}.declarations ++ bOpt.declarations;
declarationPositions = a.tags.${tagName}.declarations ++ bOpt.declarations;
}
) )
(builtins.intersectAttrs a.tags b.tags); (builtins.intersectAttrs a.tags b.tags);
}; };