trivial-builders.nix: Add input argument passthru to makeSetupHook

One significant use case is adding `passthru.tests` to setup-hooks,
and help increase test coverage for mission-critical setup-hooks.

As `meta`, `passthru` doesn't go into the build script directly.
However, passing an empty set to `passthru` breaks nixpkgs-review
and OfBorg tests, so pass it only when specified.
This commit is contained in:
Shamrock Lee 2022-08-12 16:29:37 +08:00
parent c4a0efdd5a
commit ba895a7da8
2 changed files with 13 additions and 4 deletions

View File

@ -1,9 +1,8 @@
{ callPackage, makeSetupHook }:
(makeSetupHook {
makeSetupHook {
name = "postgresql-test-hook";
} ./postgresql-test-hook.sh).overrideAttrs (o: {
passthru.tests = {
simple = callPackage ./test.nix { };
};
})
} ./postgresql-test-hook.sh

View File

@ -523,12 +523,22 @@ rec {
* substitutions = { bash = "${pkgs.bash}/bin/bash"; };
* meta.platforms = lib.platforms.linux;
* } ./myscript.sh;
*
* # setup hook with a package test
* myhellohookTested = makeSetupHook {
* deps = [ hello ];
* substitutions = { bash = "${pkgs.bash}/bin/bash"; };
* meta.platforms = lib.platforms.linux;
* passthru.tests.greeting = callPackage ./test { };
* } ./myscript.sh;
*/
makeSetupHook = { name ? "hook", deps ? [], substitutions ? {}, meta ? {} }: script:
makeSetupHook = { name ? "hook", deps ? [], substitutions ? {}, meta ? {}, passthru ? null }: script:
runCommand name
(substitutions // {
inherit meta;
strictDeps = true;
} // lib.optionalAttrs (passthru != null) {
inherit passthru;
})
(''
mkdir -p $out/nix-support