diff options
author | Vladimír Čunát <vcunat@gmail.com> | 2017-04-14 19:08:20 +0200 |
---|---|---|
committer | Vladimír Čunát <vcunat@gmail.com> | 2017-04-14 19:08:59 +0200 |
commit | 4aec96b379d3f1b89128297b0943253d6961cf94 (patch) | |
tree | bae26b8f66fa14c858f20ae409594e4abe7bc9b9 /lib | |
parent | eb750f9a7b22620a9bafc1ff3c498e062b3bd5b2 (diff) | |
parent | 6617c8bd87e185ece1762c22ed4521adebd7c65b (diff) | |
download | nixlib-4aec96b379d3f1b89128297b0943253d6961cf94.tar nixlib-4aec96b379d3f1b89128297b0943253d6961cf94.tar.gz nixlib-4aec96b379d3f1b89128297b0943253d6961cf94.tar.bz2 nixlib-4aec96b379d3f1b89128297b0943253d6961cf94.tar.lz nixlib-4aec96b379d3f1b89128297b0943253d6961cf94.tar.xz nixlib-4aec96b379d3f1b89128297b0943253d6961cf94.tar.zst nixlib-4aec96b379d3f1b89128297b0943253d6961cf94.zip |
Merge the two "same" merges
This only takes the state from the second parent. The purpose is that when this commit depends on the failed one, simply merging this commit is a safe way to fix the problems. Details: https://github.com/NixOS/nixpkgs/commit/24444513fb5#commitcomment-21767916
Diffstat (limited to 'lib')
-rw-r--r-- | lib/default.nix | 5 | ||||
-rw-r--r-- | lib/tests.nix | 10 | ||||
-rw-r--r-- | lib/trivial.nix | 9 |
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 40499b2b5092..acbd687dd98f 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: { }) |