From 47de66b1a437c8dbef29b03be51dedb2274d0006 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Mon, 5 Sep 2022 16:11:50 -0700 Subject: [PATCH] lib/attrsets.nix: add unionOfDisjoint --- lib/attrsets.nix | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/attrsets.nix b/lib/attrsets.nix index 5575e9577029..6c666ea375e5 100644 --- a/lib/attrsets.nix +++ b/lib/attrsets.nix @@ -622,6 +622,16 @@ rec { dontRecurseIntoAttrs = attrs: attrs // { recurseForDerivations = false; }; + /* `unionOfDisjoint x y` is equal to `x // y // z` where the + attrnames in `z` are the intersection of the attrnames in `x` and + `y`, and all values `assert` with an error message */ + unionOfDisjoint = x: y: + x // (mapAttrs + (name: val: + if hasAttr name x + then builtins.throw "attribute collision: ${name}" + else val) y); + /*** deprecated stuff ***/ zipWithNames = zipAttrsWithNames;