about summary refs log tree commit diff
path: root/pkgs/lib
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2007-11-09 18:05:32 +0000
committerEelco Dolstra <eelco.dolstra@logicblox.com>2007-11-09 18:05:32 +0000
commitb5f893d92a651bc824450b55af5ee9a42e72e574 (patch)
tree18f86679a9feb1c53f3631d8d7879ffd2566296f /pkgs/lib
parent15e2d9c3044b8aa3540fcb34cf9717e381ccc03c (diff)
downloadnixlib-b5f893d92a651bc824450b55af5ee9a42e72e574.tar
nixlib-b5f893d92a651bc824450b55af5ee9a42e72e574.tar.gz
nixlib-b5f893d92a651bc824450b55af5ee9a42e72e574.tar.bz2
nixlib-b5f893d92a651bc824450b55af5ee9a42e72e574.tar.lz
nixlib-b5f893d92a651bc824450b55af5ee9a42e72e574.tar.xz
nixlib-b5f893d92a651bc824450b55af5ee9a42e72e574.tar.zst
nixlib-b5f893d92a651bc824450b55af5ee9a42e72e574.zip
* Moved the functions for option processing to lib.
svn path=/nixpkgs/trunk/; revision=9616
Diffstat (limited to 'pkgs/lib')
-rw-r--r--pkgs/lib/default.nix30
-rw-r--r--pkgs/lib/options.nix100
2 files changed, 30 insertions, 100 deletions
diff --git a/pkgs/lib/default.nix b/pkgs/lib/default.nix
index bb6f9061467e..4e2e213bdfba 100644
--- a/pkgs/lib/default.nix
+++ b/pkgs/lib/default.nix
@@ -201,4 +201,34 @@ rec {
 	else condConcat
 		name (tail (tail list)) checker;
 
+
+  /* Options. */
+  
+  mkOption = attrs: attrs // {_type = "option";};
+
+  typeOf = x: if x ? _type then x._type else "";
+
+  fillOptionsDefaults = defs: opts: opts //
+    builtins.listToAttrs (map (defName:
+      { name = defName;
+        value = 
+          let
+            defValue = builtins.getAttr defName defs;
+            optValue = builtins.getAttr defName opts;
+          in
+          if typeOf defValue == "option"
+          then
+            # `defValue' is an option.
+            if builtins.hasAttr defName opts
+            then builtins.getAttr defName opts
+            else defValue.default
+          else
+            # `defValue' is an attribute set containing options.
+            # So recurse.
+            if builtins.hasAttr defName opts && builtins.isAttrs optValue 
+            then fillOptionsDefaults defValue optValue
+            else fillOptionsDefaults defValue {};
+      }
+    ) (builtins.attrNames defs));
+
 }
diff --git a/pkgs/lib/options.nix b/pkgs/lib/options.nix
deleted file mode 100644
index 802d318dc059..000000000000
--- a/pkgs/lib/options.nix
+++ /dev/null
@@ -1,100 +0,0 @@
-let
-
-  mkOption = attrs: attrs // {_type = "option";};
-
-  typeOf = x: if x ? _type then x._type else "";
-
-
-  combine = defs: opts: opts //
-    builtins.listToAttrs (map (defName:
-      { name = defName;
-        value = 
-          let
-            defValue = builtins.getAttr defName defs;
-            optValue = builtins.getAttr defName opts;
-          in
-          if typeOf defValue == "option"
-          then
-            # `defValue' is an option.
-            if builtins.hasAttr defName opts
-            then builtins.getAttr defName opts
-            else defValue.default
-          else
-            # `defValue' is an attribute set containing options.
-            # So recurse.
-            if builtins.hasAttr defName opts && builtins.isAttrs optValue 
-            then combine defValue optValue
-            else combine defValue {};
-      }
-    ) (builtins.attrNames defs));
-
-
-  testDefs = {
-  
-    time = {
-      timeZone = mkOption {
-        default = "CET";
-        example = "America/New_York";
-        description = "The time zone used when displaying times and dates.";
-      };
-    };
-
-    boot = {
-      kernelModules = mkOption {
-        default = ["mod1"];
-        description = "
-          The set of kernel modules to be loaded in the second stage of
-          the boot process.  That is, these modules are not included in
-          the initial ramdisk, so they'd better not be required for
-          mounting the root file system.  Add them to
-          <option>boot.initrd.extraKernelModules</option> if they are.
-        ";
-      };
-
-      initrd = {
-      
-        kernelModules = mkOption {
-          default = [
-            "ahci"
-            "ata_piix"
-            "pata_marvell"
-            "sd_mod"
-            "sr_mod"
-            "ide-cd"
-            "ide-disk"
-            "ide-generic"
-            "ext3"
-            # Support USB keyboards, in case the boot fails and we only have
-            # a USB keyboard.
-            "ehci_hcd"
-            "ohci_hcd"
-            "usbhid"
-          ];
-          description = "
-            The set of kernel modules in the initial ramdisk used during the
-            boot process.
-          ";
-        };
-        
-      };
-      
-    };
-    
-  };
-
-
-  testOpts = {
-    /*
-    time = {
-      timeZone = "UTC";
-    };
-    */
-    boot = {
-      initrd = {
-        kernelModules = ["foo"];
-        extraKernelModules = ["bar"];
-      };
-    };
-  };
-
-in (combine testDefs testOpts).boot.initrd.kernelModules