···362362363363 # Like unifyModuleSyntax, but also imports paths and calls functions if necessary
364364 loadModule = args: fallbackFile: fallbackKey: m:
365365- if isFunction m || isAttrs m then
365365+ if isFunction m then
366366 unifyModuleSyntax fallbackFile fallbackKey (applyModuleArgsIfFunction fallbackKey m args)
367367+ else if isAttrs m then
368368+ if m._type or "module" == "module" then
369369+ unifyModuleSyntax fallbackFile fallbackKey (applyModuleArgsIfFunction fallbackKey m args)
370370+ else if m._type == "if" || m._type == "override" then
371371+ loadModule args fallbackFile fallbackKey { config = m; }
372372+ else
373373+ 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}."}"
367374 else if isList m then
368375 let defs = [{ file = fallbackFile; value = m; }]; in
369376 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
···365365checkConfigError 'The module .*/module-class-is-darwin.nix was imported into nixos instead of darwin.' config.fail.config ./class-check.nix
366366checkConfigError 'The module foo.nix#darwinModules.default was imported into nixos instead of darwin.' config.fail-anon.config ./class-check.nix
367367368368+# _type check
369369+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
370370+checkConfigOutput '^true$' "$@" config.enable ./declare-enable.nix ./define-enable-with-top-level-mkIf.nix
371371+368372# doRename works when `warnings` does not exist.
369373checkConfigOutput '^1234$' config.c.d.e ./doRename-basic.nix
370374# doRename adds a warning.