NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.73k stars 13.85k forks source link

Add support for darwin to jetbrains jdk #84263

Open ldeck opened 4 years ago

ldeck commented 4 years ago

Describe the bug The jetbrains jdk from nix blocks installation of jetbrains editors on darwin.

To Reproduce Steps to reproduce the behavior:

  1. nix-env -i idea-community idea-ultimate

Expected behavior Success

Related Issues See #56549 — Java: multiple variations to install zulu on darwin and linux

Additional context The jetbrains editors support darwin, but won’t install out of the box because the jbrsdk in nixpkgs (i.e., jetbrains jdk) currently only supports linux.

The jetbrains runtime is, however, available for darwin.

The jetbrains jdk from nixpkgs overrides openjdk11 at this time. Neither currently support darwin. Both are publicly available for darwin.

Using an overlay like the following installation of jetbrains editors succeeds.

self: super:
{
  jetbrains = super.jetbrains // {
    jdk = super.stdenv.mkDerivation rec {
      pname = "jetbrainsjdk";
      version = "702.1";
      darwinVersion = "11_0_6-osx-x64-b${version}";

      src = super.fetchurl {
    url = "https://bintray.com/jetbrains/intellij-jbr/download_file?file_path=jbrsdk-${darwinVersion}.tar.gz";
    sha256 = "1ra33mp71awhmzf735dq7hxmx9gffsqj9cdp51k5xdmnmb66g12s";
      };

      nativeBuildInputs = [ super.file ];
      unpackCmd = "mkdir jdk; pushd jdk; tar -xzf $src; popd";
      installPhase = ''
    cd ..;
    mv $sourceRoot/jbrsdk $out;
      '';

      passthru.home = "${self.jetbrains.jdk}/Contents/Home";

      meta = with super.stdenv.lib; {
    description = "An OpenJDK fork to better support Jetbrains's products.";
    longDescription = ''
      JetBrains Runtime is a runtime environment for running IntelliJ Platform
      based products on Windows, Mac OS X, and Linux. JetBrains Runtime is
      based on OpenJDK project with some modifications. These modifications
      include: Subpixel Anti-Aliasing, enhanced font rendering on Linux, HiDPI
      support, ligatures, some fixes for native crashes not presented in
      official build, and other small enhancements.

      JetBrains Runtime is not a certified build of OpenJDK. Please, use at
      your own risk.
    '';
    homepage = "https://bintray.com/jetbrains/intellij-jdk/";
    documentation = "https://confluence.jetbrains.com/display/JBR/JetBrains+Runtime";
    license = licenses.gpl2;
    maintainers = with maintainers; [ edwtjo ];
    platforms = with platforms; [ "x86_64-linux" "x86_64-darwin" ];
      };
    };
  };
}

Metadata

% nix-shell -p nix-info --run "nix-info -m"
these paths will be fetched (1.46 MiB download, 7.88 MiB unpacked):
  /nix/store/035ypsc5cwpb0mxg3vis9q6lxp3wvjsl-bash-interactive-4.4-p23
  /nix/store/cgrsbqls5vxc91sm2nsk6j4lrmpx1cdb-bash-interactive-4.4-p23-man
  /nix/store/d53m2iyciyz9g1ya49awgf66gdkfrhci-readline-7.0p5
  /nix/store/f66c7p1j3hxmglcwqvsjghbafqxv7y5a-nix-info
  /nix/store/g9mldq38hm6yxigz90vswv2d57my794j-bash-interactive-4.4-p23-info
  /nix/store/ifb3hl9gpvcg429rlz5a6hx8plf92yww-bash-interactive-4.4-p23-doc
  /nix/store/rfynznfz5ckpvyrdxwhc4sm8q9sikqq8-bash-interactive-4.4-p23-dev
  /nix/store/vsykql6171j54wn2m2bqpjnygxp30dwi-DarwinTools-1
copying path '/nix/store/ifb3hl9gpvcg429rlz5a6hx8plf92yww-bash-interactive-4.4-p23-doc' from 'https://cache.nixos.org'...
copying path '/nix/store/vsykql6171j54wn2m2bqpjnygxp30dwi-DarwinTools-1' from 'https://cache.nixos.org'...
copying path '/nix/store/g9mldq38hm6yxigz90vswv2d57my794j-bash-interactive-4.4-p23-info' from 'https://cache.nixos.org'...
copying path '/nix/store/cgrsbqls5vxc91sm2nsk6j4lrmpx1cdb-bash-interactive-4.4-p23-man' from 'https://cache.nixos.org'...
copying path '/nix/store/f66c7p1j3hxmglcwqvsjghbafqxv7y5a-nix-info' from 'https://cache.nixos.org'...
copying path '/nix/store/d53m2iyciyz9g1ya49awgf66gdkfrhci-readline-7.0p5' from 'https://cache.nixos.org'...
copying path '/nix/store/035ypsc5cwpb0mxg3vis9q6lxp3wvjsl-bash-interactive-4.4-p23' from 'https://cache.nixos.org'...
copying path '/nix/store/rfynznfz5ckpvyrdxwhc4sm8q9sikqq8-bash-interactive-4.4-p23-dev' from 'https://cache.nixos.org'...
 - system: `"x86_64-darwin"`
 - host os: `Darwin 19.4.0, macOS 10.15.4`
 - multi-user?: `no`
 - sandbox: `no`
 - version: `nix-env (Nix) 2.3.3`
 - channels(ldeck): `"nixpkgs-20.09pre218717.05f0934825c"`
 - nixpkgs: `/Users/ldeck/.nix-defexpr/channels/nixpkgs`

