NixOS modules: Add error context on module arguments evaluation.

This commit is contained in:
Nicolas B. Pierron
2015-07-14 15:07:54 +02:00
parent 2fa88f65ea
commit a6b455bbae
5 changed files with 37 additions and 8 deletions
+14 -5
View File
@@ -91,9 +91,11 @@ rec {
let
toClosureList = file: parentKey: imap (n: x:
if isAttrs x || isFunction x then
unifyModuleSyntax file "${parentKey}:anon-${toString n}" (unpackSubmodule applyIfFunction x args)
let key = "${parentKey}:anon-${toString n}"; in
unifyModuleSyntax file key (unpackSubmodule (applyIfFunction key) x args)
else
unifyModuleSyntax (toString x) (toString x) (applyIfFunction (import x) args));
let file = toString x; key = toString x; in
unifyModuleSyntax file key (applyIfFunction key (import x) args));
in
builtins.genericClosure {
startSet = toClosureList unknownModule "" modules;
@@ -122,7 +124,7 @@ rec {
config = removeAttrs m ["key" "_file" "require" "imports"];
};
applyIfFunction = f: arg@{ config, options, lib, ... }: if isFunction f then
applyIfFunction = key: f: args@{ config, options, lib, ... }: if isFunction f then
let
# Module arguments are resolved in a strict manner when attribute set
# deconstruction is used. As the arguments are now defined with the
@@ -137,11 +139,18 @@ rec {
# not their values. The values are forwarding the result of the
# evaluation of the option.
requiredArgs = builtins.attrNames (builtins.functionArgs f);
context = name: ''while evaluating the module argument `${name}' in "${key}":'';
extraArgs = builtins.listToAttrs (map (name: {
inherit name;
value = config._module.args.${name};
value = addErrorContext (context name)
(args.${name} or config._module.args.${name});
}) requiredArgs);
in f (extraArgs // arg)
# Note: we append in the opposite order such that we can add an error
# context on the explicited arguments of "args" too. This update
# operator is used to make the "args@{ ... }: with args.lib;" notation
# works.
in f (args // extraArgs)
else
f;