summary refs log tree commit diff
path: root/pkgs/lib/options.nix
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/lib/options.nix')
-rw-r--r--pkgs/lib/options.nix16
1 files changed, 7 insertions, 9 deletions
diff --git a/pkgs/lib/options.nix b/pkgs/lib/options.nix
index cd60b8f3b88c..59bda41a623f 100644
--- a/pkgs/lib/options.nix
+++ b/pkgs/lib/options.nix
@@ -2,7 +2,7 @@
 
 let lib = import ./default.nix; in
 
-with { inherit (builtins) head tail; };
+with { inherit (builtins) head length; };
 with import ./trivial.nix;
 with import ./lists.nix;
 with import ./misc.nix;
@@ -133,7 +133,7 @@ rec {
   # separate the merge & apply fields from the interface.
   mergeOptionDecls = opts:
     if opts == [] then {}
-    else if tail opts == [] then
+    else if length opts == 1 then
       let opt = head opts; in
       if opt ? options then
         opt // { options = toList opt.options; }
@@ -152,13 +152,11 @@ rec {
         opt1 // opt2
         // optionalAttrs (opt1 ? options || opt2 ? options) {
             options =
-               (toList (attrByPath ["options"] [] opt1))
-            ++ (toList (attrByPath ["options"] [] opt2));
+               (toList (opt1.options or []))
+            ++ (toList (opt2.options or []));
           }
         // optionalAttrs (opt1 ? extraConfigs || opt2 ? extraConfigs) {
-            extraConfigs =
-               (attrByPath ["extraConfigs"] [] opt1)
-            ++ (attrByPath ["extraConfigs"] [] opt2);
+            extraConfigs = opt1.extraConfigs or [] ++ opt2.extraConfigs or [];
           }
       )) {} opts;
 
@@ -189,7 +187,7 @@ rec {
     ) (attrNames defs));
 
   mergeDefaultOption = list:
-    if list != [] && tail list == [] then head list
+    if length list == 1 then head list
     else if all builtins.isFunction list then x: mergeDefaultOption (map (f: f x) list)
     else if all isList list then concatLists list
     else if all isAttrs list then fold lib.mergeAttrs {} list
@@ -214,7 +212,7 @@ rec {
 
   mergeOneOption = list:
     if list == [] then abort "This case should never happen."
-    else if tail list != [] then throw "Multiple definitions. Only one is allowed for this option."
+    else if length list != 1 then throw "Multiple definitions. Only one is allowed for this option."
     else head list;