about summary refs log tree commit diff
path: root/lib/modules.nix
diff options
context:
space:
mode:
authorRobert Hensing <robert@roberthensing.nl>2020-02-24 00:15:36 +0100
committerRobert Hensing <robert@roberthensing.nl>2020-02-24 00:15:36 +0100
commit9c0ab2f26db26c21950e5c61fb06570cb4c5c79a (patch)
tree763ffa6fe19125c4878f8def2b61d244483d9ea9 /lib/modules.nix
parenta9b0ccd68e7ac9ad301c2e3d86dbdd70604ebd0e (diff)
downloadnixlib-9c0ab2f26db26c21950e5c61fb06570cb4c5c79a.tar
nixlib-9c0ab2f26db26c21950e5c61fb06570cb4c5c79a.tar.gz
nixlib-9c0ab2f26db26c21950e5c61fb06570cb4c5c79a.tar.bz2
nixlib-9c0ab2f26db26c21950e5c61fb06570cb4c5c79a.tar.lz
nixlib-9c0ab2f26db26c21950e5c61fb06570cb4c5c79a.tar.xz
nixlib-9c0ab2f26db26c21950e5c61fb06570cb4c5c79a.tar.zst
nixlib-9c0ab2f26db26c21950e5c61fb06570cb4c5c79a.zip
lib/modules.nix: Add file context to unmerged values in mergeDefinitions
This helps with troubleshooting exceptions in config values, which were hard
to track down for options with many definitions.
The trace will look like:

    error: while evaluating the attribute 'config.foo' at undefined position:
    [...]
    while evaluating the option `foo':
    [...]
    while evaluating definitions from `/home/user/mymod.nix':
    while evaluating 'dischargeProperties' at /home/user/nixpkgs/lib/modules.nix:464:25, called from /home/user/nixpkgs/lib/modules.nix:392:137:
    while evaluating the attribute 'value' at /home/user/nixpkgs/lib/modules.nix:277:44:
    Value error!

where the `/home/user/mymod.nix` module is

    { lib, ... }: {
      options.foo = lib.mkOption {
        type = lib.types.lines;
      };
      config.foo = builtins.throw "Value error!";
    }
Diffstat (limited to 'lib/modules.nix')
-rw-r--r--lib/modules.nix2
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/modules.nix b/lib/modules.nix
index 2b1faf4f0c28..6cbef5632bd7 100644
--- a/lib/modules.nix
+++ b/lib/modules.nix
@@ -389,7 +389,7 @@ rec {
       let
         # Process mkMerge and mkIf properties.
         defs' = concatMap (m:
-          map (value: { inherit (m) file; inherit value; }) (dischargeProperties m.value)
+          map (value: { inherit (m) file; inherit value; }) (builtins.addErrorContext "while evaluating definitions from `${m.file}':" (dischargeProperties m.value))
         ) defs;
 
         # Process mkOverride properties.