Skip to content

jdk{8,11,17,23,24}: always enable __structuredAttrs; cleanup#425773

Merged
symphorien merged 2 commits intoNixOS:stagingfrom
limwa:fix/enable-structured-attrs-jdk8
Jul 27, 2025
Merged

jdk{8,11,17,23,24}: always enable __structuredAttrs; cleanup#425773
symphorien merged 2 commits intoNixOS:stagingfrom
limwa:fix/enable-structured-attrs-jdk8

Conversation

@limwa
Copy link
Contributor

@limwa limwa commented Jul 16, 2025

Re-enables __structuredAttrs in jdk8.

Because the getAllOutputNames function returns different results depending on the value of __structuredAttrs, and the LIBDIRS variable needs to be constructed in a given order, the build for jdk8 fails with __structuredAttrs = true. The outputs should be patched separately to avoid having a cycle between outputs.

As such, I've simplified the postFixup hook to use autoPatchelf individually on each output. Using autoPatchelf retains the old behavior and introduces other checks such as erroring when a library dependency cannot be satisfied.

Relevant issue: #425323 (comment)
Follow up to: #425561

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/)
  • Nixpkgs 25.11 Release Notes (or backporting 25.05 Nixpkgs Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
  • NixOS 25.11 Release Notes (or backporting 25.05 NixOS Release notes)
    • (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, pkgs/README.md, maintainers/README.md and other contributing documentation in corresponding paths.

Add a 👍 reaction to pull requests you find important.

@limwa
Copy link
Contributor Author

limwa commented Jul 16, 2025

Things to consider:

  • should we update mkDerivation to retain the old getAllOutputNames behavior? This would trigger a rebuild for all packages in nixpkgs with __structuredAttrs = true...
  • should we rework the postFixup hook?
  • to reduce rebuilds, I can change the derivation to only use concatStringsSep on JDK8. Do I do this?

@nixpkgs-ci nixpkgs-ci bot added 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1001-2500 This PR causes many rebuilds on Linux and should target the staging branches. 6.topic: java Including JDK, tooling, other languages, other VMs labels Jul 16, 2025
@nixpkgs-ci nixpkgs-ci bot added the 9.needs: reviewer This PR currently has no reviewers requested and needs attention. label Jul 16, 2025
@Infinidoge
Copy link
Contributor

Hello mass rebuild. Ideally the root cause for why there is a difference in the function before/after structured attrs would be sorted out without a universe rebuild, however if no solution can be found then I think it is worth doing, as this is a huge oversight.

@limwa
Copy link
Contributor Author

limwa commented Jul 16, 2025

Hey there! I'll change the code to only apply the workaround for JDK8, that should reduce rebuilds significantly!

@limwa limwa force-pushed the fix/enable-structured-attrs-jdk8 branch from f80d3c7 to 6f6098a Compare July 16, 2025 12:54
@nixpkgs-ci nixpkgs-ci bot added 10.rebuild-linux: 101-500 This PR causes between 101 and 500 packages to rebuild on Linux. and removed 9.needs: reviewer This PR currently has no reviewers requested and needs attention. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 1001-2500 This PR causes many rebuilds on Linux and should target the staging branches. labels Jul 16, 2025
@limwa limwa force-pushed the fix/enable-structured-attrs-jdk8 branch from 6f6098a to f89e9d8 Compare July 16, 2025 13:01
@limwa
Copy link
Contributor Author

limwa commented Jul 16, 2025

Alright, I've changed the code and rebuilds are now at 101-500.

@Infinidoge
Copy link
Contributor

That's a lot better, good catch

@symphorien
Copy link
Member

in my opinion it is better to target staging and change for the better code now. Conditionals to prevent a mass rebuild like that are only useful to get a change quicker to master until it can be cleaned up in a mass rebuild, but there is no rush to enable debuginfo for jdk8.

@limwa
Copy link
Contributor Author

limwa commented Jul 16, 2025

in my opinion it is better to target staging and change for the better code now. Conditionals to prevent a mass rebuild like that are only useful to get a change quicker to master until it can be cleaned up in a mass rebuild, but there is no rush to enable debuginfo for jdk8.

I don't really have an opinion on this, I'm open to whatever is preferred. If we go through with the mass rebuild, do you think it would be better to do this for all derivations with __structuredAttrs = true (i.e. put these changes into "mkDerivation") instead? Or do we just do it for this derivation?

@symphorien
Copy link
Member

depends how you feel about fixing all occurences in nixpkgs :) but a change local to openjdk is fine by me.

@limwa
Copy link
Contributor Author

limwa commented Jul 16, 2025

depends how you feel about fixing all occurences in nixpkgs :) but a change local to openjdk is fine by me.

My "best fix" atm is to add another env variable in make-derivation.nix that has the order of the outputs. getAllOutputNames would use this variable instead of the outputs variable. So, in theory, the fix would be only a few lines and quite easy to implement. The problem is it would rebuild all derivations with __structuredAttrs = true and all other derivations that rely on those (so, in practice, a universe rebuild).

The problem with that approach is that derivations that use $outputs would not be fixed. Maybe we could overwrite the outputs array with the correct order right after sourcing .attrs.sh?

@nyabinary
Copy link
Contributor

+1 to the doing the code and targeting for staging instead :P better than a hack tbh

@limwa limwa force-pushed the fix/enable-structured-attrs-jdk8 branch from f89e9d8 to 4d187ee Compare July 17, 2025 02:57
@limwa limwa changed the base branch from master to staging July 17, 2025 02:57
@nixpkgs-ci nixpkgs-ci bot closed this Jul 17, 2025
@limwa limwa force-pushed the fix/enable-structured-attrs-jdk8 branch 4 times, most recently from b4bab36 to 9891244 Compare July 17, 2025 22:34
@limwa
Copy link
Contributor Author

