depot/doc/hooks/versionCheckHook.section.md
Luke Granger-Brown 57725ef3ec Squashed 'third_party/nixpkgs/' content from commit 76612b17c0ce
git-subtree-dir: third_party/nixpkgs
git-subtree-split: 76612b17c0ce71689921ca12d9ffdc9c23ce40b2
2024-11-10 23:59:47 +00:00

1.8 KiB

versionCheckHook

This hook adds a versionCheckPhase to the preInstallCheckHooks that runs the main program of the derivation with a --help or --version argument, and checks that the ${version} string is found in that output. You use it like this:

{
  lib,
  stdenv,
  versionCheckHook,
  # ...
}:

stdenv.mkDerivation (finalAttrs: {
  # ...

  nativeInstallCheckInputs = [
    versionCheckHook
  ];
  doInstallCheck = true;

  # ...
})

Note that for buildPythonPackage and buildPythonApplication, doInstallCheck is enabled by default.

It does so in a clean environment (using env --ignore-environment), and it checks for the ${version} string in both the stdout and the stderr of the command. It will report to you in the build log the output it received and it will fail the build if it failed to find ${version}.

The variables that this phase control are:

  • dontVersionCheck: Disable adding this hook to the preInstallCheckHooks. Useful if you do want to load the bash functions of the hook, but run them differently.
  • versionCheckProgram: The full path to the program that should print the ${version} string. Defaults roughly to ${placeholder "out"}/bin/${pname}. Using $out in the value of this variable won't work, as environment variables from this variable are not expanded by the hook. Hence using placeholder is unavoidable.
  • versionCheckProgramArg: The argument that needs to be passed to versionCheckProgram. If undefined the hook tries first --help and then --version. Examples: version, -V, -v.
  • preVersionCheck: A hook to run before the check is done.
  • postVersionCheck: A hook to run after the check is done.