Skip to content

open{jdk{8,11,17,21,23},jfx{17,21,23}}: deduplicate#350736

Merged
thiagokokada merged 15 commits intoNixOS:staging-nextfrom
emilazy:push-supksqmwuypr
Oct 24, 2024
Merged

open{jdk{8,11,17,21,23},jfx{17,21,23}}: deduplicate#350736
thiagokokada merged 15 commits intoNixOS:staging-nextfrom
emilazy:push-supksqmwuypr

Conversation

@emilazy
Copy link
Member

@emilazy emilazy commented Oct 23, 2024

Previously, the OpenJDK and OpenJFX derivations had been copied, pasted, and modified through some 14 distinct versions. This is a maintenance nightmare and resulted in a lot of inessential build configuration drift between versions. This PR aims to deduplicate them into a single expression with conditionals for the version; it should hopefully result in zero rebuilds.

The intent here is not to do anything about the madness but simply to make it legible, so as to have a single point of reference for future refactoring. I plan to do more aggressive clean‐up and add Darwin support to the derivations later, but this is what I have for 24.11. The nice thing about Nix is that as long as the resulting derivation hashes are the same, we don’t need to worry about my refactored code having significant errors.

I also rewrote the update script code. It’s in Python now, sorry; nothing against Java, but the previous state involved bootstrapping a JDK in order to run its own update script, which made adding OpenJDK 23 more of a pain than it needed to be, and I had to rework the behaviour in order to get the correct build number version handling in future. Python is the most common language for this kind of utility script in Nixpkgs after Bash, and I tried to extensively comment the code, so hopefully this won’t pose a maintenance burden for others in future.

cc @jtojnar for the update script combinator change – sorry for making it uglier.

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.

@Infinidoge
Copy link
Contributor

Infinidoge commented Oct 23, 2024

Creating an entire Python package (and package itself) feels way overkill for an update script, which seems (hard to tell from my phone) to be contained in a single Python file. Unless there is library usage I'm not seeing, it would be preferable to condense that down to a single script file if possible.

(Which for the record, I am definitely for using Python for the update script. An entire Python package just feels a bit overkill.)

Will make a more proper review when I'm both on my laptop and feeling better

@emilazy
Copy link
Member Author

emilazy commented Oct 23, 2024

It made the development easier (since it does have external dependencies, mostly the GitHub library) and means that the linting and type‐checking can be enforced. This caught a bunch of issues while I was working on it. Since it’s used in both OpenJDK and OpenJFX, the latter of which is now in pkgs/by-name and therefore cannot directly access files outside of its own directory, it has to be its own package anyway.

Note that all the actual code is in one file. (I admit that pkgs/by-name/ni/nixpkgs-openjdk-updater/nixpkgs-openjdk-updater/src/nixpkgs_openjdk_updater/__init__.py is an absurd filename, but it matches the conventions for both Nixpkgs and tooling for Python development and packaging, so I think it’s better to be absurd than to try and contort it to go against those.)

@Infinidoge
Copy link
Contributor

I'm pretty sure it's relatively straight forward to make pyproject work in a flat directory, which would be better imo. I'd rather be slightly off of Python standards than have a tiny ancillary package with an absurd amount of boilerplate structure.

Don't know how that's done off of the top of my head, but that's more to do with me not being able to think straight right now than anything else lol. Update script structure isn't a blocker by any means, and it can be cleaned up later.

@emilazy
Copy link
Member Author

emilazy commented Oct 23, 2024

The way it is set up now allows doing e.g. uv run nixpkgs-openjdk-updater … to test it and using a standard buildPythonApplication. Given the existing by-name constraints requiring a full‐blown package, the only real boilerplate is a couple nested directories. I would prefer to stick with what Python tooling does rather than making sacrifices on the development and testing front in the absence of a strongly compelling reason to the contrary.

A bigger problem is that nixpkgs-vet isn’t happy with my interpolated JSON path. I might have to move things back to one big JSON file and eat the annoying merge conflicts that might result from updates.

@ofborg ofborg bot added the 8.has: package (new) This PR adds a new package label Oct 23, 2024
@ofborg ofborg bot requested a review from edwtjo October 23, 2024 17:34
@ofborg ofborg bot added 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux. labels Oct 23, 2024
@emilazy
Copy link
Member Author

emilazy commented Oct 23, 2024

Looks like I also have to figure out what’s causing the rebuild.

@emilazy
Copy link
Member Author

emilazy commented Oct 23, 2024

