diff --git a/pkgs/build-support/setup-hooks/make-binary-wrapper/default.nix b/pkgs/build-support/setup-hooks/make-binary-wrapper/default.nix index 9f52a05f61ca..c9b03b75cd03 100644 --- a/pkgs/build-support/setup-hooks/make-binary-wrapper/default.nix +++ b/pkgs/build-support/setup-hooks/make-binary-wrapper/default.nix @@ -16,12 +16,14 @@ makeSetupHook { substitutions = { cc = "${cc}/bin/${cc.targetPrefix}cc ${lib.escapeShellArgs (map (s: "-fsanitize=${s}") sanitizers)}"; + }; + passthru = { # Extract the function call used to create a binary wrapper from its embedded docstring - passthru.extractCmd = writeShellScript "extract-binary-wrapper-cmd" '' + extractCmd = writeShellScript "extract-binary-wrapper-cmd" '' strings -dw "$1" | sed -n '/^makeCWrapper/,/^$/ p' ''; - passthru.tests = tests.makeBinaryWrapper; + tests = tests.makeBinaryWrapper; }; } ./make-binary-wrapper.sh diff --git a/pkgs/build-support/setup-hooks/postgresql-test-hook/default.nix b/pkgs/build-support/setup-hooks/postgresql-test-hook/default.nix index d0031c93c10c..e9e77b0bbe6f 100644 --- a/pkgs/build-support/setup-hooks/postgresql-test-hook/default.nix +++ b/pkgs/build-support/setup-hooks/postgresql-test-hook/default.nix @@ -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 diff --git a/pkgs/build-support/setup-hooks/wrap-gapps-hook/default.nix b/pkgs/build-support/setup-hooks/wrap-gapps-hook/default.nix index d7699b2557fc..5ef613838856 100644 --- a/pkgs/build-support/setup-hooks/wrap-gapps-hook/default.nix +++ b/pkgs/build-support/setup-hooks/wrap-gapps-hook/default.nix @@ -13,6 +13,7 @@ }: makeSetupHook { + name = "wrap-gapps-hook"; deps = lib.optionals (!stdenv.isDarwin) [ # It is highly probable that a program will use GSettings, # at minimum through GTK file chooser dialogue. @@ -36,8 +37,8 @@ makeSetupHook { # We use the wrapProgram function. makeWrapper ]; - substitutions = { - passthru.tests = let + passthru = { + tests = let sample-project = ./tests/sample-project; testLib = callPackage ./tests/lib.nix { }; diff --git a/pkgs/build-support/trivial-builders.nix b/pkgs/build-support/trivial-builders.nix index e73cb9c5decb..a8c291b82324 100644 --- a/pkgs/build-support/trivial-builders.nix +++ b/pkgs/build-support/trivial-builders.nix @@ -1,5 +1,12 @@ { lib, stdenv, stdenvNoCC, lndir, runtimeShell, shellcheck }: +let + inherit (lib) + optionalAttrs + warn + ; +in + rec { /* Run the shell command `buildCommand' to produce a store path named @@ -525,12 +532,25 @@ 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 ? {} }: script: runCommand name (substitutions // { inherit meta; strictDeps = true; + # TODO 2023-01, no backport: simplify to inherit passthru; + passthru = passthru + // optionalAttrs (substitutions?passthru) + (warn "makeSetupHook (name = ${lib.strings.escapeNixString name}): `substitutions.passthru` is deprecated. Please set `passthru` directly." + substitutions.passthru); }) ('' mkdir -p $out/nix-support diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 447ab999e24f..7ba44a2a37dd 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -918,7 +918,9 @@ with pkgs; { deps = [ dieHook ]; substitutions = { shell = targetPackages.runtimeShell; - passthru.tests = tests.makeWrapper; + }; + passthru = { + tests = tests.makeWrapper; }; } ../build-support/setup-hooks/make-wrapper.sh;