···
toClosureList = file: parentKey: imap (n: x:
if isAttrs x || isFunction x then
+
unifyModuleSyntax file "${parentKey}:anon-${toString n}" (unpackSubmodule applyIfFunction x args)
unifyModuleSyntax (toString x) (toString x) (applyIfFunction (import x) args));
···
applyIfFunction = f: arg@{ config, options, lib }: if isFunction f then
+
# Module arguments are resolved in a strict manner when attribute set
+
# deconstruction is used. As the arguments are now defined with the
+
# config.__interanl.args option, the strictness used on the attribute
+
# set argument would cause an infinite loop, if the result of the
+
# option is given as argument.
+
# To work-around the strictness issue on the deconstruction of the
+
# attributes set argument, we create a new attribute set which is
+
# constructed to satisfy the expected set of attributes. Thus calling
+
# 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.
requiredArgs = builtins.attrNames (builtins.functionArgs f);
extraArgs = builtins.listToAttrs (map (name: {
···
+
/* We have to pack and unpack submodules. We cannot wrap the expected
+
result of the function as we would no longer be able to list the arguments
+
of the submodule. (see applyIfFunction) */
+
unpackSubmodule = unpack: m: args:
+
if isType "submodule" m then
+
{ _file = m.file; } // (unpack m.submodule args)
+
packSubmodule = file: m:
+
{ _type = "submodule"; file = file; submodule = m; };
/* Merge a list of modules. This will recurse over the option
declarations in all modules, combining them into a single set.
···
current option declaration as the file use for the submodule. If the
submodule defines any filename, then we ignore the enclosing option file. */
options' = toList opt.options.options;
coerceOption = file: opt:
+
if isFunction opt then packSubmodule file opt
+
else packSubmodule file { options = opt; };
getSubModules = opt.options.type.getSubModules or null;
+
if getSubModules != null then map (packSubmodule opt.file) getSubModules ++ res.options
else if opt.options ? options then map (coerceOption opt.file) options' ++ res.options