Skip to content

treewide: Fix finalAttrs.doCheck by explicitly setting doCheck to the conditional in mkDerivation#434550

Open
Artturin wants to merge 1 commit intoNixOS:masterfrom
Artturin:treewidedocheckfix
Open

treewide: Fix finalAttrs.doCheck by explicitly setting doCheck to the conditional in mkDerivation#434550
Artturin wants to merge 1 commit intoNixOS:masterfrom
Artturin:treewidedocheckfix

Conversation

@Artturin
Copy link
Member

@Artturin Artturin commented Aug 17, 2025

finalAttrs.doCheck does not include the conditionals in mkDerivation which disable doCheck on !canExecute cross.

This is better than changing all finalAttrs.doCheck to
finalAttrs.finalPackage.doCheck because it works without conditional
outputs and it addresses the comment in mkDerivation about not using
doCheck = true

Things done

  • Built on platform:
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • Tested, as applicable:
  • Ran nixpkgs-review on this PR. See nixpkgs-review usage.
  • Tested basic functionality of all binary files, usually in ./result/bin/.
  • Nixpkgs Release Notes
    • Package update: when the change is major or breaking.
  • NixOS Release Notes
    • Module addition: when adding a new NixOS module.
    • Module update: when the change is significant.
  • Fits CONTRIBUTING.md, pkgs/README.md, maintainers/README.md and other READMEs.

Add a 👍 reaction to pull requests you find important.

@ofborg ofborg bot added the 6.topic: cross-compilation Building packages on a different platform than they will be used on label Aug 17, 2025
@Artturin Artturin force-pushed the treewidedocheckfix branch from 0c67139 to 6406e79 Compare August 17, 2025 20:45
@Artturin Artturin changed the title treewide: Fix finalAttrs.doChecks which do not function correctly when cross-compiling treewide: Fix finalAttrs.doCheck by explicitly setting doCheck to the conditional in mkDerivation Aug 17, 2025
@Artturin Artturin force-pushed the treewidedocheckfix branch from 6406e79 to 1b0f217 Compare August 17, 2025 20:46
…he conditional in mkDerivation

`finalAttrs.doCheck` does not include the conditionals in `mkDerivation`
which disable `doCheck` on `!canExecute` cross.

This is better than changing all `finalAttrs.doCheck` to
`finalAttrs.finalPackage.doCheck` because it works without conditional
`outputs` and it addresses the comment in `mkDerivation` about not using
`doCheck = true`
@Artturin Artturin force-pushed the treewidedocheckfix branch from 1b0f217 to e5becbe Compare August 17, 2025 21:01
@nixpkgs-ci nixpkgs-ci 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. 6.topic: golang Go is a high-level general purpose programming language that is statically typed and compiled. 6.topic: cuda Parallel computing platform and API labels Aug 17, 2025
@nixpkgs-ci nixpkgs-ci bot added the 12.approvals: 1 This PR was reviewed and approved by one person. label Aug 18, 2025
@nixpkgs-ci nixpkgs-ci bot added 12.approvals: 2 This PR was reviewed and approved by two persons. and removed 12.approvals: 1 This PR was reviewed and approved by one person. labels Aug 19, 2025
@ConnorBaker
Copy link
Contributor

finalAttrs.doCheck does not include the conditionals in mkDerivation which disable doCheck on !canExecute cross.

Is it a longer term goal to update the implementation of mkDerivation to provide consistent handling of doCheck across different supported arguments (like attribute set and fixed point)?

This is better than changing all finalAttrs.doCheck to finalAttrs.finalPackage.doCheck because it works without conditional outputs and it addresses the comment in mkDerivation about not using doCheck = true

By conditional outputs, do you mean entries in outputs which depend on finalAttrs or something else?

I wasn’t aware of the comment about doCheck:

# TODO(@oxij, @Ericson2314): This is here to keep the old semantics, remove when
# no package has `doCheck = true`.
doCheck' = doCheck && stdenv.buildPlatform.canExecute stdenv.hostPlatform;

I’m not sure I understand it either. Is removal referring to doCheck (so tests would happen so long as canExecute) or the whole line (so doCheck' is gone and doCheck is used directly or potentially removed as well under the assumption we should always run tests, per

# TODO(@Ericson2314): Make unconditional / resolve #33599
# Check phase
doCheck ? config.doCheckByDefault or false,
).

At any rate, if doCheck = true is an anti-pattern and people should be using the (far less ergonomic) canExecute pattern, is there a way to prevent usage of the anti-pattern or make it easier to do the right thing?

@Artturin
Copy link
Member Author

Artturin commented Aug 19, 2025

By conditional outputs, do you mean entries in outputs which depend on finalAttrs or something else?

There's a few attrs where a finalAttrs.finalPackage.... conditional can't be used because it'll cause infinite recursion, IIRC for example the env attrset(env = lib.optional finalAttrs.finalPackage...)

I’m not sure I understand it either. Is removal referring to doCheck (so tests would happen so long as canExecute) or the whole line (so doCheck' is gone and doCheck is used directly

Removal of the doCheck' internal conditional

At any rate, if doCheck = true is an anti-pattern and people should be using the (far less ergonomic) canExecute pattern, is there a way to prevent usage of the anti-pattern or make it easier to do the right thing?

It can't be seen during eval so it would have to be a lint.

@ConnorBaker
Copy link
Contributor

ConnorBaker commented Aug 21, 2025

It can't be seen during eval so it would have to be a lint.

For the short term, is it worth documenting this somewhere? Perhaps in the Nixpkgs reference manual? If not, then I think this is good to merge!

@nixpkgs-ci nixpkgs-ci bot added 12.approvals: 3+ This PR was reviewed and approved by three or more persons. and removed 12.approvals: 2 This PR was reviewed and approved by two persons. labels Aug 21, 2025
@nixpkgs-ci nixpkgs-ci bot added the 2.status: merge conflict This PR has merge conflicts with the target branch label Sep 12, 2025
@nixpkgs-ci nixpkgs-ci bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Feb 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.status: merge conflict This PR has merge conflicts with the target branch 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 6.topic: cross-compilation Building packages on a different platform than they will be used on 6.topic: cuda Parallel computing platform and API 6.topic: golang Go is a high-level general purpose programming language that is statically typed and compiled. 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. 12.approvals: 3+ This PR was reviewed and approved by three or more persons.

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

4 participants