Maintainer information:

# a list of nixpkgs attributes affected by the problem
attribute:
  - jetbrains.clion
  - jetbrains.datagrip
  - jetbrains.goland
  - jetbrains.idea-community
  - jetbrains.idea-ultimate
  - jetbrains.jdk
  - jetbrains-mono
  - jetbrains.phpstorm
  - jetbrains.pycharm-community
  - jetbrains.pycharm-professional
  - jetbrains.rider
  - jetbrains.ruby-mine
  - jetbrains.webstorm
# a list of nixos modules affected by the problem
module:
stale[bot] commented 4 years ago

Hello, I'm a bot and I thank you in the name of the community for opening this issue.

To help our human contributors focus on the most-relevant reports, I check up on old issues to see if they're still relevant. This issue has had no activity for 180 days, and so I marked it as stale, but you can rest assured it will never be closed by a non-human.

The community would appreciate your effort in checking if the issue is still valid. If it isn't, please close it.

If the issue persists, and you'd like to remove the stale label, you simply need to leave a comment. Your comment can be as simple as "still important to me". If you'd like it to get more attention, you can ask for help by searching for maintainers and people that previously touched related code and @ mention them in a comment. You can use Git blame or GitHub's web interface on the relevant files to find them.

Lastly, you can always ask for help at our Discourse Forum or at #nixos' IRC channel.

ldeck commented 4 years ago

This would still be great to solve.

tw commented 3 years ago

@edwtjo @petabyteboy apologies for the notification, do either of you have any interest in fixing this?

I'm happy to try and help if I can, I've actually played around with this locally (very new to Nix) and managed to clobber something together, although it could definitely be better (I didn't worry about getting the same version for example).

Primarily I'd love some advice on how to do the Darwin specific stuff, I saw other packages using a darwin.nix file

  src =
    if stdenv.isDarwin then
      fetchurl {
        url = "https://bintray.com/jetbrains/intellij-jbr/download_file?file_path=jbrsdk-11_0_10-osx-x64-b1341.2.tar.gz";
        sha256 = "0x9nhjb6dnj8v63l9lkd1nb4w7gfkyz446bsjcazpfqmwayd0hpz";
      }
    else
      fetchFromGitHub {
        owner = "JetBrains";
        repo = "JetBrainsRuntime";
        rev = "jb${lib.replaceStrings ["."] ["_"] version}";
        sha256 = "1gxqi6dkyriv9j29ppan638w1ns2g9m4q1sq7arf9kwqr05zim90";
      };
  installPhase =
    if stdenv.isDarwin then ''
      mkdir -p $out
      mv Contents/Home/* $out
      ''
    else
      oldAttrs.installPhase;

Let me know your thoughts - if either are open to fixing it that's great, if you don't have time but are willing to help me a little I'm happy to do it!

Thanks for your contributions already ❤️

ghost commented 3 years ago

For most packages there are only a few differences between the darwin build and the linux build. In these case, lib.optionals stdenv.isDarwin is used to add additional buildInputs only for the darwin build.

I haven't seen many packages where the darwin build is entirely different, but specifically for jetbrain this will probably be the case. Of course the best solution would be to fix the source-built Jetbrains.jdk on darwin, but I don't have a Mac and I don't have the motivation to put this much time into support for a proprietary operating system that's against my core values in a lot of cases and that I don't use.

So in this case someone(tm) should probably revive the old prebuilt jetbrains.jdk packaging just for darwin (or use the expression from the first post of this issue). The if stdenv.isDarwin then ... else ... pattern could be used in pkgs/top-level/all-packages.nix to point jetbrains.jdk to a different derivation, something like this:


  jetbrains = (recurseIntoAttrs (callPackages ../applications/editors/jetbrains {
    [...]
    jdk = jetbrains.jdk;
  }) // {
    jdk-sourcebuilt = callPackage ../development/compilers/jetbrains-jdk {  };
    jdk-prebuilt = callPackage ../development/compilers/jetbrains-jdk/prebuilt.nix {  };
    jdk = if stdenv.isDarwin then jetbrains.jdk-prebuilt else jetbrains.jdk-sourcebuilt;
  });

I don't think naming the file darwin.nix would make a lot of sense in this case, because the prebuilt packaging will look a lot like it would on Linux, and it could even support Linux in addition to the source-built jdk.

edwtjo commented 3 years ago

I am unfortunately also not a darwin user.

maciej-trebacz commented 3 years ago

I would be interested in testing this if someone is willing to help porting the package to Darwin. I have both Intel and ARM platforms.

stale[bot] commented 2 years ago

I marked this as stale due to inactivity. → More info