Add setAttrByPath:

- used to defined an attribute with its path as a list of attribute names.

svn path=/nixpkgs/trunk/; revision=17480
This commit is contained in:
Nicolas Pierron 2009-09-28 18:22:44 +00:00
parent 7ff2778cc6
commit b3b40ebf79

View file

@ -22,6 +22,14 @@ rec {
then attrByPath (tail attrPath) default (getAttr attr e)
else default;
/* Return nested attribute set in which an attribute is set. For instance
["x" "y"] applied with some value v returns `x.y = v;' */
setAttrByPath = attrPath: value:
if attrPath == [] then value
else listToAttrs [(
nameValuePair (head attrPath) (setAttrByPath (tail attrPath) value)
)];
/* Backwards compatibility hack: lib.attrByPath used to be called
lib.getAttr, which was confusing given that there was also a