Skip to content
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

doc/passthru: improve sanctioned use of installCheckPhase #319087

Closed
wants to merge 1 commit into from

Conversation

pbsds
Copy link
Member

@pbsds pbsds commented Jun 11, 2024

Description of changes

I only found #315616 after it was merged. Here are my two cents.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.11 Release Notes (or backporting 23.11 and 24.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@github-actions github-actions bot added the 8.has: documentation This PR adds or changes documentation label Jun 11, 2024
@pbsds pbsds requested review from raboof, abathur, doronbehar and Atemu June 11, 2024 15:29
@pbsds pbsds marked this pull request as ready for review June 11, 2024 15:29
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux labels Jun 11, 2024
- Access the package as consumers would, independently from the environment in which it was built
- Access the package as consumers would, e.g. the environment setup up the way `mkDerivation` or `environment.systemPackages` would.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not to defend the existing text (I see an argument it's leaving too much to the imagination), but the rephrased clause this adds feels incomplete and I'm not sure what it's trying to clarify.

In case it helps, I'm just going to unpack the distinctions I read the existing text as trying to make:

Since they are separate derivations, passthru.tests depend on the package under test just like any other consumer of the package would. This separation ensures these tests depend on actual derivation outputs and are not affected by temporary state in the build sandbox.

Copy link
Member Author

@pbsds pbsds Jun 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a explanation to the example

@@ -94,7 +94,7 @@ stdenv.mkDerivation (finalAttrs: {
installCheckPhase = ''
runHook preInstallCheck
echo checking if 'git --version' mentions ${finalAttrs.version}
$out/bin/git --version | grep ${finalAttrs.version}
env --ignore-environment $out/bin/git --version | grep --silent "${finalAttrs.version}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change solving for a specific failure mode in the example, or is it just demonstrating one way to guard against state inside the build environment in order to make a general point about the fact that tests run during the build may be sensitive to temporary state that won't exist after the build completes?

If it's the former, I think it might be better to just lay the cards down here and show the problem we'd have without this workaround (because it will provide a better illustration of the underlying risk of these tests depending on the state inside the sandbox) and also show the fix?

If this just demonstrates how to guard against state without an acute need, I think it's still worth explaining why a "clean" environment is important (and perhaps noting that this only guards against environment variables which are only one kind of state present in the sandbox).

Copy link
Member Author

@pbsds pbsds Jun 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is specifically to avoid variables like PYTHONPATH, to guard against build artifacts one could pushd "$(mktemp -d)"

Copy link
Member

@raboof raboof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about the 'as consumers would' description, otherwise nice improvements!

@@ -104,9 +104,9 @@ stdenv.mkDerivation (finalAttrs: {

However, tests that are non-trivial will better fit into `passthru.tests` because they:

- Access the package as consumers would, independently from the environment in which it was built
- Access the package as consumers would, e.g. the environment setup up the way `mkDerivation` or `environment.systemPackages` would.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure mkDerivation makes sense to me here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/mkDerivation/stdenv/?

@pbsds pbsds force-pushed the fix-meta-docs-1718119182 branch 2 times, most recently from ed110f5 to 64f1a22 Compare June 15, 2024 17:25
@pbsds pbsds force-pushed the fix-meta-docs-1718119182 branch from 64f1a22 to cf39d24 Compare June 15, 2024 17:26
:::

However, tests that are non-trivial will better fit into `passthru.tests` because they:

- Access the package as consumers would, independently from the environment in which it was built
- Access the package outputs as any consumer would, with an environment as setup up with either `stdenv` or `environment.systemPackages`, and without temporary build artifacts and state produced in `configurePhase` and `buildPhase`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Access the package outputs as any consumer would, with an environment as setup up with either `stdenv` or `environment.systemPackages`, and without temporary build artifacts and state produced in `configurePhase` and `buildPhase`.
- Access the package outputs as any consumer would, with an environment set up with either `stdenv` or `environment.systemPackages`, and without temporary build artifacts and state produced in `configurePhase` and `buildPhase`.

Just fixes. Generally like this better, though I'm still personally a little unsure about the "with an environment set up with either stdenv or environment.systemPackages" bit:

  • Is it clarifying something specific beyond what "as any consumer would" already implies?
  • I'm not sure I grok how the environment.systemPackages bit fits--is there any testing context in which a passthru test would run with all of the user's systemPackages in scope? (That seems undesirable and a sure source of flakiness, unless maybe it's gesturing at grafting in NixOS VM tests? If the latter, it's worth clarifying.)
  • It reads like a complete list, but I imagine it's leaving out cases?

Copy link
Member Author

@pbsds pbsds Jun 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I mention those two means of consuming a package is because of the various hooks that run through the packages and ensure their propagated inputs are also added and set up in various ways. It should read as non-exhausive. environment.systemPackages is a means of adding a package to your environment.

how about

Suggested change
- Access the package outputs as any consumer would, with an environment as setup up with either `stdenv` or `environment.systemPackages`, and without temporary build artifacts and state produced in `configurePhase` and `buildPhase`.
- Access the package outputs as any consumer would, for example like the environments set up when using `nix-shell`, `stdenv`, or `environment.systemPackages`, and without the temporary build artifacts and state produced in `configurePhase` and `buildPhase`.

@doronbehar
Copy link
Contributor

Maybe we should create a versionInstallCheckHook that will take care of all the details that you try to explain here, and we can instruct users to simply read the shell code of the hook if they want to know the details of how we ignore the environment etc.

@pbsds
Copy link
Member Author

pbsds commented Jun 28, 2024

closing in favor of #320266

@pbsds pbsds closed this Jun 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8.has: documentation This PR adds or changes documentation 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants