about summary refs log tree commit diff
path: root/nixpkgs/pkgs/build-support/testers/test-equal-derivation.nix
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/build-support/testers/test-equal-derivation.nix')
-rw-r--r--nixpkgs/pkgs/build-support/testers/test-equal-derivation.nix26
1 files changed, 26 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/build-support/testers/test-equal-derivation.nix b/nixpkgs/pkgs/build-support/testers/test-equal-derivation.nix
new file mode 100644
index 000000000000..610d5f585576
--- /dev/null
+++ b/nixpkgs/pkgs/build-support/testers/test-equal-derivation.nix
@@ -0,0 +1,26 @@
+{ lib, runCommand, emptyFile, nix-diff }:
+
+assertion: a: b:
+let
+  drvA = builtins.unsafeDiscardOutputDependency a.drvPath or (throw "testEqualDerivation second argument must be a package");
+  drvB = builtins.unsafeDiscardOutputDependency b.drvPath or (throw "testEqualDerivation third argument must be a package");
+  name =
+    if a?name
+    then "testEqualDerivation-${a.name}"
+    else "testEqualDerivation";
+in
+if drvA == drvB then
+  emptyFile
+else
+  runCommand name
+    {
+      inherit assertion drvA drvB;
+      nativeBuildInputs = [ nix-diff ];
+    } ''
+      echo "$assertion"
+      echo "However, the derivations differ:"
+      echo
+      echo nix-diff $drvA $drvB
+      nix-diff $drvA $drvB
+      exit 1
+    ''