limwa commented Jul 17, 2025

Turns out autoPatchelf can be used to dramatically simplify the postFixup hook.
I don't think it can get simpler than this... The PR is ready!

@wolfgangwalther wolfgangwalther requested review from wolfgangwalther and removed request for wolfgangwalther July 19, 2025 17:00
Copy link
Contributor

Choose a reason for hiding this comment

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

Came here because I wanted to see how you dealt with getAllOutputNames.. glad to see you just removed it. Will have to keep thinking about this elsewhere, whether we can fix the order of that somehow.

Copy link
Contributor Author

@limwa limwa Jul 19, 2025

Choose a reason for hiding this comment

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

If I were to fix getAllOutputNames, it would be something like this #425773 (comment). Like the comment says, it only addresses getAllOutputNames and scripts using $outputs or ${outputs[@]} would not be fixed.

Also, in response to #425561 (comment), it was said that relying on the order of getAllOutputNames is not correct, which I tend to agree with. Imo, getAllOutputNames should only be used for applying some steps equally to all outputs, where order does not matter.

I also searched Nixpkgs for occurrences of getAllOutputNames, $outputs, ${outputs[*]}, ${outputs[@]} and there were not that many occurrences. And the places where those were being used either the order was not relevant or there was already some fix in place to ensure the order was correct (look at expect-fail.sh). Only some JDK (jdk8, jetbrains-jdk) derivations were expecting the order to be correct and those are already being fixed.

In the end, if a fix for getAllOoutputNames is provided, I think it should be temporary. More (and clearer) documentation is needed to $outputs on the nix side and to getAllOutputNames on Nixpkgs side.

Copy link
Contributor

Choose a reason for hiding this comment

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

If I were to fix getAllOutputNames, it would be something like this #425773 (comment).

I'd do it differently: I'd just sort the outputs both with and without structuredAttrs alphabetically. That's consistent and rather simple to do.

It implies the same, though: Scripts should not rely on a specific order of these.

Copy link
Contributor Author

@limwa limwa Jul 23, 2025

Choose a reason for hiding this comment

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

@wolfgangwalther it appears this code in multiple-outputs.sh that relies on outputs having a fixed order when returned by getAllOutputNames

local outputFirst
for outputFirst in $(getAllOutputNames); do
break
done

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for finding this. I added it as a note to the tracking issue in #205690.

@limwa
Copy link
Contributor Author

limwa commented Jul 21, 2025

I just saw the review comments on #350736. Would you like me to address some of those (removing strings with just comments, fixing disallowedReferences for JDK8, ...) or do I just leave the PR as-is?

@nyabinary
Copy link
Contributor

I just saw the review comments on #350736. Would you like me to address some of those (removing strings with just comments, fixing disallowedReferences for JDK8, ...) or do I just leave the PR as-is?

You can honestly probably do it and then add ;cleanup to it (do it in a different commit though)

@limwa limwa force-pushed the fix/enable-structured-attrs-jdk8 branch from 9891244 to 1149111 Compare July 23, 2025 13:25
Copy link
Contributor Author

Choose a reason for hiding this comment

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

patchShebangs replaces /bin/bash automatically

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It appears setJavaClassPath is also propagated for jdk8, although it is done in the installPhase

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Previously, the build jobs were set based on the available cores on the machine and not the NIX_BUILD_CORES variable

Comment on lines 514 to 515
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed these two lines and the build was still successful, so I figured I could remove them. Should I revert?

Comment on lines -613 to -605
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is automatically set based on propagatedBuildInputs

Comment on lines 608 to 609
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Left a comment because I didn't know if this was correct or not

@limwa
Copy link
Contributor Author

limwa commented Jul 23, 2025

Did the cleanup and left some comments explaining some of the weirder changes. Other than those, the cleanup consisted of:

  • moving comments out of hooks to prevent rebuilds due to comments
  • move inputs that are always used together
  • use more common constructs (e.g lib.optionals vs ${if atLeast17 then "configurePlatforms" else null} = ...)

Built all jdk derivations and everything seems to be okay.

EDIT: it's the first time I'm doing anything like this,.so I'm especially open to suggestions! Thanks!

@limwa limwa changed the title jdk{8,11,17,23,24}: always enable __structuredAttrs jdk{8,11,17,23,24}: always enable __structuredAttrs; cleanup Jul 23, 2025
@nixpkgs-ci nixpkgs-ci bot added the 2.status: merge conflict This PR has merge conflicts with the target branch label Jul 24, 2025
@limwa limwa force-pushed the fix/enable-structured-attrs-jdk8 branch from 1149111 to 1bc0ebe Compare July 25, 2025 17:44
@nixpkgs-ci nixpkgs-ci bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Jul 25, 2025
@symphorien
Copy link
Member

I will merge this soon unless somebody speaks up.

@nixpkgs-ci nixpkgs-ci bot added the 12.approvals: 1 This PR was reviewed and approved by one person. label Jul 25, 2025
@symphorien symphorien merged commit 29c0b0f into NixOS:staging Jul 27, 2025
26 of 28 checks passed
@symphorien
Copy link
Member

thank you for your persistence, this kind of change is not easy.

@limwa limwa deleted the fix/enable-structured-attrs-jdk8 branch November 25, 2025 23:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: java Including JDK, tooling, other languages, other VMs 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 1001-2500 This PR causes many rebuilds on Linux and should target the staging branches. 12.approvals: 1 This PR was reviewed and approved by one person.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants