Merge pull request #126718 from roberth/testEqualDerivation
testEqualDerivation: init
This commit is contained in:
commit
91917122d3
@ -1,7 +1,9 @@
|
||||
{ lib
|
||||
, stdenv
|
||||
, fetchurl
|
||||
, nixos
|
||||
, testVersion
|
||||
, testEqualDerivation
|
||||
, hello
|
||||
}:
|
||||
|
||||
@ -16,8 +18,15 @@ stdenv.mkDerivation rec {
|
||||
|
||||
doCheck = true;
|
||||
|
||||
passthru.tests.version =
|
||||
testVersion { package = hello; };
|
||||
passthru.tests = {
|
||||
version = testVersion { package = hello; };
|
||||
|
||||
invariant-under-noXlibs =
|
||||
testEqualDerivation
|
||||
"hello must not be rebuilt when environment.noXlibs is set."
|
||||
hello
|
||||
(nixos { environment.noXlibs = true; }).pkgs.hello;
|
||||
};
|
||||
|
||||
meta = with lib; {
|
||||
description = "A program that produces a familiar, friendly greeting";
|
||||
|
43
pkgs/build-support/test-equal-derivation.nix
Normal file
43
pkgs/build-support/test-equal-derivation.nix
Normal file
@ -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
|
||||
''
|
@ -10136,6 +10136,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 { };
|
||||
|
Loading…
Reference in New Issue
Block a user