summary refs log tree commit diff
path: root/lib/modules.nix
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2013-10-30 14:21:41 +0100
committerEelco Dolstra <eelco.dolstra@logicblox.com>2013-10-30 14:57:43 +0100
commit800f9c203728ee84d50181af6fa34ac9e5c04e73 (patch)
tree69192ea9020cffb5a6a51557f17105ec10d76bb5 /lib/modules.nix
parent4680af6a9334297885a96ba464d58316587a87fd (diff)
downloadnixpkgs-800f9c203728ee84d50181af6fa34ac9e5c04e73.tar
nixpkgs-800f9c203728ee84d50181af6fa34ac9e5c04e73.tar.gz
nixpkgs-800f9c203728ee84d50181af6fa34ac9e5c04e73.tar.bz2
nixpkgs-800f9c203728ee84d50181af6fa34ac9e5c04e73.tar.lz
nixpkgs-800f9c203728ee84d50181af6fa34ac9e5c04e73.tar.xz
nixpkgs-800f9c203728ee84d50181af6fa34ac9e5c04e73.tar.zst
nixpkgs-800f9c203728ee84d50181af6fa34ac9e5c04e73.zip
Show correct position info for errors in submodules
E.g.

  The unique option `fileSystems./.device' is defined multiple times, in `/etc/nixos/configuration.nix' and `/etc/nixos/foo.nix'.

This requires passing file/value tuples to the merge functions.
Diffstat (limited to 'lib/modules.nix')
-rw-r--r--lib/modules.nix19
1 files changed, 8 insertions, 11 deletions
diff --git a/lib/modules.nix b/lib/modules.nix
index 11a2f64799f..040ccf68214 100644
--- a/lib/modules.nix
+++ b/lib/modules.nix
@@ -17,7 +17,7 @@ rec {
       # Traverse options and extract the option values into the final
       # config set.  At the same time, check whether all option
       # definitions have matching declarations.
-      config = yieldConfig [] options;
+      config = yieldConfig prefix options;
       yieldConfig = prefix: set:
         let res = removeAttrs (mapAttrs (n: v:
           if isOption v then v.value
@@ -52,22 +52,22 @@ rec {
      of ‘options’, ‘config’ and ‘imports’ attributes. */
   unifyModuleSyntax = file: key: m:
     if m ? config || m ? options then
-      let badAttrs = removeAttrs m ["imports" "options" "config" "key"]; in
+      let badAttrs = removeAttrs m ["imports" "options" "config" "key" "_file"]; in
       if badAttrs != {} then
         throw "Module `${key}' has an unsupported attribute `${head (attrNames badAttrs)}'."
       else
-        { inherit file;
+        { file = m._file or file;
           key = toString m.key or key;
           imports = m.imports or [];
           options = m.options or {};
           config = m.config or {};
         }
     else
-      { inherit file;
+      { file = m._file or file;
         key = toString m.key or key;
         imports = m.require or [] ++ m.imports or [];
         options = {};
-        config = removeAttrs m ["key" "require" "imports"];
+        config = removeAttrs m ["key" "_file" "require" "imports"];
       };
 
   applyIfFunction = f: arg: if builtins.isFunction f then f arg else f;
@@ -151,7 +151,7 @@ rec {
     let
       # Process mkOverride properties, adding in the default
       # value specified in the option declaration (if any).
-      defsFinal = filterOverrides'
+      defsFinal = filterOverrides
         ((if opt ? default then [{ file = head opt.declarations; value = mkOptionDefault opt.default; }] else []) ++ defs);
       files = map (def: def.file) defsFinal;
       # Type-check the remaining definitions, and merge them if
@@ -163,7 +163,7 @@ rec {
           fold (def: res:
             if opt.type.check def.value then res
             else throw "The option value `${showOption loc}' in `${def.file}' is not a ${opt.type.name}.")
-            (opt.type.merge { prefix = loc; inherit files; } (map (m: m.value) defsFinal)) defsFinal;
+            (opt.type.merge loc defsFinal) defsFinal;
       # Finally, apply the ‘apply’ function to the merged
       # value.  This allows options to yield a value computed
       # from the definitions.
@@ -240,7 +240,7 @@ rec {
 
      Note that "z" has the default priority 100.
   */
-  filterOverrides' = defs:
+  filterOverrides = defs:
     let
       defaultPrio = 100;
       getPrio = def: if def.value._type or "" == "override" then def.value.priority else defaultPrio;
@@ -249,9 +249,6 @@ rec {
       strip = def: if def.value._type or "" == "override" then def // { value = def.value.content; } else def;
     in concatMap (def: if getPrio def == highestPrio then [(strip def)] else []) defs;
 
-  /* For use in options like environment.variables. */
-  filterOverrides = defs: map (def: def.value) (filterOverrides' (map (def: { value = def; }) defs));
-
   /* Hack for backward compatibility: convert options of type
      optionSet to configOf.  FIXME: remove eventually. */
   fixupOptionType = loc: opt: