-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nixpkgs documentation: reword info about version testers #348025
base: master
Are you sure you want to change the base?
Changes from all commits
fc65e45
ef4531d
772030b
3bde853
c2d89a1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -1,6 +1,12 @@ | ||||||||||
# versionCheckHook {#versioncheckhook} | ||||||||||
1# versionCheckHook {#versioncheckhook} | ||||||||||
|
||||||||||
This hook adds a `versionCheckPhase` to the [`preInstallCheckHooks`](#ssec-installCheck-phase) 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: | ||||||||||
This hook adds a `versionCheckPhase` to the [`preInstallCheckHooks`](#ssec-installCheck-phase) that runs the main program of the derivation with a `--help` or `--version` argument, and verifies if the `${version}` string is found in the output. | ||||||||||
|
||||||||||
It does so in a clean environment (using `env --ignore-environment --chdir=/`), 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}`. | ||||||||||
|
||||||||||
Here is a typical usage example: | ||||||||||
|
||||||||||
:::{.example #ex-versioncheckhook-phantom} | ||||||||||
|
||||||||||
```nix | ||||||||||
{ | ||||||||||
|
@@ -16,20 +22,76 @@ stdenv.mkDerivation (finalAttrs: { | |||||||||
nativeInstallCheckInputs = [ | ||||||||||
versionCheckHook | ||||||||||
]; | ||||||||||
|
||||||||||
doInstallCheck = true; | ||||||||||
|
||||||||||
# ... | ||||||||||
}) | ||||||||||
``` | ||||||||||
|
||||||||||
Note that for [`buildPythonPackage`](#buildpythonpackage-function) and [`buildPythonApplication`](#buildpythonapplication-function), `doInstallCheck` is enabled by default. | ||||||||||
::: | ||||||||||
AndersonTorres marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
|
||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a question: What is the purpose of this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The triple dot? It closes the |
||||||||||
Note that `doInstallCheck` is enabled by default for [`buildPythonPackage`](#buildpythonpackage-function) and [`buildPythonApplication`](#buildpythonapplication-function). | ||||||||||
|
||||||||||
doronbehar marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
## Attributes controlling versionCheckHook {#versioncheckhook-attributes-controlling} | ||||||||||
|
||||||||||
The following attributes control `versionCheckHook`: | ||||||||||
|
||||||||||
- `dontVersionCheck`: When set as `true`, the hook is not added to the [`preInstallCheckHooks`](#ssec-installCheck-phase). | ||||||||||
|
||||||||||
Useful when one wants to load the function defined by the hook, so that it can be used for a different purpose. | ||||||||||
|
||||||||||
Defaults to false. | ||||||||||
|
||||||||||
- `versionCheckProgram`: The full path to the program to be executed. | ||||||||||
|
||||||||||
Defaults to `${placeholder "out"}/bin/${pname}`, roughly speaking. | ||||||||||
|
||||||||||
The usage of `placeholder "out"` instead of `$out` here is unavoidable, since the hook does not expand environment variables. | ||||||||||
|
||||||||||
- `versionCheckProgramArg`: The argument to be passed to `versionCheckProgram`. | ||||||||||
|
||||||||||
When not defined, the hook tries `--help` first and then `--version`. | ||||||||||
|
||||||||||
Examples: `version`, `-V`, `-v`. | ||||||||||
|
||||||||||
- `preVersionCheck`: Hook that runs before the check is done. Defaults to an empty string. | ||||||||||
|
||||||||||
- `postVersionCheck`: Hook that runs after the check is done. Defaults to an empty string. | ||||||||||
|
||||||||||
Note: see also [`testers.testVersion`](#tester-testVersion). | ||||||||||
|
||||||||||
AndersonTorres marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
## Comparison between `versionCheckHook` and `testers.testVersion` {#versioncheckhook-testversion-comparison} | ||||||||||
|
||||||||||
The most notable difference between `versionCheckHook` and `testers.testVersion` is that `versionCheckHook` runs as a phase during the build time of the package, while `passthru.tests.versions` runs a complete derivation that depends on the package. | ||||||||||
|
||||||||||
Given the current limitations of Nixpkgs's tooling and CI, `versionCheckHook` fits better in most of typical situations. | ||||||||||
|
||||||||||
Below we provide tables comparing `versionCheckHook` and `testers.testVersion`. | ||||||||||
|
||||||||||
|
||||||||||
### General {#versioncheckhook-testversion-comparison-general} | ||||||||||
|
||||||||||
| Item | `versionCheckHook` | `testers.testVersion` via `passthru.tests.version` | | ||||||||||
|-------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------| | ||||||||||
| Customization | Besides the attributes described above, `versionCheckHook` provides no other methods for controlling it. | `tests.version` has access to the whole feature set of Nixpkgs, like multiple version test derivations and tools outside the package inputs. | | ||||||||||
| Execution time | `versionCheckHook` is executed automatically whenever the package is executed, e.g. `nix-build -A pkg`, since it is a phase executed during the package build time. | `tests.version` is executed only when explicitly called, e.g. `nix-build -A pkg.tests.version`; it is executed after package build time. | | ||||||||||
| Execution environment | `versionCheckHook` uses `env --ignore-environment --chdir=/` to run the executables in an environment as clean as possible, but there is no way to change its behavior. | `tests.version` executes in an environment identical to that of a consumer, independent from the package build environment. | | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Executing a package" seems incorrect / misleading to me.
Suggested change
OTH in the right column it is correct to say that test is executed, although the test is a package. |
||||||||||
| Rebuild after modification | Modifying `versionCheckHook` triggers the package rebuild. | `tests.version` does not rebuild the package, since it runs after package build time. | | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know I wrote that sentence before myself, so I hope you'd forgive me for these nitpicks:
Suggested change
|
||||||||||
| Overhead during package build time | Negligible. Although executed during the the package build time, `versionCheckHook` is lean and executes few commands. | Zero, since `tests.version` is a derivation that runs after package build time. | | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another accuracy nit:
Suggested change
|
||||||||||
| Failure detection time | `versionCheckHook` runs during the package build time, therefore it does not deal with failures happening after that. | `tests.version` detects failures after package build time, like rewritings and relocations. | | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can be more accurate:
Suggested change
It's the 2nd time you write "a derivation that runs after a package build time" or something roughly the same - I hope you are OK with the fact I emphasize that not necessarily people will build (and not run) that derivation, because people might forget to do it by themselves or look at ofborg's attempts (which are sometimes inaccurate). |
||||||||||
| Package breakage awareness | Loud and clear as soon as `versionCheckHook` is reached during the package build time. | Requires specific commands to be noticed, e.g. `nix-build -A pkg.tests.version`. | | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand this line of comparison. Do you mean "when will |
||||||||||
|
||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Small nit now:
Suggested change
|
||||||||||
### OfBorg {#versioncheckhook-testversion-comparison-general} | ||||||||||
|
||||||||||
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}`. | ||||||||||
| Item | `versionCheckHook` | `testers.testVersion` via `passthru.tests.version` | | ||||||||||
|-------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------| | ||||||||||
| OfBorg CI | `versionCheckHook` will be executed by OfBorg, since ofBorg automatically executes the packages affected by the pull request (PR). | OfBorg supports automatic execution of `passthru.tests` for _packages directly affected_ by the PR. | | ||||||||||
| OfBorg CI, transitive dependencies | `versionCheckHook` will executed by OfBorg, since it builds transitive dependencies of a package affected by the PR. (????) | OfBorg does not support automatic execution of `passthru.tests` for transitive dependencies, requiring extra commands for this. | | ||||||||||
|
||||||||||
Comment on lines
+89
to
+90
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm maybe each line should explain better to which ofborg behavior are we referring to. Here's my suggestion:
Suggested change
|
||||||||||
The variables that this phase control are: | ||||||||||
### nixpkgs-review {#versioncheckhook-testversion-comparison-nixpkgs-review} | ||||||||||
|
||||||||||
- `dontVersionCheck`: Disable adding this hook to the [`preInstallCheckHooks`](#ssec-installCheck-phase). 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. | ||||||||||
| Item | `versionCheckHook` | `testers.testVersion` via `passthru.tests.version` | | ||||||||||
|-------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------| | ||||||||||
| `nixpkgs-review` | `versionCheckHook` will be executed by `nixpkgs-review`. | `nixpkgs-review` has no support for executing `passthru.tests` at all. | | ||||||||||
| `nixpkgs-review`, transitive dependencies | `versionCheckHook` will be executed by `nixpkgs-review`, since the tool reaches transitive dependencies automatically. | `nixpkgs-review` has no support for executing `passthru.tests` at all, even for transitive dependencies. | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm this suggests a sort of dissatisfaction that might be opinionated, but I don't have a strong opinion regarding it, so I won't make this comment of mine a blocker.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You recognized the limitations of the tooling, at least indirectly:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that these are "limitations", that also don't allow us to easily run
passthru.tests
of packages automatically etc., but I don't necessarily think that these limitations should be solved at some point. I'd say that calling this a limitation might even be an overstatement, at least for some tools. It'd be very nice ifnixpkgs-review
would have builtpassthru.tests
automatically, but I wouldn't say that ofborg is not that well designed. Not only that, even ifnixpkgs-review
would have run it, I'd still claim thatversionCheckHook
is better, because runningnixpkgs-review
is not mandatory, and silent breakages can still rot in your system.