diff --git a/pkgs/lib/attrsets.nix b/pkgs/lib/attrsets.nix index 9f911299f1bb..ab3d3f49e180 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