···362363 # Like unifyModuleSyntax, but also imports paths and calls functions if necessary
364 loadModule = args: fallbackFile: fallbackKey: m:
365- if isFunction m || isAttrs m then
366 unifyModuleSyntax fallbackFile fallbackKey (applyModuleArgsIfFunction fallbackKey m args)
0000000367 else if isList m then
368 let defs = [{ file = fallbackFile; value = m; }]; in
369 throw "Module imports can't be nested lists. Perhaps you meant to remove one level of lists? Definitions: ${showDefs defs}"
···362363 # Like unifyModuleSyntax, but also imports paths and calls functions if necessary
364 loadModule = args: fallbackFile: fallbackKey: m:
365+ if isFunction m then
366 unifyModuleSyntax fallbackFile fallbackKey (applyModuleArgsIfFunction fallbackKey m args)
367+ else if isAttrs m then
368+ if m._type or "module" == "module" then
369+ unifyModuleSyntax fallbackFile fallbackKey (applyModuleArgsIfFunction fallbackKey m args)
370+ else if m._type == "if" || m._type == "override" then
371+ loadModule args fallbackFile fallbackKey { config = m; }
372+ else
373+ throw "Could not load a value as a module, because it is of type ${lib.strings.escapeNixString m._type}${lib.optionalString (fallbackFile != null) ", in file ${toString fallbackFile}."}"
374 else if isList m then
375 let defs = [{ file = fallbackFile; value = m; }]; in
376 throw "Module imports can't be nested lists. Perhaps you meant to remove one level of lists? Definitions: ${showDefs defs}"
+4
lib/tests/modules.sh
···365checkConfigError 'The module .*/module-class-is-darwin.nix was imported into nixos instead of darwin.' config.fail.config ./class-check.nix
366checkConfigError 'The module foo.nix#darwinModules.default was imported into nixos instead of darwin.' config.fail-anon.config ./class-check.nix
3670000368# doRename works when `warnings` does not exist.
369checkConfigOutput '^1234$' config.c.d.e ./doRename-basic.nix
370# doRename adds a warning.
···365checkConfigError 'The module .*/module-class-is-darwin.nix was imported into nixos instead of darwin.' config.fail.config ./class-check.nix
366checkConfigError 'The module foo.nix#darwinModules.default was imported into nixos instead of darwin.' config.fail-anon.config ./class-check.nix
367368+# _type check
369+checkConfigError 'Could not load a value as a module, because it is of type "flake", in file .*/module-imports-_type-check.nix' config.ok.config ./module-imports-_type-check.nix
370+checkConfigOutput '^true$' "$@" config.enable ./declare-enable.nix ./define-enable-with-top-level-mkIf.nix
371+372# doRename works when `warnings` does not exist.
373checkConfigOutput '^1234$' config.c.d.e ./doRename-basic.nix
374# doRename adds a warning.