Commit ba895a7d authored by Shamrock Lee's avatar Shamrock Lee
Browse files

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.
parent c4a0efdd
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
{ callPackage, makeSetupHook }:

(makeSetupHook {
makeSetupHook {
  name = "postgresql-test-hook";
} ./postgresql-test-hook.sh).overrideAttrs (o: {
  passthru.tests = {
    simple = callPackage ./test.nix { };
  };
})
} ./postgresql-test-hook.sh
+11 −1
Original line number Diff line number Diff line
@@ -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