summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorAdam Joseph <adam@westernsemico.com>2022-09-05 16:11:50 -0700
committerAdam Joseph <adam@westernsemico.com>2022-09-12 12:53:31 -0700
commit47de66b1a437c8dbef29b03be51dedb2274d0006 (patch)
tree6932f4f0a544d4ac23cbda1d4a447e4124968740 /lib
parentbf4312de3eb33c4967c32cdf123a2d97edeb1e4a (diff)
lib/attrsets.nix: add unionOfDisjoint
Diffstat (limited to 'lib')
-rw-r--r--lib/attrsets.nix10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/attrsets.nix b/lib/attrsets.nix
index 5575e9577029a..6c666ea375e59 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;