diff options
author | Vladimír Čunát <vcunat@gmail.com> | 2017-04-14 19:11:17 +0200 |
---|---|---|
committer | Vladimír Čunát <vcunat@gmail.com> | 2017-04-14 19:11:17 +0200 |
commit | 2090aa4f65e860567af03cb3b7aa042df7168ead (patch) | |
tree | bdf4623501830af0cbf68f2d22075f70b38157b5 /lib | |
parent | eec35cb6bd82cb0eba69c55e83990f3b9f0107dc (diff) | |
parent | 4aec96b379d3f1b89128297b0943253d6961cf94 (diff) |
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.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 09a64f754d8f3..632b12510e824 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 1a9a5accd1c03..d93cadf253351 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 6cdc869b300be..62906339e6058 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: { }) |