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

stdenv.mkDerivation: support output checks with and without structuredAttrs #357054

Merged
merged 3 commits into from
Nov 30, 2024

Conversation

wolfgangwalther
Copy link
Contributor

@wolfgangwalther wolfgangwalther commented Nov 18, 2024

With a recent enough nix, there will be an eval warning when building a derivation with __structuredAttrs = true and e.g. disallowedReferences = ... With structuredAttrs, nix expects those split up in outputChecks.<output>.disallowedReferences etc. instead.

To allow derivations to support both structuredAttrs enabled and disabled during a transition period, this PR maps top-level disallowedReferences and friends to each output's outputChecks. This has the nice side-effect that it is possible to define checks which should apply to all outputs at the top-level, and extend them with output-specific checks as well.

While on it, we also apply the same fix that #211783 did to those structured outputChecks, which had not been the case before.

Part of the overall effort to enable structuredAttrs by default eventually, tracking: #205690

Marking as draft for now, because I intend to add some tests as well. It's really annoying to write tests for this, because we effectively need to test a nix-build failure :/

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/)
  • 25.05 Release Notes (or backporting 24.11 and 25.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.

Copy link
Member

@Ma27 Ma27 left a comment

Choose a reason for hiding this comment

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

sgtm 👍

@wegank wegank added 12.approvals: 1 This PR was reviewed and approved by one reputable person 12.approved-by: package-maintainer This PR was reviewed and approved by a maintainer listed in the package labels Nov 23, 2024
This just moves the code around a little bit to be able to build on it
in follow up commits without too much of a diff.

Adding to removedOrReplacedAttrNames is just a cleanup right now and
doesn't change anything functionally, yet. This will be required for
later on to avoid having structured outputChecks and those directly on
the derivation at the same time.
…hecks

This was added for non-structuredAttrs output checks in NixOS#211783. Here we
extend the same concept to structuredAttrs-enabled outputChecks, too.

The postgresql package worked around this with some conditionals. Those
can now be removed - without causing LLVM to be built or substituted.
Once __structuredAttrs are enabled, nix only supports
disallowedReferences and friends inside the outputChecks attribute set,
defined specifically for each output.

Top-level disallowedReferences, as used throughout nixpkgs without
structuredAttrs, throws a warning instead:

  warning: In a derivation named 'perl-5.40.0', 'structuredAttrs'
  disables the effect of the derivation attribute
  'disallowedReferences'; use
  'outputChecks.<output>.disallowedReferences' instead

To support a seamless migration to enabling structuredAttrs by default,
those derivation attributes are now mapped to each output separately
when structuredAttrs are enabled.

Since both top-level disallowedReferences and outputChecks can be given
at the same time, those are now merged together. One package that can be
simplified this way is neovim, because all checks should be applied to
all outputs anyway.
@wolfgangwalther wolfgangwalther changed the base branch from master to staging November 25, 2024 17:46
@wolfgangwalther wolfgangwalther force-pushed the structured-attrs-output-checks branch from c87e982 to d37f90a Compare November 25, 2024 17:46
@wolfgangwalther
Copy link
Contributor Author

Rebased to target staging, because of the number of rebuilds.

@wolfgangwalther
Copy link
Contributor Author

re rebuilds: IIUC, those are caused by adding empty outputChecks.<each-output> = {} to all derivations which already use structuredAttrs. This could be prevented, but only at the cost of readability of the code, I think. Those empty outputChecks should not do any harm.

Copy link
Contributor

@philiptaron philiptaron left a comment

Choose a reason for hiding this comment

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

Makes sense to me.

@wegank wegank added 12.approvals: 2 This PR was reviewed and approved by two reputable people and removed 12.approvals: 1 This PR was reviewed and approved by one reputable person labels Nov 25, 2024
@ofborg ofborg bot requested a review from Ma27 November 26, 2024 13:55
@Ma27 Ma27 merged commit 65b948d into NixOS:staging Nov 30, 2024
31 checks passed
@wolfgangwalther wolfgangwalther deleted the structured-attrs-output-checks branch November 30, 2024 11:52
Comment on lines +496 to +501
}) // lib.optionalAttrs (!__structuredAttrs) (
makeOutputChecks attrs
) // lib.optionalAttrs (__structuredAttrs) {
outputChecks = builtins.listToAttrs (map (name: {
inherit name;
value = lib.zipAttrsWith (_: builtins.concatLists) [
Copy link
Member

Choose a reason for hiding this comment

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

The functions should be inherited from lib at the top of the file for improved perf

@Artturin
Copy link
Member

Artturin commented Dec 1, 2024

Not great performance-wise
image
(ignore cpuTime)

@wolfgangwalther
Copy link
Contributor Author

Not great performance-wise

How can I run those performance tests myself?

(ignore cpuTime)

What else should I be looking at, then?

In general: Is there some documentation somewhere on writing performant nix code for such heavily used code paths as mkDerivation?

wolfgangwalther added a commit to wolfgangwalther/nixpkgs that referenced this pull request Dec 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: stdenv Standard environment 10.rebuild-darwin: 501+ 10.rebuild-darwin: 5001+ 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild 10.rebuild-linux: 501+ 10.rebuild-linux: 5001+ 12.approvals: 2 This PR was reviewed and approved by two reputable people 12.approved-by: package-maintainer This PR was reviewed and approved by a maintainer listed in the package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants