summary refs log tree commit diff
path: root/lib/trivial.nix
diff options
context:
space:
mode:
authorShea Levy <shea@shealevy.com>2017-04-07 14:03:40 -0400
committerShea Levy <shea@shealevy.com>2017-04-07 14:30:05 -0400
commit0a15af2ed170b30636a264b6b535a9327effddc5 (patch)
tree831f89fc2ff64af9402542d3c54ad8347ea95782 /lib/trivial.nix
parenta5ee494046b4259a4a2dfea95776faa898d1bd26 (diff)
downloadnixpkgs-0a15af2ed170b30636a264b6b535a9327effddc5.tar
nixpkgs-0a15af2ed170b30636a264b6b535a9327effddc5.tar.gz
nixpkgs-0a15af2ed170b30636a264b6b535a9327effddc5.tar.bz2
nixpkgs-0a15af2ed170b30636a264b6b535a9327effddc5.tar.lz
nixpkgs-0a15af2ed170b30636a264b6b535a9327effddc5.tar.xz
nixpkgs-0a15af2ed170b30636a264b6b535a9327effddc5.tar.zst
nixpkgs-0a15af2ed170b30636a264b6b535a9327effddc5.zip
lib: Add composeExtensions for composing extension functions
Diffstat (limited to 'lib/trivial.nix')
-rw-r--r--lib/trivial.nix9
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/trivial.nix b/lib/trivial.nix
index 40499b2b509..acbd687dd98 100644
--- a/lib/trivial.nix
+++ b/lib/trivial.nix
@@ -80,6 +80,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: { })