* 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.
This commit is contained in:
Eelco Dolstra 2012-01-04 11:04:19 +00:00
parent 71f3c46cf6
commit 83647f4ef1

View file

@ -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 let
strict = derivationStrict attrs; strict = derivationStrict drvAttrs;
attrValues = attrs: commonAttrs = drvAttrs // (builtins.listToAttrs outputsList) // { all = map (x: x.value) outputsList; };
map (name: builtins.getAttr name attrs) (builtins.attrNames attrs);
outputToAttrListElement = outputName: outputToAttrListElement = outputName:
{ name = outputName; { name = outputName;
value = attrs // { value = commonAttrs // {
outPath = builtins.getAttr outputName strict; outPath = builtins.getAttr outputName strict;
drvPath = strict.drvPath; drvPath = strict.drvPath;
type = "derivation"; type = "derivation";
currentOutput = outputName; currentOutput = outputName;
} // outputsAttrs // { all = allList; }; };
}; };
outputsList = outputsList = map outputToAttrListElement outputs;
if attrs ? outputs
then map outputToAttrListElement attrs.outputs
else [ (outputToAttrListElement "out") ];
outputsAttrs = builtins.listToAttrs outputsList; in (builtins.head outputsList).value
allList = attrValues outputsAttrs;
head = if attrs ? outputs then builtins.head attrs.outputs else "out";
in builtins.getAttr head outputsAttrs