lib.modules: Add hint when using config in imports

This commit is contained in:
49016
2025-08-01 21:33:33 +02:00
parent 20d21f317c
commit 7a787e122b

View File

@@ -637,6 +637,15 @@ let
key: f:
args@{ config, ... }:
let
importHint =
name:
if name == "config" then
"\n\n"
+ ''
If you get an infinite recursion here, you probably reference `config`
in `imports`. This is not supported; consider using mkEnableOption.''
else
"";
# Module arguments are resolved in a strict manner when attribute set
# deconstruction is used. As the arguments are now defined with the
# config._module.args option, the strictness used on the attribute
@@ -649,7 +658,7 @@ let
# a module will resolve strictly the attributes used as argument but
# not their values. The values are forwarding the result of the
# evaluation of the option.
context = name: ''while evaluating the module argument `${name}' in "${key}":'';
context = name: ''while evaluating the module argument `${name}' in "${key}":${importHint name}'';
extraArgs = mapAttrs (
name: _: addErrorContext (context name) (args.${name} or config._module.args.${name})
) (functionArgs f);