Author: eelco
Date: Wed Jan  4 11:04:19 2012
New Revision: 31270
URL: https://nixos.org/websvn/nix/?rev=31270&sc=1

Log:
* Simplify the implementation of "derivation" a bit: lift out the
  common attribution so that they're evaluated only once, etc.  Note
  that the default output is now the first element of the "outputs"
  attribute, rather than the first element of the sorted list of
  outputs.  This seems more user-friendly.

Modified:
   nix/branches/multiple-outputs-sandbox/corepkgs/derivation.nix

Modified: nix/branches/multiple-outputs-sandbox/corepkgs/derivation.nix
==============================================================================
--- nix/branches/multiple-outputs-sandbox/corepkgs/derivation.nix       Wed Jan 
 4 10:31:49 2012        (r31269)
+++ nix/branches/multiple-outputs-sandbox/corepkgs/derivation.nix       Wed Jan 
 4 11:04:19 2012        (r31270)
@@ -1,31 +1,24 @@
-attrs:
+/* This is the implementation of the ‘derivation’ builtin function.
+   It's actually a wrapper around the ‘derivationStrict’ primop. */
+
+drvAttrs @ { outputs ? [ "out" ], ... }:
 
 let
 
-  strict = derivationStrict attrs;
+  strict = derivationStrict drvAttrs;
   
-  attrValues = attrs:
-    map (name: builtins.getAttr name attrs) (builtins.attrNames attrs);
-    
+  commonAttrs = drvAttrs // (builtins.listToAttrs outputsList) // { all = map 
(x: x.value) outputsList; };
+
   outputToAttrListElement = outputName:
     { name = outputName;
-      value = attrs // {
+      value = commonAttrs // {
         outPath = builtins.getAttr outputName strict;
         drvPath = strict.drvPath;
         type = "derivation";
         currentOutput = outputName;
-      } // outputsAttrs // { all = allList; };
+      };
     };
     
-  outputsList =
-    if attrs ? outputs
-    then map outputToAttrListElement attrs.outputs
-    else [ (outputToAttrListElement "out") ];
+  outputsList = map outputToAttrListElement outputs;
     
-  outputsAttrs = builtins.listToAttrs outputsList;
-  
-  allList = attrValues outputsAttrs;
-  
-  head = if attrs ? outputs then builtins.head attrs.outputs else "out";
-  
-in builtins.getAttr head outputsAttrs
+in (builtins.head outputsList).value
_______________________________________________
nix-commits mailing list
[email protected]
http://lists.science.uu.nl/mailman/listinfo/nix-commits

Reply via email to