Skip to content

Commit 84f3dee

Browse files
mightyiamA-jay98
andcommitted
lib.evalModules: add modules tree report attribute
Co-authored-by: Ali Jamadi <[email protected]>
1 parent 6a0960a commit 84f3dee

File tree

5 files changed

+39
-0
lines changed

5 files changed

+39
-0
lines changed

lib/modules.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ let
358358
options = checked options;
359359
config = checked (removeAttrs config [ "_module" ]);
360360
_module = checked (config._module);
361+
modules = [];
361362
inherit extendModules type class;
362363
};
363364
in
@@ -513,6 +514,7 @@ let
513514
disabledKeys = concatMap ({ file, disabled }: map (moduleKey file) disabled) disabled;
514515
keyFilter = filter (attrs: !elem attrs.key disabledKeys);
515516
in
517+
# CONITUE HERE ALI AND DAWN
516518
map (attrs: attrs.module) (genericClosure {
517519
startSet = keyFilter modules;
518520
operator = attrs: keyFilter attrs.modules;

lib/tests/modules.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,24 @@ checkConfigOutput() {
8282
fi
8383
}
8484

85+
checkConfigOutputVerbatim() {
86+
local expected=$1
87+
shift
88+
local actual
89+
set +e
90+
actual=$(evalConfig "$@" 2> /dev/null)
91+
set -e
92+
if [[ "$actual" == "$expected" ]]; then
93+
((++pass))
94+
else
95+
logStartFailure
96+
echo "ACTUAL:"
97+
reportFailure "$@"
98+
echo "EXPECTED: '$expected'"
99+
logFailure
100+
logEndFailure
101+
fi
102+
}
85103
checkConfigError() {
86104
local errorContains=$1
87105
local err=""
@@ -305,6 +323,20 @@ checkConfigOutput '^12$' config.value ./declare-coerced-value-unsound.nix
305323
checkConfigError 'A definition for option .* is not of type .*. Definition values:\n\s*- In .*: "1000"' config.value ./declare-coerced-value-unsound.nix ./define-value-string-bigint.nix
306324
checkConfigError 'toInt: Could not convert .* to int' config.value ./declare-coerced-value-unsound.nix ./define-value-string-arbitrary.nix
307325

326+
# Check `modules` attribute
327+
expected='
328+
[
329+
{
330+
"_file": "./modules/modules/root.nix",
331+
"imports": [],
332+
"type": "attrset"
333+
}
334+
]
335+
'
336+
337+
expected=$(echo "$expected" | jq --compact-output)
338+
checkConfigOutputVerbatim "$expected" modules ./modules/root.nix
339+
308340
# Check mkAliasOptionModule.
309341
checkConfigOutput '^true$' config.enable ./alias-with-priority.nix
310342
checkConfigOutput '^true$' config.enableAlias ./alias-with-priority.nix

lib/tests/modules/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
})
1212
config
1313
options
14+
modules
1415
;
1516
}

lib/tests/modules/modules/root.nix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
3+
}

lib/tests/test-with-nix.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pkgs.runCommand "nixpkgs-lib-tests-nix-${nix.version}"
3232
})
3333
];
3434
nativeBuildInputs = [
35+
pkgs.jq
3536
nix
3637
pkgs.gitMinimal
3738
] ++ lib.optional pkgs.stdenv.hostPlatform.isLinux pkgs.inotify-tools;

0 commit comments

Comments
 (0)