From b3b40ebf791156abba529b2e50678f8958e284c3 Mon Sep 17 00:00:00 2001 From: Nicolas Pierron Date: Mon, 28 Sep 2009 18:22:44 +0000 Subject: [PATCH] Add setAttrByPath: - used to defined an attribute with its path as a list of attribute names. svn path=/nixpkgs/trunk/; revision=17480 --- pkgs/lib/attrsets.nix | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkgs/lib/attrsets.nix b/pkgs/lib/attrsets.nix index 9f911299f1b..ab3d3f49e18 100644 --- a/pkgs/lib/attrsets.nix +++ b/pkgs/lib/attrsets.nix @@ -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