scalameta / metals-vscode

Visual Studio Code extension for Metals
https://marketplace.visualstudio.com/items?itemName=scalameta.metals#overview
Apache License 2.0
297 stars 74 forks source link

Metals 1.30.0 doesn't start anymore on NixOS #1489

Closed gpremer closed 2 months ago

gpremer commented 2 months ago

Describe the bug

With the automatic upgrade of the plugin to 1.30.0 Metals can't activate anymore.

To Reproduce Steps to reproduce the behavior:

Just install version 1.30.0

Expected behavior

Metals should keep working as it did before. It should be able to work with the java installation present on the system.

Screenshots

Metals version: 1.3.0
Fetching coursier
Coursier: % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
Coursier: 0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
Coursier: 6 19.8M    6 1231k    0     0   936k      0  0:00:21  0:00:01  0:00:20 1241k
Coursier: 100 19.8M  100 19.8M    0     0  10.8M      0  0:00:01
Coursier: 0:00:01 --:--:-- 13.1M
Using coursier located at /home/me/.metals/cs
/nix/store/wjybihmnh2a38nvpn37c6094yykjy1gj-openjdk-19.0.2+7/lib/openjdk/bin/java -version:
openjdk version "19.0.2" 2023-01-17
OpenJDK Runtime Environment (build 19.0.2+7-nixos)
/nix/store/wjybihmnh2a38nvpn37c6094yykjy1gj-openjdk-19.0.2+7/lib/openjdk/bin/java -version:
OpenJDK 64-Bit Server VM (build 19.0.2+7-nixos, mixed mode, sharing)
Using Java Home: /nix/store/wjybihmnh2a38nvpn37c6094yykjy1gj-openjdk-19.0.2+7/lib/openjdk
Downloading Metals failed with the following:
spawn /home/me/.metals/cs ENOENT

Installation:

Additional context

The release notes already lay out the problem. With the new approach to allowing a different version a binary of coursier is included in the extension.

However, on NixOS, by default, arbitrary executables, such as the bundled coursier, can't be run because of linker issues. While this can be worked around, the next step would be that a Java version is downloaded that has similar problems.

Again, NixOS can be configured to allow this, but the end result is not desirable. This means that "some" version of Java will be used. That version might be different on a fellow developer's machine and a CI server. It will indeed be the same major version of Java, but it is not guaranteed to be the exact same version.

So, for example, a setting that allows bypassing the need for a download such as explicitly setting the java home for the build and server separately would fix this issue. Or reverting to the behaviour like before 1.30.0 in case coursier can't be run.

Search terms

coursier, nix, download, javahome

tgodzik commented 2 months ago

Thanks for reporting!

However, on NixOS, by default, arbitrary executables, such as the bundled coursier, can't be run because of linker issues. While this can be worked around, the next step would be that a Java version is downloaded that has similar problems.

Is that a problem here though, I see that Metals did find Java, so we will not try to download it later on. I think running the coursier binary is an issue, no?

So, for example, a setting that allows bypassing the need for a download such as explicitly setting the java home for the build and server separately would fix this issue. Or reverting to the behaviour like before 1.30.0 in case coursier can't be run.

I think falling back to previous behaviour should help.

Btw. If we find coursier on PATH we will use that and not download anything, so this could be a workaround for now.

Alternatively, we could allow people to have metals on their PATH and just run that if it's available. :thinking:

gpremer commented 2 months ago

Per your suggestion, I made coursier available in the path and as you said, no additional Java was downloaded and metals starts normally.

I'm happy with this solution, but having metals as a dependency in my flake would be clearer than requiring coursier. Especially since coursier isn't used anyway (with java being found already).

Thanks for the quick reply, the good suggestion and the great work overall.