summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorVladimír Čunát <vcunat@gmail.com>2017-04-14 19:11:17 +0200
committerVladimír Čunát <vcunat@gmail.com>2017-04-14 19:11:17 +0200
commit2090aa4f65e860567af03cb3b7aa042df7168ead (patch)
treebdf4623501830af0cbf68f2d22075f70b38157b5 /lib
parenteec35cb6bd82cb0eba69c55e83990f3b9f0107dc (diff)
parent4aec96b379d3f1b89128297b0943253d6961cf94 (diff)
downloadnixlib-2090aa4f65e860567af03cb3b7aa042df7168ead.tar
nixlib-2090aa4f65e860567af03cb3b7aa042df7168ead.tar.gz
nixlib-2090aa4f65e860567af03cb3b7aa042df7168ead.tar.bz2
nixlib-2090aa4f65e860567af03cb3b7aa042df7168ead.tar.lz
nixlib-2090aa4f65e860567af03cb3b7aa042df7168ead.tar.xz
nixlib-2090aa4f65e860567af03cb3b7aa042df7168ead.tar.zst
nixlib-2090aa4f65e860567af03cb3b7aa042df7168ead.zip
Merge: fixup a bad merge
For details see:
https://github.com/NixOS/nixpkgs/commit/24444513fb5#commitcomment-21767916
Diffstat (limited to 'lib')
-rw-r--r--lib/default.nix5
-rw-r--r--lib/tests.nix10
-rw-r--r--lib/trivial.nix9
3 files changed, 24 insertions, 0 deletions
diff --git a/lib/default.nix b/lib/default.nix
index 09a64f754d8f..632b12510e82 100644
--- a/lib/default.nix
+++ b/lib/default.nix
@@ -1,3 +1,8 @@
+/* Library of low-level helper functions for nix expressions.
+ *
+ * Please implement (mostly) exhaustive unit tests
+ * for new functions in `./tests.nix'.
+ */
 let
 
   # trivial, often used functions
diff --git a/lib/tests.nix b/lib/tests.nix
index 1a9a5accd1c0..d93cadf25335 100644
--- a/lib/tests.nix
+++ b/lib/tests.nix
@@ -277,4 +277,14 @@ runTests {
     expected = [ "2001" "db8" "0" "0042" "" "8a2e" "370" "" ];
   };
 
+  testComposeExtensions = {
+    expr = let obj = makeExtensible (self: { foo = self.bar; });
+               f = self: super: { bar = false; baz = true; };
+               g = self: super: { bar = super.baz or false; };
+               f_o_g = composeExtensions f g;
+               composed = obj.extend f_o_g;
+           in composed.foo;
+    expected = true;
+  };
+
 }
diff --git a/lib/trivial.nix b/lib/trivial.nix
index 6cdc869b300b..62906339e605 100644
--- a/lib/trivial.nix
+++ b/lib/trivial.nix
@@ -85,6 +85,15 @@ rec {
   # argument, but it's nice this way if several uses of `extends` are cascaded.
   extends = f: rattrs: self: let super = rattrs self; in super // f self super;
 
+  # Compose two extending functions of the type expected by 'extends'
+  # into one where changes made in the first are available in the
+  # 'super' of the second
+  composeExtensions =
+    f: g: self: super:
+      let fApplied = f self super;
+          super' = super // fApplied;
+      in fApplied // g self super';
+
   # Create an overridable, recursive attribute set. For example:
   #
   #     nix-repl> obj = makeExtensible (self: { })