core/pkgs/build-support/testers/test-equal-derivation.nix

34 lines
743 B
Nix
Raw Normal View History

2024-06-30 08:16:52 +00:00
{
lib,
runCommand,
emptyFile,
nix-diff,
}:
2024-05-02 00:46:19 +00:00
assertion: a: b:
let
2024-06-30 08:16:52 +00:00
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";
2024-05-02 00:46:19 +00:00
in
if drvA == drvB then
emptyFile
else
runCommand name
{
inherit assertion drvA drvB;
nativeBuildInputs = [ nix-diff ];
2024-06-30 08:16:52 +00:00
}
''
2024-05-02 00:46:19 +00:00
echo "$assertion"
echo "However, the derivations differ:"
echo
echo nix-diff $drvA $drvB
nix-diff $drvA $drvB
exit 1
''