lib/modules: introduce setDefaultModuleLocation

Wraps a module with a default location for reporting errors.
This commit is contained in:
Naïm Favier 2021-12-17 15:17:49 +01:00
parent f90310a12f
commit 5a07097772
No known key found for this signature in database
GPG Key ID: 49B07322580B7EE2
2 changed files with 9 additions and 7 deletions

View File

@ -111,8 +111,8 @@ let
cleanSource sourceByRegex sourceFilesBySuffices cleanSource sourceByRegex sourceFilesBySuffices
commitIdFromGitRepo cleanSourceWith pathHasContext commitIdFromGitRepo cleanSourceWith pathHasContext
canCleanSource pathIsRegularFile pathIsGitRepo; canCleanSource pathIsRegularFile pathIsGitRepo;
inherit (self.modules) evalModules unifyModuleSyntax inherit (self.modules) evalModules setDefaultModuleLocation
applyIfFunction mergeModules unifyModuleSyntax applyIfFunction mergeModules
mergeModules' mergeOptionDecls evalOptionValue mergeDefinitions mergeModules' mergeOptionDecls evalOptionValue mergeDefinitions
pushDownProperties dischargeProperties filterOverrides pushDownProperties dischargeProperties filterOverrides
sortProperties fixupOptionType mkIf mkAssert mkMerge mkOverride sortProperties fixupOptionType mkIf mkAssert mkMerge mkOverride

View File

@ -334,6 +334,10 @@ rec {
in modulesPath: initialModules: args: in modulesPath: initialModules: args:
filterModules modulesPath (collectStructuredModules unknownModule "" initialModules args); filterModules modulesPath (collectStructuredModules unknownModule "" initialModules args);
/* Wrap a module with a default location for reporting errors. */
setDefaultModuleLocation = file: m:
{ _file = file; imports = [ m ]; };
/* Massage a module into canonical form, that is, a set consisting /* Massage a module into canonical form, that is, a set consisting
of options, config and imports attributes. */ of options, config and imports attributes. */
unifyModuleSyntax = file: key: m: unifyModuleSyntax = file: key: m:
@ -534,11 +538,9 @@ rec {
correspond to the definition of 'loc' in 'opt.file'. */ correspond to the definition of 'loc' in 'opt.file'. */
mergeOptionDecls = mergeOptionDecls =
let let
packSubmodule = file: m:
{ _file = file; imports = [ m ]; };
coerceOption = file: opt: coerceOption = file: opt:
if isFunction opt then packSubmodule file opt if isFunction opt then setDefaultModuleLocation file opt
else packSubmodule file { options = opt; }; else setDefaultModuleLocation file { options = opt; };
in loc: opts: in loc: opts:
foldl' (res: opt: foldl' (res: opt:
let t = res.type; let t = res.type;
@ -568,7 +570,7 @@ rec {
getSubModules = opt.options.type.getSubModules or null; getSubModules = opt.options.type.getSubModules or null;
submodules = submodules =
if getSubModules != null then map (packSubmodule opt._file) getSubModules ++ res.options if getSubModules != null then map (setDefaultModuleLocation opt._file) getSubModules ++ res.options
else if opt.options ? options then map (coerceOption opt._file) options' ++ res.options else if opt.options ? options then map (coerceOption opt._file) options' ++ res.options
else res.options; else res.options;
in opt.options // res // in opt.options // res //