Commit 7a8b1426 authored by nixdrin's avatar nixdrin
Browse files

jetbrains: use -Djna.libary.path instead of LD_LIBRARY_PATH

Most of the libraries listed in the LD_LIBRARY_PATH for the Jetbrains
IDEs are loaded indirectly using JNA in Java code, e.g.

  myLibNotify = Native.load("libnotify.so.4", LibNotify.class); [1]
  private val library = Native.load("secret-1", SecretLibrary::class.java) [2]

In this case the typical patching mechanism with Nix does not work
because JNA does the library lookup at runtime with its own mechanism.

However, to avoid causing ABI conflicts when using Nix in the terminal
of the IDE it's better to avoid using LD_LIBRARY_PATH. JNA also looks
for a "jna.library.path" Java system property when looking for libraries.

Generate that property with the needed paths instead and append it to
the vmopts file so that the property is applied when starting the IDE.
With this the libraries only become available for the IDE and do not
leak into terminals opened within the IDE context.

[1]: https://github.com/JetBrains/intellij-community/blob/c0a703267a671bbbac2384fc226c82b2203db72b/platform/platform-impl/src/com/intellij/ui/LibNotifyWrapper.java#L40
[2]: https://github.com/JetBrains/intellij-community/blob/c0a703267a671bbbac2384fc226c82b2203db72b/platform/credential-store/src/linuxSecretLibrary.kt#L38
parent 8ff6850f
Loading
Loading
Loading
Loading
+16 −6
Original line number Diff line number Diff line
@@ -89,6 +89,21 @@ with stdenv; lib.makeOverridable mkDerivation (rec {
    if [ -d "plugins/remote-dev-server" ]; then
      patch -p1 < ${./JetbrainsRemoteDev.patch}
    fi

    vmopts_file=bin/linux/${vmoptsName}
    if [[ ! -f $vmopts_file ]]; then
      vmopts_file=bin/${vmoptsName}
      if [[ ! -f $vmopts_file ]]; then
        echo "ERROR: $vmopts_file not found"
        exit 1
      fi
    fi
    echo -Djna.library.path=${lib.makeLibraryPath ([
      libsecret e2fsprogs libnotify
      # Required for Help -> Collect Logs
      # in at least rider and goland
      udev
    ])} >> $vmopts_file
  '';

  installPhase = ''
@@ -106,12 +121,7 @@ with stdenv; lib.makeOverridable mkDerivation (rec {

    wrapProgram  "$out/$pname/bin/${loName}.sh" \
      --prefix PATH : "$out/libexec/${pname}:${lib.makeBinPath [ jdk coreutils gnugrep which git python3 ]}" \
      --prefix LD_LIBRARY_PATH : "${lib.makeLibraryPath ([
        libsecret e2fsprogs libnotify
        # Required for Help -> Collect Logs
        # in at least rider and goland
        udev
      ] ++ extraLdPath)}" \
      --prefix LD_LIBRARY_PATH : "${lib.makeLibraryPath extraLdPath}" \
      ${lib.concatStringsSep " " extraWrapperArgs} \
      --set-default JDK_HOME "$jdk" \
      --set-default ANDROID_JAVA_HOME "$jdk" \