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

jetbrains: respect boot java runtime settings #306712

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

herberteuler
Copy link
Member

@herberteuler herberteuler commented Apr 25, 2024

Description of changes

All JetBrain IDEs support setting the boot-time Java runtime, which is helpful in some cases. For example, I had the issue of error reading /nix/store/liz01j673lwb0wzkrykg39a7z388fy41-mps-2023.2/mps/lib/app.jar; Invalid CEN header (invalid zip64 extra data field size) with an old version of JetBrains MPS. Similar issues have been reported and the recommended solution at the time was to change the boot-time JDK.

This setting can be changed, for example, as described here for MPS, but also similarly for other JetBrains IDEs, by creating *.jdk files in ~/.config/JetBrains/*. JetBrain's scripts will then load them for the boot time JDKs. For example, ~/.config/JetBrains/MPS2023.3/mps.jdk is generated for MPS 2023.3 and ~/.config/JetBrains/IntelliJIdea2024.1/idea.jdk is generated for IntelliJ Ultimate 2024.1.

Unfortunately, the current wrapper scripts ignore such settings and always enforce the Java runtime chosen at installation time.

This PR fixes the wrapper scripts so that they respect boot-time JDK settings. It achieves the goal by tweaking the procedure that sets environment variables. For example, while the two variables were set directly for MPS as below:

export MPS_JDK=${MPS_JDK-'/nix/store/a9hjq76qi7acm4pfi928ih7z70d5bndj-jetbrains-jdk-jcef-17.0.8-b1000.8/lib/openjdk'}
export MPS_VM_OPTIONS=${MPS_VM_OPTIONS-''}

They are now only set when boot-time JDKs are not set, as below:

CONFIG_HOME="${XDG_CONFIG_HOME-${HOME}/.config}/JetBrains/MPS2023.3"
if [[ ! -s "$CONFIG_HOME/mps.jdk" ]]; then
    export MPS_JDK=${MPS_JDK-'/nix/store/grdjncqiwimlbgpgxvbadbnrfvybvaz6-jetbrains-jdk-jcef-21.0.3-b465.3/lib/openjdk'}
fi
export MPS_VM_OPTIONS=${MPS_VM_OPTIONS-''}
VMOPTS_PATTERN="$CONFIG_HOME/*.vmoptions"
VMOPTS="$(echo $VMOPTS_PATTERN)"
if [[ -s "$VMOPTS" ]]; then
    export MPS_VM_OPTIONS="$MPS_VM_OPTIONS $(cat "$VMOPTS")"
fi

Loading of *.jdk files is then delegated to the corresponding upstream scripts. Note also that the *.vmoptions files are also treated specially.

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.05 Release Notes (or backporting 23.05 and 23.11 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.

@herberteuler herberteuler force-pushed the fix/jetbrains-boot-java-runtime branch from 88cb12f to d5f0a46 Compare April 25, 2024 12:49
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/prs-ready-for-review/3032/4037

@herberteuler
Copy link
Member Author

@liff I am sorry to bother you. Could you please take a look at this PR as well? Many thanks!

Copy link
Contributor

@liff liff left a comment

Choose a reason for hiding this comment

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

Patching the upstream launcher script seems rather brittle. Would you be able to achieve the desired result by overriding the jdk argument, like: jetbrains.mps.override { jdk = some-other-jdk; }? Or alternatively, setting MPS_JDK to an empty string?

@herberteuler
Copy link
Member Author

Patching the upstream launcher script seems rather brittle. Would you be able to achieve the desired result by overriding the jdk argument, like: jetbrains.mps.override { jdk = some-other-jdk; }? Or alternatively, setting MPS_JDK to an empty string?

Overriding jdk requires an additional installation. It is actually nix's launcher receiving the patches, avoid setting MPS_JDK if *.jdk exists, achieving the same effect of setting it to empty. This script has to be patched; please compare the difference in the description.

@herberteuler
Copy link
Member Author

herberteuler commented Jun 8, 2024

Strictly speaking, one can also type <IDE_NAME>_JDK=$(cat ...) <ide-command> on the command line but that is fairly tedious.

@zlepper
Copy link
Contributor

zlepper commented Jun 17, 2024

Because bash always seems a bit dark magic to me, i'll have to base my comment on your issue description instead. Will this always override the boot JDK for all IDEs as long as you have one laying around in the correct directory? That seems like it could be rather problematic on updates? It also kinda goes against Nix's whole "Everything is deterministic/isolated/reproducible" thought?

I know the IDE already has a way of controlling this internally, could we do something so that can work correctly instead, or is that was this attempts to do?

@zlepper
Copy link
Contributor

zlepper commented Jun 17, 2024

Result of nixpkgs-review pr 306712 run on x86_64-linux 1

2 packages failed to build:
  • jetbrains.idea-community (jetbrains.idea-community-src)
  • jetbrains.pycharm-community (jetbrains.pycharm-community-src)
16 packages built:
  • jetbrains.clion
  • jetbrains.datagrip
  • jetbrains.dataspell
  • jetbrains.gateway
  • jetbrains.goland
  • jetbrains.idea-community-bin
  • jetbrains.idea-ultimate
  • jetbrains.mps
  • jetbrains.phpstorm
  • jetbrains.pycharm-community-bin
  • jetbrains.pycharm-professional
  • jetbrains.rider
  • jetbrains.ruby-mine
  • jetbrains.rust-rover
  • jetbrains.webstorm
  • jetbrains.writerside
error: builder for '/nix/store/6iadizj083lq495fiyx1d1frbghlhsxn-idea-community-233.13135.103.tar.gz.drv' failed with exit code 1;
       last 10 log lines:
       >    at org.jetbrains.jpsBootstrap.JpsBootstrapMain.main(JpsBootstrapMain.kt:158)
       >   at org.jetbrains.jpsBootstrap.JpsBootstrapMain.access$main(JpsBootstrapMain.kt:47)
       >     at org.jetbrains.jpsBootstrap.JpsBootstrapMain$Companion.main(JpsBootstrapMain.kt:358)
       >         at org.jetbrains.jpsBootstrap.JpsBootstrapMain.main(JpsBootstrapMain.kt)
       >
       >
       >           ###### ERROR EXIT due to FATAL error: Build finished with errors. See TC artifacts for build log. First error:
       > java:ERROR:error: release version 7 not supported
       >
       > ###### You may try to delete caches at /build/source/build/jps-bootstrap-work and retry
       For full logs, run 'nix log /nix/store/6iadizj083lq495fiyx1d1frbghlhsxn-idea-community-233.13135.103.tar.gz.drv'.
error: 1 dependencies of derivation '/nix/store/l0f0l8q8w5x05xcqxx7hiva10x98jyn3-idea-community-2024.1.3.drv' failed to build
error: builder for '/nix/store/49zhkbg2rhjkkhzw4jaxx3x7k0rf194x-pycharm-community-233.13135.95.tar.gz.drv' failed with exit code 1;
       last 10 log lines:
       >  at org.jetbrains.jpsBootstrap.JpsBootstrapMain.main(JpsBootstrapMain.kt:158)
       >   at org.jetbrains.jpsBootstrap.JpsBootstrapMain.access$main(JpsBootstrapMain.kt:47)
       >     at org.jetbrains.jpsBootstrap.JpsBootstrapMain$Companion.main(JpsBootstrapMain.kt:358)
       >         at org.jetbrains.jpsBootstrap.JpsBootstrapMain.main(JpsBootstrapMain.kt)
       >
       >
       >           ###### ERROR EXIT due to FATAL error: Build finished with errors. See TC artifacts for build log. First error:
       > java:ERROR:error: release version 7 not supported
       >
       > ###### You may try to delete caches at /build/source/build/jps-bootstrap-work and retry
       For full logs, run 'nix log /nix/store/49zhkbg2rhjkkhzw4jaxx3x7k0rf194x-pycharm-community-233.13135.95.tar.gz.drv'.
error: 1 dependencies of derivation '/nix/store/hcw8m70jg1cy4dv75y17xrp9hyz3id00-pycharm-community-2024.1.3.drv' failed to build
error: 2 dependencies of derivation '/nix/store/336hr0rlagp39dwww3zfqh77xc4fjig8-review-shell.drv' failed to build

@herberteuler
Copy link
Member Author

herberteuler commented Jun 17, 2024

Will this always override the boot JDK for all IDEs as long as you have one laying around in the correct directory? That seems like it could be rather problematic on updates? It also kinda goes against Nix's whole "Everything is deterministic/isolated/reproducible" thought?

The *.jdk and *.vmoptions files are user configuration files. They are created in JetBrain's configuration directory, which is normally located at $HOME/.config/JetBrains. For each IDE and each release, there will be a separate directory, hence there will be many such files. For example, this is what I currently have on my laptop:

$ ls ~/.config/JetBrains
CLion2023.2  DataGrip2023.3   GoLand2022.2        IntelliJIdea2023.2  IntelliJIdea2024.1.bak  MPS2023.3      PyCharm2024.1
CLion2023.3  DataGrip2024.1   IntelliJIdea2022.2  IntelliJIdea2023.3  MPS2022.3               PyCharm2022.2  WebStorm2022.2
CLion2024.1  DataSpell2023.3  IntelliJIdea2023.1  IntelliJIdea2024.1  MPS2023.2               PyCharm2023.3

$ find ~/.config/JetBrains -name '*.jdk'
/home/xgp/.config/JetBrains/MPS2023.2/mps.jdk
/home/xgp/.config/JetBrains/IntelliJIdea2023.3/idea.jdk

Here is an excerpt of the upstream script from Intellij 2024.1.3:

if [ -z "$JRE" ] && [ -s "${CONFIG_HOME}/JetBrains/IntelliJIdea2024.1/idea.jdk" ]; then
  USER_JRE=$(cat "${CONFIG_HOME}/JetBrains/IntelliJIdea2024.1/idea.jdk")
  if [ -x "$USER_JRE/bin/java" ]; then
    JRE="$USER_JRE"
  fi
fi

It will load *.jdk for the user chosen JVM runtime. Similar logic exists for all other IDEs.

To answer your first question, no, not all configurations of all IDEs are overridden at the same time. If the user selects a different JVM for a specific release of an IDE, it will be overridden for this one until they change it or remove the customization. The configurations of other IDEs are untouched. Note that different releases of a single IDE use different configurations.

In the case of updates, the user has to reassess the situation and decide whether they want to apply another override to the new configuration.

Because the *.jvm and *.vmoptions files are user configurations instead of system files, to adhere to the philosophy of reproducibility, it is better to manage them with home manager. The primary goal of nixpkgs, on the other hand, should be to provide the mechanism.

could we do something so that can work correctly instead

What this patch attempts to achieve is just this: to not set arbitrary values for the *_JDK variables in certain cases and let the upstream scripts decide which JVM to use.

@herberteuler
Copy link
Member Author

herberteuler commented Jun 17, 2024

Result of nixpkgs-review pr 306712 run on x86_64-linux 1
2 packages failed to build:

* jetbrains.idea-community (jetbrains.idea-community-src)

* jetbrains.pycharm-community (jetbrains.pycharm-community-src)

16 packages built:

error: builder for '/nix/store/6iadizj083lq495fiyx1d1frbghlhsxn-idea-community-233.13135.103.tar.gz.drv' failed with exit code 1;
       last 10 log lines:
       >    at org.jetbrains.jpsBootstrap.JpsBootstrapMain.main(JpsBootstrapMain.kt:158)
       >   at org.jetbrains.jpsBootstrap.JpsBootstrapMain.access$main(JpsBootstrapMain.kt:47)
       >     at org.jetbrains.jpsBootstrap.JpsBootstrapMain$Companion.main(JpsBootstrapMain.kt:358)
       >         at org.jetbrains.jpsBootstrap.JpsBootstrapMain.main(JpsBootstrapMain.kt)
       >
       >
       >           ###### ERROR EXIT due to FATAL error: Build finished with errors. See TC artifacts for build log. First error:
       > java:ERROR:error: release version 7 not supported
       >
       > ###### You may try to delete caches at /build/source/build/jps-bootstrap-work and retry
       For full logs, run 'nix log /nix/store/6iadizj083lq495fiyx1d1frbghlhsxn-idea-community-233.13135.103.tar.gz.drv'.
error: 1 dependencies of derivation '/nix/store/l0f0l8q8w5x05xcqxx7hiva10x98jyn3-idea-community-2024.1.3.drv' failed to build
error: builder for '/nix/store/49zhkbg2rhjkkhzw4jaxx3x7k0rf194x-pycharm-community-233.13135.95.tar.gz.drv' failed with exit code 1;
       last 10 log lines:
       >  at org.jetbrains.jpsBootstrap.JpsBootstrapMain.main(JpsBootstrapMain.kt:158)
       >   at org.jetbrains.jpsBootstrap.JpsBootstrapMain.access$main(JpsBootstrapMain.kt:47)
       >     at org.jetbrains.jpsBootstrap.JpsBootstrapMain$Companion.main(JpsBootstrapMain.kt:358)
       >         at org.jetbrains.jpsBootstrap.JpsBootstrapMain.main(JpsBootstrapMain.kt)
       >
       >
       >           ###### ERROR EXIT due to FATAL error: Build finished with errors. See TC artifacts for build log. First error:
       > java:ERROR:error: release version 7 not supported
       >
       > ###### You may try to delete caches at /build/source/build/jps-bootstrap-work and retry
       For full logs, run 'nix log /nix/store/49zhkbg2rhjkkhzw4jaxx3x7k0rf194x-pycharm-community-233.13135.95.tar.gz.drv'.
error: 1 dependencies of derivation '/nix/store/hcw8m70jg1cy4dv75y17xrp9hyz3id00-pycharm-community-2024.1.3.drv' failed to build
error: 2 dependencies of derivation '/nix/store/336hr0rlagp39dwww3zfqh77xc4fjig8-review-shell.drv' failed to build

This is due to the upgrade to JBR 21 in #318036. It will be resolved later with another PR.

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/prs-ready-for-review/3032/4267

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

Successfully merging this pull request may close these issues.

5 participants