summary refs log tree commit diff
diff options
context:
space:
mode:
authorShea Levy <shea@shealevy.com>2013-06-07 03:42:46 -0400
committerShea Levy <shea@shealevy.com>2013-06-07 03:42:46 -0400
commit6d64b1d92c9ac0b0f7404f8bbb3a302b3030027a (patch)
tree2adc234219c37ff16d7a7c2cb03f3470d393d148
parentd465d6764ab6e11bdd01b2f8bf8bd5cb436e6870 (diff)
downloadnixpkgs-6d64b1d92c9ac0b0f7404f8bbb3a302b3030027a.tar
nixpkgs-6d64b1d92c9ac0b0f7404f8bbb3a302b3030027a.tar.gz
nixpkgs-6d64b1d92c9ac0b0f7404f8bbb3a302b3030027a.tar.bz2
nixpkgs-6d64b1d92c9ac0b0f7404f8bbb3a302b3030027a.tar.lz
nixpkgs-6d64b1d92c9ac0b0f7404f8bbb3a302b3030027a.tar.xz
nixpkgs-6d64b1d92c9ac0b0f7404f8bbb3a302b3030027a.tar.zst
nixpkgs-6d64b1d92c9ac0b0f7404f8bbb3a302b3030027a.zip
Give unique keys to submodule components
I'm not wed to the outPath values I chose, other options are probably
valid there too. It would be nice if we could track which file each
merged value came from as well.

Signed-off-by: Shea Levy <shea@shealevy.com>
-rw-r--r--pkgs/lib/modules.nix19
-rw-r--r--pkgs/lib/options.nix11
2 files changed, 22 insertions, 8 deletions
diff --git a/pkgs/lib/modules.nix b/pkgs/lib/modules.nix
index 74603e9c579..3d4ebc32512 100644
--- a/pkgs/lib/modules.nix
+++ b/pkgs/lib/modules.nix
@@ -75,12 +75,19 @@ rec {
         );
 
 
-  unifyOptionModule = {key ? "<unknown location>"}: m: (args:
-    let module = lib.applyIfFunction m args; in
-    if lib.isModule module then
-      { inherit key; } // module
+  unifyOptionModule = {key ? "<unknown location>"}: name: index: m: (args:
+    let
+      module = lib.applyIfFunction m args;
+      key_ = rec {
+        file = key;
+        option = name;
+        number = index;
+        outPath = "file ${toString file} option ${option} options number ${toString number}";
+      };
+    in if lib.isModule module then
+      { key = key_; } // module
     else
-      { inherit key; options = module; }
+      { key = key_; options = module; }
   );
 
 
@@ -240,7 +247,7 @@ rec {
           decls = # add location to sub-module options.
             map (m:
               mapSubOptions
-                (unifyOptionModule {inherit (m) key;})
+                (unifyOptionModule {inherit (m) key;} name)
                 m.options
             ) declarations;
 
diff --git a/pkgs/lib/options.nix b/pkgs/lib/options.nix
index d31a501cac9..1fdf9ad8088 100644
--- a/pkgs/lib/options.nix
+++ b/pkgs/lib/options.nix
@@ -31,7 +31,7 @@ rec {
   mapSubOptions = f: opt:
     if opt ? options then
       opt // {
-        options = map f (toList opt.options);
+        options = imap f (toList opt.options);
       }
     else
       opt;
@@ -86,7 +86,14 @@ rec {
             subModuleMerge = path: vals:
               lib.fix (args:
                 let
-                  result = recurseInto path (opt.options ++ toList vals) args;
+                  result = recurseInto path (opt.options ++ imap (index: v: args: {
+                    key = rec {
+                      #!!! Would be nice if we had the file the val was from
+                      option = path;
+                      number = index;
+                      outPath = "option ${option} config number ${toString number}";
+                    };
+                  } // (lib.applyIfFunction v args)) (toList vals)) args;
                   name = lib.removePrefix (opt.name + ".") path;
                   extraArgs = opt.extraArgs or {};
                   individualExtraArgs = opt.individualExtraArgs or {};