From f822b93e0558441962ac7f18b2f39848ca75f154 Mon Sep 17 00:00:00 2001 From: Hoang Xuan Phu Date: Thu, 7 Jul 2016 20:25:35 +0800 Subject: [PATCH] android-studio: repackage in an FHS environment This commit fixes 2 main problems: - Android Studio comes with its own package manager. The current packaging approach doesn't allow such management. As a result the package is unusable (see https://github.com/NixOS/nixpkgs/issues/8650 and https://github.com/NixOS/nixpkgs/issues/14903). In this version, $ANDROID_HOME is _not_ set, allowing Android Studio to deal with the Android SDK as it pleases (typically in $HOME/Android/Sdk). - Android Studio downloads prebuilt binaries as part of the SDK. These tools (e.g. `mksdcard`) have `/lib/ld-linux.so.2` set as the interpreter. An FHS environment is used as a work around for that. --- .../editors/android-studio/default.nix | 82 +++++++++++++++++++ pkgs/applications/editors/idea/default.nix | 41 ---------- pkgs/top-level/all-packages.nix | 13 +++ 3 files changed, 95 insertions(+), 41 deletions(-) create mode 100644 pkgs/applications/editors/android-studio/default.nix diff --git a/pkgs/applications/editors/android-studio/default.nix b/pkgs/applications/editors/android-studio/default.nix new file mode 100644 index 000000000000..eea686d691de --- /dev/null +++ b/pkgs/applications/editors/android-studio/default.nix @@ -0,0 +1,82 @@ +{ bash +, buildFHSUserEnv +, coreutils +, fetchurl +, findutils +, git +, gnugrep +, gnutar +, gzip +, jdk +, libXrandr +, makeWrapper +, pkgsi686Linux +, stdenv +, unzip +, which +, writeTextFile +, zlib +}: + +let + + version = "2.1.2.0"; + build = "143.2915827"; + + androidStudio = stdenv.mkDerivation { + name = "android-studio"; + buildInputs = [ + makeWrapper + unzip + ]; + installPhase = '' + cp -r . $out + wrapProgram $out/bin/studio.sh --set PATH "${stdenv.lib.makeBinPath [ + + # Checked in studio.sh + coreutils + findutils + gnugrep + jdk + which + + # Used during setup wizard + gnutar + gzip + + # Runtime stuff + git + + ]}" --set LD_LIBRARY_PATH "${stdenv.lib.makeLibraryPath [ + # Gradle wants libstdc++.so.6 + stdenv.cc.cc.lib + # mksdcard wants 32 bit libstdc++.so.6 + pkgsi686Linux.stdenv.cc.cc.lib + # aapt wants libz.so.1 + zlib + # Support multiple monitors + libXrandr + ]}" + ''; + src = fetchurl { + url = "https://dl.google.com/dl/android/studio/ide-zips/${version}/android-studio-ide-${build}-linux.zip"; + sha256 = "0q61m8yln77valg7y6lyxlml53z387zh6fyfgc22sm3br5ahbams"; + }; + }; + + # Android Studio downloads prebuilt binaries as part of the SDK. These tools + # (e.g. `mksdcard`) have `/lib/ld-linux.so.2` set as the interpreter. An FHS + # environment is used as a work around for that. + fhsEnv = buildFHSUserEnv { + name = "android-studio-fhs-env"; + }; + +in writeTextFile { + name = "android-studio-${version}"; + destination = "/bin/android-studio"; + executable = true; + text = '' + #!${bash}/bin/bash + ${fhsEnv}/bin/android-studio-fhs-env ${androidStudio}/bin/studio.sh + ''; +} diff --git a/pkgs/applications/editors/idea/default.nix b/pkgs/applications/editors/idea/default.nix index 7bfa55d28bdd..c113b63390fa 100644 --- a/pkgs/applications/editors/idea/default.nix +++ b/pkgs/applications/editors/idea/default.nix @@ -10,33 +10,6 @@ let bnumber = with stdenv.lib; build: last (splitString "-" build); mkIdeaProduct = callPackage ./common.nix { }; - buildAndroidStudio = { name, version, build, src, license, description, wmClass }: - let drv = (mkIdeaProduct rec { - inherit name version build src wmClass jdk; - product = "Studio"; - meta = with stdenv.lib; { - homepage = https://developer.android.com/sdk/installing/studio.html; - inherit description license; - longDescription = '' - Android development environment based on IntelliJ - IDEA providing new features and improvements over - Eclipse ADT and will be the official Android IDE - once it's ready. - ''; - platforms = platforms.linux; - hydraPlatforms = []; # Depends on androidsdk, which hits Hydra's output limits - maintainers = with maintainers; [ edwtjo ]; - }; - }); - in stdenv.lib.overrideDerivation drv (x : { - buildInputs = x.buildInputs ++ [ makeWrapper ]; - installPhase = x.installPhase + '' - wrapProgram "$out/bin/android-studio" \ - --set ANDROID_HOME "${androidsdk}/libexec/" \ - --set LD_LIBRARY_PATH "${stdenv.cc.cc.lib}/lib" # Gradle installs libnative-platform.so in ~/.gradle, that requires libstdc++.so.6 - ''; - }); - buildClion = { name, version, build, src, license, description, wmClass }: (mkIdeaProduct rec { inherit name version build src wmClass jdk; @@ -148,20 +121,6 @@ in { - android-studio = let buildNumber = "143.2915827"; in buildAndroidStudio rec { - name = "android-studio-${version}"; - version = "2.1.2.0"; - build = "AI-${buildNumber}"; - description = "Android development environment based on IntelliJ IDEA"; - license = stdenv.lib.licenses.asl20; - src = fetchurl { - url = "https://dl.google.com/dl/android/studio/ide-zips/${version}" + - "/android-studio-ide-${buildNumber}-linux.zip"; - sha256 = "0q61m8yln77valg7y6lyxlml53z387zh6fyfgc22sm3br5ahbams"; - }; - wmClass = "jetbrains-studio"; - }; - clion = buildClion rec { name = "clion-${version}"; version = "1.2.5"; diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 7d0ba0533e9e..77c7a386d69e 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -12263,6 +12263,19 @@ in amsn = callPackage ../applications/networking/instant-messengers/amsn { }; + # Oracle JDK is recommended upstream, but unfree and requires a manual + # download. OpenJDK is straightforward, but may suffer from compatibility + # problems e.g. https://code.google.com/p/android/issues/detail?id=174496. + # To use Oracle JDK add an override to ~/.nixpkgs/config.nix: + # { + # packageOverrides = pkgs: { + # android-studio = pkgs.android-studio.override { + # jdk = pkgs.oraclejdk8; + # }; + # }; + # } + android-studio = callPackage ../applications/editors/android-studio { }; + antimony = qt5.callPackage ../applications/graphics/antimony {}; antiword = callPackage ../applications/office/antiword {};