summary refs log tree commit diff
path: root/pkgs/lib/misc.nix
diff options
context:
space:
mode:
authorMarc Weber <marco-oweber@gmx.de>2009-11-22 21:28:43 +0000
committerMarc Weber <marco-oweber@gmx.de>2009-11-22 21:28:43 +0000
commit976def943b2fccfaf34adc31a66e58bfa0760678 (patch)
tree2306f62a7101a9dea0290640c7996726037270df /pkgs/lib/misc.nix
parent88e654b1ede63f286979bc5de1da05550399cf4c (diff)
downloadnixpkgs-976def943b2fccfaf34adc31a66e58bfa0760678.tar
nixpkgs-976def943b2fccfaf34adc31a66e58bfa0760678.tar.gz
nixpkgs-976def943b2fccfaf34adc31a66e58bfa0760678.tar.bz2
nixpkgs-976def943b2fccfaf34adc31a66e58bfa0760678.tar.lz
nixpkgs-976def943b2fccfaf34adc31a66e58bfa0760678.tar.xz
nixpkgs-976def943b2fccfaf34adc31a66e58bfa0760678.tar.zst
nixpkgs-976def943b2fccfaf34adc31a66e58bfa0760678.zip
nix lib: add nixType returning type of value as string which is used in
eqStrict now to return false when a b have different types. Passing
string and {} to eqStrict caused coercion failures when running tests
previously

svn path=/nixpkgs/trunk/; revision=18539
Diffstat (limited to 'pkgs/lib/misc.nix')
-rw-r--r--pkgs/lib/misc.nix25
1 files changed, 19 insertions, 6 deletions
diff --git a/pkgs/lib/misc.nix b/pkgs/lib/misc.nix
index c1fee190268..e3215d9ec56 100644
--- a/pkgs/lib/misc.nix
+++ b/pkgs/lib/misc.nix
@@ -1,5 +1,5 @@
 let lib = import ./default.nix;
-    inherit (builtins) isFunction hasAttr getAttr head tail isList isAttrs attrNames;
+    inherit (builtins) isFunction hasAttr getAttr head tail isList isAttrs isInt attrNames;
 
 in
 
@@ -348,6 +348,18 @@ rec {
       ["flags" "cfg" "mergeAttrBy" ];
 
 
+  nixType = x:
+      if isAttrs x then
+          if x ? outPath then "derivation"
+          else "aattrs"
+      else if isFunction x then "function"
+      else if isList x then "list"
+      else if x == true then "bool"
+      else if x == false then "bool"
+      else if x == null then "null"
+      else if isInt x then "int"
+      else "string";
+
   # deep, strict equality testing. This should be implemented as primop
   eqStrict = a : b :
     let eqListStrict = a : b :
@@ -355,9 +367,10 @@ rec {
       else if a == [] then true
       else eqStrict (head a) (head b) && eqListStrict (tail a) (tail b);
     in
-    if isList a && isList b then eqListStrict a b
-    else if isAttrs a && isAttrs b then
-      (eqListStrict (attrNames a) (attrNames b))
-      && (eqListStrict (lib.attrValues a) (lib.attrValues b))
-    else a == b; # FIXME !
+    if nixType a != nixType b then false
+      else if isList a then eqListStrict a b
+        else if isAttrs a then
+          (eqListStrict (attrNames a) (attrNames b))
+          && (eqListStrict (lib.attrValues a) (lib.attrValues b))
+        else a == b; # FIXME !
 }