about summary refs log tree commit diff
path: root/pkgs/development/tools/jdt-language-server/default.nix
blob: 1af69700152d2d8af86b50eb57bd41f6e9e95397 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
{ lib
, stdenv
, fetchurl
, makeWrapper
, jdk
}:

stdenv.mkDerivation rec {
  pname = "jdt-language-server";
  version = "1.17.0";
  timestamp = "202210271413";

  src = fetchurl {
    url = "https://download.eclipse.org/jdtls/milestones/${version}/jdt-language-server-${version}-${timestamp}.tar.gz";
    sha256 = "sha256-3NVzL3o/8LXR94/3Yma42XHfwNEFEVrmUijkeMs/vL0=";
  };

  sourceRoot = ".";

  buildInputs = [
    jdk
  ];

  nativeBuildInputs = [
    makeWrapper
  ];

  installPhase =
    let
      # The application ships with config directories for linux and mac
      configDir = if stdenv.isDarwin then "config_mac" else "config_linux";
    in
    ''
      # Copy jars
      install -D -t $out/share/java/plugins/ plugins/*.jar

      # Copy config directories for linux and mac
      install -Dm 444 -t $out/share/config ${configDir}/*

      # Get latest version of launcher jar
      # e.g. org.eclipse.equinox.launcher_1.5.800.v20200727-1323.jar
      launcher="$(ls $out/share/java/plugins/org.eclipse.equinox.launcher_* | sort -V | tail -n1)"

      # The wrapper script will create a directory in the user's cache, copy in the config
      # files since this dir can't be read-only, and by default use this as the runtime dir.
      #
      # The following options are required as per the upstream documentation:
      #
      #   -Declipse.application=org.eclipse.jdt.ls.core.id1
      #   -Dosgi.bundles.defaultStartLevel=4
      #   -Declipse.product=org.eclipse.jdt.ls.core.product
      #   -noverify
      #   --add-modules=ALL-SYSTEM
      #   --add-opens java.base/java.util=ALL-UNNAMED
      #   --add-opens java.base/java.lang=ALL-UNNAMED
      #
      # The following options configure the server to run without writing logs to the nix store:
      #
      #   -Dosgi.sharedConfiguration.area.readOnly=true
      #   -Dosgi.checkConfiguration=true
      #   -Dosgi.configuration.cascaded=true
      #   -Dosgi.sharedConfiguration.area=$out/share/config
      #
      # Other options which the caller may change:
      #
      #   -Dlog.level:
      #     Log level.
      #     This can be overidden by setting JAVA_OPTS.
      #
      # The caller must specify the following:
      #
      #   -data:
      #     The application stores runtime data here. We set this to <cache-dir>/$PWD
      #     so that projects don't collide with each other.
      #     This can be overidden by specifying -configuration to the wrapper.
      #
      # Java options, such as -Xms and Xmx can be specified by setting JAVA_OPTS.
      #
      makeWrapper ${jdk}/bin/java $out/bin/jdt-language-server \
        --add-flags "-Declipse.application=org.eclipse.jdt.ls.core.id1" \
        --add-flags "-Dosgi.bundles.defaultStartLevel=4" \
        --add-flags "-Declipse.product=org.eclipse.jdt.ls.core.product" \
        --add-flags "-Dosgi.sharedConfiguration.area=$out/share/config" \
        --add-flags "-Dosgi.sharedConfiguration.area.readOnly=true" \
        --add-flags "-Dosgi.checkConfiguration=true" \
        --add-flags "-Dosgi.configuration.cascaded=true" \
        --add-flags "-Dlog.level=ALL" \
        --add-flags "-noverify" \
        --add-flags "\$JAVA_OPTS" \
        --add-flags "-jar $launcher" \
        --add-flags "--add-modules=ALL-SYSTEM" \
        --add-flags "--add-opens java.base/java.util=ALL-UNNAMED" \
        --add-flags "--add-opens java.base/java.lang=ALL-UNNAMED"
    '';

  meta = with lib; {
    homepage = "https://github.com/eclipse/eclipse.jdt.ls";
    description = "Java language server";
    sourceProvenance = with sourceTypes; [ binaryBytecode ];
    license = licenses.epl20;
    maintainers = with maintainers; [ matt-snider ];
  };
}