summary refs log tree commit diff
diff options
context:
space:
mode:
authorNicolas Pierron <nicolas.b.pierron@gmail.com>2009-06-26 12:42:00 +0000
committerNicolas Pierron <nicolas.b.pierron@gmail.com>2009-06-26 12:42:00 +0000
commitdd50af4923a71461262f3113022548edff545b79 (patch)
tree861809e1cc542e6023f419588b29fbf2f2cb2989
parentc69010d6eb67db58aaf96aa40b0ae96dfc4dcbb7 (diff)
downloadnixpkgs-dd50af4923a71461262f3113022548edff545b79.tar
nixpkgs-dd50af4923a71461262f3113022548edff545b79.tar.gz
nixpkgs-dd50af4923a71461262f3113022548edff545b79.tar.bz2
nixpkgs-dd50af4923a71461262f3113022548edff545b79.tar.lz
nixpkgs-dd50af4923a71461262f3113022548edff545b79.tar.xz
nixpkgs-dd50af4923a71461262f3113022548edff545b79.tar.zst
nixpkgs-dd50af4923a71461262f3113022548edff545b79.zip
Add a description of values which cause a bad type the failure.
svn path=/nixpkgs/trunk/; revision=16054
-rw-r--r--pkgs/lib/debug.nix2
-rw-r--r--pkgs/lib/options.nix16
2 files changed, 10 insertions, 8 deletions
diff --git a/pkgs/lib/debug.nix b/pkgs/lib/debug.nix
index 18b5e1db9d4..c05f540e503 100644
--- a/pkgs/lib/debug.nix
+++ b/pkgs/lib/debug.nix
@@ -43,6 +43,8 @@ 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));
 
+  traceValIfNot = c: x:
+    if c x then true else trace (showVal x) false;
 
   /* Evaluate a set of tests.  A test is an attribute set {expr,
      expected}, denoting an expression and its expected result.  The
diff --git a/pkgs/lib/options.nix b/pkgs/lib/options.nix
index 1d6b7061473..6f408090738 100644
--- a/pkgs/lib/options.nix
+++ b/pkgs/lib/options.nix
@@ -163,37 +163,37 @@ rec {
 
     bool = mkOptionType {
       name = "boolean";
-      check = builtins.isBool;
+      check = lib.traceValIfNot builtins.isBool;
       merge = fold lib.or false;
     };
 
     int = mkOptionType {
       name = "integer";
-      check = builtins.isInt;
+      check = lib.traceValIfNot builtins.isInt;
     };
 
     string = mkOptionType {
       name = "string";
-      check = x: builtins ? isString -> builtins.isString x;
+      check = lib.traceValIfNot (x: builtins ? isString -> builtins.isString x);
       merge = lib.concatStrings;
     };
 
     attrs = mkOptionType {
       name = "attribute set";
-      check = builtins.isAttrs;
+      check = lib.traceValIfNot builtins.isAttrs;
       merge = fold lib.mergeAttrs {};
     };
 
     # derivation is a reserved keyword.
     package = mkOptionType {
       name = "derivation";
-      check = x: builtins.isAttrs x && x ? outPath;
+      check = lib.traceValIfNot isDerivation;
     };
 
 
     list = elemType: mkOptionType {
       name = "list of ${elemType.name}s";
-      check = value: isList value && all elemType.check value;
+      check = value: lib.traceValIfNot isList value && all elemType.check value;
       merge = concatLists;
       iter = f: path: list: map (elemType.iter f (path + ".*")) list;
       fold = op: nul: list: lib.fold (e: l: elemType.fold op l e) nul list;
@@ -203,7 +203,7 @@ rec {
 
     attrsOf = elemType: mkOptionType {
       name = "attribute set of ${elemType}s";
-      check = x: builtins.isAttrs x
+      check = x: lib.traceValIfNot builtins.isAttrs x
         && fold (e: v: v && elemType.check e) true (lib.attrValues x);
       merge = fold lib.mergeAttrs {};
       iter = f: path: set: lib.mapAttrs (name: elemType.iter f (path + "." + name)) set;
@@ -230,7 +230,7 @@ rec {
 
     optionSet = mkOptionType {
       name = "option set";
-      check = x: builtins.isAttrs x;
+      check = x: lib.traceValIfNot builtins.isAttrs x;
       hasOptions = true;
     };