summary refs log tree commit diff
path: root/lib/types.nix
diff options
context:
space:
mode:
authorNicolas B. Pierron <nicolas.b.pierron@gmail.com>2015-03-12 23:01:47 +0100
committerNicolas B. Pierron <nicolas.b.pierron@gmail.com>2015-03-12 23:42:58 +0100
commited91474e9b94f06a44b7aa5bda9911292f709f54 (patch)
treeddbb4b53861c4743fde7201db6b502faaee742e4 /lib/types.nix
parentdd4f5f6b789c7fb2cac45cb8024e87bdb13c9740 (diff)
downloadnixpkgs-ed91474e9b94f06a44b7aa5bda9911292f709f54.tar
nixpkgs-ed91474e9b94f06a44b7aa5bda9911292f709f54.tar.gz
nixpkgs-ed91474e9b94f06a44b7aa5bda9911292f709f54.tar.bz2
nixpkgs-ed91474e9b94f06a44b7aa5bda9911292f709f54.tar.lz
nixpkgs-ed91474e9b94f06a44b7aa5bda9911292f709f54.tar.xz
nixpkgs-ed91474e9b94f06a44b7aa5bda9911292f709f54.tar.zst
nixpkgs-ed91474e9b94f06a44b7aa5bda9911292f709f54.zip
Share common code for merging option definitions.
This move idioms which were used in `evalOptionValue` and in the `merge`
functions of `listOf` and `attrsOf` types, such that we can use a names such
as `isDefined` and `optionalValue` instead or repeating identical
comparisons of `defsFinal == []`.
Diffstat (limited to 'lib/types.nix')
-rw-r--r--lib/types.nix22
1 files changed, 10 insertions, 12 deletions
diff --git a/lib/types.nix b/lib/types.nix
index 32f332ed21b..f836b07e335 100644
--- a/lib/types.nix
+++ b/lib/types.nix
@@ -6,10 +6,9 @@ with import ./attrsets.nix;
 with import ./options.nix;
 with import ./trivial.nix;
 with import ./strings.nix;
+with {inherit (import ./modules.nix) mergeDefinitions; };
 
-let
-  inherit (import ./modules.nix) mergeDefinitions;
-in rec {
+rec {
 
   isType = type: x: (x._type or "") == type;
 
@@ -114,11 +113,12 @@ in rec {
       check = isList;
       merge = loc: defs:
         map (x: x.value) (filter (x: x ? value) (concatLists (imap (n: def: imap (m: def':
-          let
-            inherit (mergeDefinitions (loc ++ ["[definition ${toString n}-entry ${toString m}]"])
-              elemType [{ inherit (def) file; value = def'; }]
-            ) defsFinal mergedValue;
-          in if defsFinal == [] then {} else { value = mergedValue; }) def.value) defs)));
+            (mergeDefinitions
+              (loc ++ ["[definition ${toString n}-entry ${toString m}]"])
+              elemType
+              [{ inherit (def) file; value = def'; }]
+            ).optionalValue
+          ) def.value) defs)));
       getSubOptions = prefix: elemType.getSubOptions (prefix ++ ["*"]);
       getSubModules = elemType.getSubModules;
       substSubModules = m: listOf (elemType.substSubModules m);
@@ -129,10 +129,8 @@ in rec {
       check = isAttrs;
       merge = loc: defs:
         mapAttrs (n: v: v.value) (filterAttrs (n: v: v ? value) (zipAttrsWith (name: defs:
-          let
-            inherit (mergeDefinitions (loc ++ [name]) elemType defs)
-              defsFinal mergedValue;
-          in if defsFinal == [] then {} else { value = mergedValue; })
+            (mergeDefinitions (loc ++ [name]) elemType defs).optionalValue
+          )
           # Push down position info.
           (map (def: listToAttrs (mapAttrsToList (n: def':
             { name = n; value = { inherit (def) file; value = def'; }; }) def.value)) defs)));