From c555a4e329904552a92947e125d9bc9d9a17c59e Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Sun, 13 Jun 2021 01:10:06 +0200 Subject: [PATCH] testEqualDerivation: init --- pkgs/build-support/test-equal-derivation.nix | 43 ++++++++++++++++++++ pkgs/top-level/all-packages.nix | 2 + 2 files changed, 45 insertions(+) create mode 100644 pkgs/build-support/test-equal-derivation.nix diff --git a/pkgs/build-support/test-equal-derivation.nix b/pkgs/build-support/test-equal-derivation.nix new file mode 100644 index 000000000000..5d2185ce1652 --- /dev/null +++ b/pkgs/build-support/test-equal-derivation.nix @@ -0,0 +1,43 @@ +{ lib, runCommand, emptyFile, nix-diff }: + +/* + Checks that two packages produce the exact same build instructions. + + This can be used to make sure that a certain difference of configuration, + such as the presence of an overlay does not cause a cache miss. + + When the derivations are equal, the return value is an empty file. + Otherwise, the build log explains the difference via `nix-diff`. + + Example: + + testEqualDerivation + "The hello package must stay the same when enabling checks." + hello + (hello.overrideAttrs(o: { doCheck = true; })) + +*/ +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 lib.strings.sanitizeDerivationName "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 + '' diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 684d67b92db8..55fde84e48cd 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -10135,6 +10135,8 @@ with pkgs; termplay = callPackage ../tools/misc/termplay { }; + testEqualDerivation = callPackage ../build-support/test-equal-derivation.nix { }; + tetrd = callPackage ../applications/networking/tetrd { }; tewisay = callPackage ../tools/misc/tewisay { };