summary refs log tree commit diff
path: root/lib/trivial.nix
diff options
context:
space:
mode:
Diffstat (limited to 'lib/trivial.nix')
-rw-r--r--lib/trivial.nix14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/trivial.nix b/lib/trivial.nix
index b7b9d25922a..735aa55e0dc 100644
--- a/lib/trivial.nix
+++ b/lib/trivial.nix
@@ -30,6 +30,11 @@ rec {
   /* boolean “and” */
   and = x: y: x && y;
 
+  /* Convert a boolean to a string.
+     Note that toString on a bool returns "1" and "".
+  */
+  boolToString = b: if b then "true" else "false";
+
   /* Merge two attribute sets shallowly, right side trumps left
 
      Example:
@@ -80,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: { })