Okay, hopefully fixed both of those. Naturally it was of course an error in the OpenJDK 8 derivation that I accidentally fixed.

@emilazy
Copy link
Member Author

emilazy commented Oct 23, 2024

Still showing a rebuild? Will look into it tomorrow.

@ofborg eval

Copy link
Contributor

@Infinidoge Infinidoge left a comment

Choose a reason for hiding this comment

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

Overall looks great! Mainly some comments on code organization, plus a couple more important comments sprinkled in.

Comment on lines 334 to 407
Copy link
Contributor

Choose a reason for hiding this comment

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

Should also merge and reorder the lists here. I would be surprised if the order mattered, and IMO the extra lists make it harder to read and reason about. That said, if the order here is important, then that can be done in when the update scripts are run.

Copy link
Member Author

Choose a reason for hiding this comment

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

Flag lists are ordered. However, most of the complexity here is not related to ordering; I believe only the devendoring flags are due to that. I plan to do a major clean‐up of this derivation for the 25.05 cycle and will rationalize this then.

Comment on lines +504 to +503
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this comment by itself >=17, when the actual code it refers to is >=11?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because it was changed between 11.nix and 17.nix, and this affects the derivation hash.

Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't ls $out/lib/openjdk/bin work?

Copy link
Member Author

Choose a reason for hiding this comment

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

That would change the derivation hash.

Comment on lines +624 to +622
Copy link
Contributor

Choose a reason for hiding this comment

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

See comment near top about the double override which makes this currently redundant.

Copy link
Member Author

@emilazy emilazy Oct 24, 2024

Choose a reason for hiding this comment

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

I changed it to be like this because the OpenJDK 8 derivation incorrectly lists the non‐overridden bootstrap JDK here, making it quite useless, but affecting the derivation hash. I’ve removed the override from the function header for now so that this can correctly match the original derivation and avoid the rebuilds.

Copy link
Member

@jtojnar jtojnar left a comment

Choose a reason for hiding this comment

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

The update script changes look good to me.

Unfortunately, the logic does not translate to Nix 1:1 so we can probably only make it clearer by introducing comments.

@emilazy
Copy link
Member Author

emilazy commented Oct 24, 2024

Good idea, I’ve applied the comments. I was working out a clearer approach with less code duplication based on a fold, but then I realized that it’s not clear that the current behaviour is correct in all cases anyway, e.g. if you combine a commit update script that explicitly enumerates the changed files with a silent update script that expects the updater to infer the additional files it changes. Update scripts are a bit of a badly‐composing mess (see e.g. my inability to just reuse finalAttrs.mitmCache.updateScript in OpenJFX), I’m thinking about trying to rationalize the system for 25.05… (But thank you for adding these neat combinators!)

@emilazy
Copy link
Member Author

emilazy commented Oct 24, 2024

Base branch eval error was fixed.

@ofborg eval

@ofborg ofborg bot added the 11.by: package-maintainer This PR was created by a maintainer of all the package it changes. label Oct 24, 2024
@emilazy
Copy link
Member Author

emilazy commented Oct 24, 2024

Well, the rebuilds are not benign: they are the canary in the coal mine telling us that overriding openjfx is broken. Packages in the tree rely on that. That’s why I need to choose between the potential fixes I listed.

@thiagokokada
Copy link
Contributor

Well, the rebuilds are not benign: they are the canary in the coal mine telling us that overriding openjfx is broken. Packages in the tree rely on that. That’s why I need to choose between the potential fixes I listed.

Between the 2 options, I think the "Or just fix the few in‐tree users and accept a minor breaking change to the interface" is the most reasonable one.

@emilazy
Copy link
Member Author

emilazy commented Oct 24, 2024

I’ve renamed the parameter to openjfx_jdk, i.e. “the version of OpenJFX to use with this JDK”, following the naming convention for multi‐version packages and preferring jdk over openjdk like jdk-bootstrap in the vague hopes that there could be uniformity between different possible JDKs in the interface here. I don’t really like that parameter name at all, but I didn’t get enough sleep to think of a better one, the deadline for breaking changes is in about 10 hours, and it’s likely there will be other breaking changes in 25.05 as I do a larger clean‐up, so I think bikeshedding can wait until then unless anyone really hates the name.

This should be ready to merge once ofborg says no rebuilds.

"armv7l-linux"
"armv6l-linux"
"powerpc64le-linux"
];

Choose a reason for hiding this comment

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

