diff options
author | Robert Hensing <robert@roberthensing.nl> | 2024-04-04 12:54:23 +0200 |
---|---|---|
committer | Robert Hensing <robert@roberthensing.nl> | 2024-05-18 17:50:05 +0200 |
commit | be91302d7e66b589439becb2b33fc651d4abcb44 (patch) | |
tree | 635a93b4933334b93ae52ff397cf5f5c285dde37 /lib | |
parent | 4c7877b3e433cc4c919b5aea79a046ef936f4de3 (diff) |
lib.types.attrTag: Fix declarationPositions after merge
Diffstat (limited to 'lib')
-rw-r--r-- | lib/tests/modules/types-attrTag.nix | 20 | ||||
-rw-r--r-- | lib/types.nix | 2 |
2 files changed, 18 insertions, 4 deletions
diff --git a/lib/tests/modules/types-attrTag.nix b/lib/tests/modules/types-attrTag.nix index ae676e3471369..b2e5158bb44b6 100644 --- a/lib/tests/modules/types-attrTag.nix +++ b/lib/tests/modules/types-attrTag.nix @@ -1,7 +1,8 @@ -{ lib, config, ... }: +{ lib, config, options, ... }: let inherit (lib) mkOption types; forceDeep = x: builtins.deepSeq x x; + mergedSubOption = (options.merged.type.getSubOptions options.merged.loc).extensible."merged.<name>"; in { options = { @@ -98,7 +99,7 @@ in merged.positive.yay = 100; merged.extensi-foo.extensible = "foo"; merged.extensi-bar.extensible = "bar"; - okChecks = + okChecks = builtins.addErrorContext "while evaluating the assertions" ( assert config.intStrings.hello == { right = "hello world"; }; assert config.intStrings.numberOne == { left = 1; }; assert config.merged.negative == { nay = false; }; @@ -115,7 +116,20 @@ in assert config.docs."submodules.<name>.qux".visible == true; # Not available (yet?) # assert config.docs."submodules.<name>.qux".declarationsWithPositions == [ ... ]; + assert options.submodules.declarations == [ __curPos.file ]; + assert lib.length options.submodules.declarationPositions == 1; + assert (lib.head options.submodules.declarationPositions).file == __curPos.file; + assert options.merged.declarations == [ __curPos.file __curPos.file ]; + assert lib.length options.merged.declarationPositions == 2; + assert (lib.elemAt options.merged.declarationPositions 0).file == __curPos.file; + assert (lib.elemAt options.merged.declarationPositions 1).file == __curPos.file; + assert (lib.elemAt options.merged.declarationPositions 0).line != (lib.elemAt options.merged.declarationPositions 1).line; + assert mergedSubOption.declarations == [ __curPos.file __curPos.file ]; + assert lib.length mergedSubOption.declarationPositions == 2; + assert (lib.elemAt mergedSubOption.declarationPositions 0).file == __curPos.file; + assert (lib.elemAt mergedSubOption.declarationPositions 1).file == __curPos.file; + assert (lib.elemAt mergedSubOption.declarationPositions 0).line != (lib.elemAt mergedSubOption.declarationPositions 1).line; assert lib.length config.docs."merged.<name>.extensible".declarations == 2; - true; + true); }; } diff --git a/lib/types.nix b/lib/types.nix index d428ea7c7d8f5..e259653caf7c9 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -695,7 +695,7 @@ rec { // { # mergeOptionDecls is not idempotent in these attrs: declarations = a.tags.${tagName}.declarations ++ bOpt.declarations; - declarationPositions = a.tags.${tagName}.declarations ++ bOpt.declarations; + declarationPositions = a.tags.${tagName}.declarationPositions ++ bOpt.declarationPositions; } ) (builtins.intersectAttrs a.tags b.tags); |