summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorArseniy Seroka <jagajaga@users.noreply.github.com>2015-03-28 13:16:13 +0300
committerArseniy Seroka <jagajaga@users.noreply.github.com>2015-03-28 13:16:13 +0300
commita639c710aebe51b395154d7694547ccd1009426f (patch)
tree0ce432cdcebe60b3046d2057f6f15e5c34205302 /lib
parentc01313085809b56f3b3ef39699a206b4ede9294e (diff)
parent4cd43bd2aed32ec6127feb35b4d5c613ced24286 (diff)
downloadnixlib-a639c710aebe51b395154d7694547ccd1009426f.tar
nixlib-a639c710aebe51b395154d7694547ccd1009426f.tar.gz
nixlib-a639c710aebe51b395154d7694547ccd1009426f.tar.bz2
nixlib-a639c710aebe51b395154d7694547ccd1009426f.tar.lz
nixlib-a639c710aebe51b395154d7694547ccd1009426f.tar.xz
nixlib-a639c710aebe51b395154d7694547ccd1009426f.tar.zst
nixlib-a639c710aebe51b395154d7694547ccd1009426f.zip
Merge pull request #6968 from oxij/unquestionably-good
Easy to check to be unquestionably good changes
Diffstat (limited to 'lib')
-rw-r--r--lib/customisation.nix17
-rw-r--r--lib/debug.nix10
2 files changed, 15 insertions, 12 deletions
diff --git a/lib/customisation.nix b/lib/customisation.nix
index 960eebfc79b5..91a25055df29 100644
--- a/lib/customisation.nix
+++ b/lib/customisation.nix
@@ -29,8 +29,8 @@ rec {
 
      For another application, see build-support/vm, where this
      function is used to build arbitrary derivations inside a QEMU
-     virtual machine. */
-     
+     virtual machine.
+  */
   overrideDerivation = drv: f:
     let
       newDrv = derivation (drv.drvAttrs // (f drv));
@@ -56,18 +56,17 @@ rec {
   makeOverridable = f: origArgs:
     let
       ff = f origArgs;
+      overrideWith = newArgs: origArgs // (if builtins.isFunction newArgs then newArgs origArgs else newArgs);
     in
       if builtins.isAttrs ff then (ff //
-        { override = newArgs:
-            makeOverridable f (origArgs // (if builtins.isFunction newArgs then newArgs origArgs else newArgs));
+        { override = newArgs: makeOverridable f (overrideWith newArgs);
           deepOverride = newArgs:
             makeOverridable f (lib.overrideExisting (lib.mapAttrs (deepOverrider newArgs) origArgs) newArgs);
           overrideDerivation = fdrv:
             makeOverridable (args: overrideDerivation (f args) fdrv) origArgs;
         })
       else if builtins.isFunction ff then
-        { override = newArgs:
-            makeOverridable f (origArgs // (if builtins.isFunction newArgs then newArgs origArgs else newArgs));
+        { override = newArgs: makeOverridable f (overrideWith newArgs);
           __functor = self: ff;
           deepOverride = throw "deepOverride not yet supported for functors";
           overrideDerivation = throw "overrideDerivation not yet supported for functors";
@@ -102,8 +101,10 @@ rec {
       };
   */
   callPackageWith = autoArgs: fn: args:
-    let f = if builtins.isFunction fn then fn else import fn; in
-    makeOverridable f ((builtins.intersectAttrs (builtins.functionArgs f) autoArgs) // args);
+    let
+      f    = if builtins.isFunction fn then fn else import fn;
+      auto = builtins.intersectAttrs (builtins.functionArgs f) autoArgs;
+    in makeOverridable f (auto // args);
 
 
   /* Add attributes to each output of a derivation without changing the derivation itself */
diff --git a/lib/debug.nix b/lib/debug.nix
index 8852c22981c5..2d10d981114c 100644
--- a/lib/debug.nix
+++ b/lib/debug.nix
@@ -13,10 +13,11 @@ rec {
 
   addErrorContextToAttrs = lib.mapAttrs (a: v: lib.addErrorContext "while evaluating ${a}" v);
 
+  traceIf = p: msg: x: if p then trace msg x else x;
 
-  traceVal = x: builtins.trace x x;
-  traceXMLVal = x: builtins.trace (builtins.toXML x) x;
-  traceXMLValMarked = str: x: builtins.trace (str + builtins.toXML x) x;
+  traceVal = x: trace x x;
+  traceXMLVal = x: trace (builtins.toXML x) x;
+  traceXMLValMarked = str: x: trace (str + builtins.toXML x) x;
 
   # this can help debug your code as well - designed to not produce thousands of lines
   traceShowVal = x : trace (showVal x) x;
@@ -42,6 +43,7 @@ rec {
   traceCall2 = n : f : a : b : let t = n2 : x : traceShowValMarked "${n} ${n2}:" x; in t "result" (f (t "arg 1" a) (t "arg 2" b));
   traceCall3 = n : f : a : b : c : let t = n2 : x : traceShowValMarked "${n} ${n2}:" x; in t "result" (f (t "arg 1" a) (t "arg 2" b) (t "arg 3" c));
 
+  # FIXME: rename this?
   traceValIfNot = c: x:
     if c x then true else trace (showVal x) false;
 
@@ -106,6 +108,6 @@ rec {
             )
           else
             let r = strict expr;
-            in builtins.trace "${str}\n result:\n${builtins.toXML r}" r
+            in trace "${str}\n result:\n${builtins.toXML r}" r
       );
 }