Suggested change
];
++ lib.optionals atLeast17 [
"riscv64-linux"
];

This would make #343907 obsolete.

Copy link
Member Author

Choose a reason for hiding this comment

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

Would you be up for rebasing your PR after this one merges? I’d be happy to review and merge it then (though I don’t have hardware to test it out). I’ve tried to keep this PR strictly to changes that result in no change in the resulting derivations and metas here in order to separate organizing the current state of things from deciding what the state of things ought to be; keeping it purely mechanical means that this PR can’t be responsible for any regressions, should never need to be reverted, and doesn’t express any policy other than “copy‐pasted code is bad”. Not that I expect adding RISC‐V support would lead to any of those, which is why I’m happy to hit the merge button after :)

Choose a reason for hiding this comment

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

Sure, no problem.

@ofborg ofborg bot added 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-linux: 1 This PR causes 1 package to rebuild on Linux. and removed 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux. labels Oct 24, 2024
@emilazy
Copy link
Member Author

emilazy commented Oct 24, 2024

One rebuild for the updater package 🎉 🎉 🎉

This is ready now.

@thiagokokada thiagokokada merged commit 7658fc3 into NixOS:staging-next Oct 24, 2024
@thiagokokada
Copy link
Contributor

Thanks for the great work again @emilazy.

@emilazy emilazy deleted the push-supksqmwuypr branch October 24, 2024 16:44
@jlesquembre
Copy link
Member

Thanks for working on this, but I don't see the advantage of rewriting the update script.

What's the painful part of running Java in the update script? The main reason for using Java was to avoid re-implementing the version parse logic. (#306616 (comment)). Also, it looks like the Python version doesn't work as expected: https://nixpkgs-update-logs.nix-community.org/jdk23/2024-10-31.log
It updates the version to refs/tags/jdk-23.0.1+11 (BTW, why not jdk-23.0.1-ga, I find the -ga suffix more user friendly. In my opinion, the build version number should only be used for non-GA versions)

@emilazy
Copy link
Member Author

emilazy commented Nov 9, 2024

refs/tags/jdk-23.0.1+11 is a correct version to update to, what’s the problem? We deliberately pick the tags corresponding to GA releases but without the -ga suffix so that we have the build number information available. That will allow us to give proper full java -evrsion output matching other Java builds like Temurin and Zulu, which identify their builds with the full version including build number and pass that build number information down to the OpenJDK build process.

The problem with the Java dependency is that having to build an OpenJDK version to update that same OpenJDK version causes problems when adding new versions and causes huge builds when doing it on top of staging. (It also made it basically impossible for me to run on macOS, where our OpenJDK packaging still needs work.) The logic needed changing to include the build number and to handle OpenJFX repositories and I was more comfortable doing it in Python than Java, and @Infinidoge, the other maintainer who has been working on cleaning up our OpenJDK packaging, agreed that it was preferable to have it in that language. Nixpkgs maintainers that aren’t familiar with a given language ecosystem will sometimes have to use and modify these scripts, and Python is the most common language after Bash for tooling tasks like these in the tree. Since the version format is documented as a simple regular expression by OpenJDK, and the modifications to handle the OpenJFX repositories meant that it needed modifying anyway, I don’t think the duplication is a problem. I am not even sure java.lang.Runtime.Version handles the JDK 8 version format, though I admittedly did not check.

@jlesquembre
Copy link
Member

the other maintainer who has been working on cleaning up our OpenJDK packaging, agreed that it was preferable to have it in that language
It also made it basically impossible for me to run on macOS

Fair enough, I didn't consider macOS (I don't have a mac, but it'd be nice to improve the macOS build)

refs/tags/jdk-23.0.1+11 is a correct version to update to, what’s the problem?

In that case, something else is going on, or I'm missing something. The update script was executed, but I don't see a PR to update jdk23 to 23.0.1

@emilazy
Copy link
Member Author

emilazy commented Nov 10, 2024

Yeah, I’d like to get our OpenJDK and OpenJFX packages building on Darwin so that we can use a source‐built JDK on all platforms and probably drop Zulu as redundant.

I already did the update in #351025, which might be it. It’s possible there’s something else going on too, though, since r-ryantm can be a bit finnicky. If we don’t get the next batch of updates automatically I’ll look into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

8.has: package (new) This PR adds a new package 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-linux: 1 This PR causes 1 package to rebuild on Linux. 11.by: package-maintainer This PR was created by a maintainer of all the package it changes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants