2020-11-14 02:18:52 +00:00
|
|
|
{ requireFile, autoPatchelfHook, pkgs, pkgsHostHost, pkgs_i686
|
|
|
|
, licenseAccepted ? false
|
|
|
|
}:
|
2018-11-27 19:36:27 +00:00
|
|
|
|
2020-11-14 02:18:52 +00:00
|
|
|
{ toolsVersion ? "26.1.1"
|
|
|
|
, platformToolsVersion ? "30.0.5"
|
|
|
|
, buildToolsVersions ? [ "30.0.3" ]
|
2018-11-27 19:36:27 +00:00
|
|
|
, includeEmulator ? false
|
2020-11-14 02:18:52 +00:00
|
|
|
, emulatorVersion ? "30.3.4"
|
2018-11-27 19:36:27 +00:00
|
|
|
, platformVersions ? []
|
|
|
|
, includeSources ? false
|
|
|
|
, includeSystemImages ? false
|
2020-11-14 02:18:52 +00:00
|
|
|
, systemImageTypes ? [ "google_apis_playstore" ]
|
2018-11-27 19:36:27 +00:00
|
|
|
, abiVersions ? [ "armeabi-v7a" ]
|
|
|
|
, cmakeVersions ? [ ]
|
|
|
|
, includeNDK ? false
|
2020-11-14 02:18:52 +00:00
|
|
|
, ndkVersion ? "22.0.7026061"
|
2018-11-27 19:36:27 +00:00
|
|
|
, useGoogleAPIs ? false
|
|
|
|
, useGoogleTVAddOns ? false
|
|
|
|
, includeExtras ? []
|
2020-11-14 02:18:52 +00:00
|
|
|
, repoJson ? ./repo.json
|
|
|
|
, repoXmls ? null
|
|
|
|
, extraLicenses ? []
|
2018-11-27 19:36:27 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
2021-02-10 18:38:17 +00:00
|
|
|
inherit (pkgs) stdenv lib fetchurl;
|
|
|
|
inherit (pkgs.buildPackages) makeWrapper unzip;
|
2018-11-27 19:36:27 +00:00
|
|
|
|
|
|
|
# Determine the Android os identifier from Nix's system identifier
|
|
|
|
os = if stdenv.system == "x86_64-linux" then "linux"
|
|
|
|
else if stdenv.system == "x86_64-darwin" then "macosx"
|
2019-05-09 02:45:33 +01:00
|
|
|
else throw "No Android SDK tarballs are available for system architecture: ${stdenv.system}";
|
2018-11-27 19:36:27 +00:00
|
|
|
|
2020-11-14 02:18:52 +00:00
|
|
|
# Uses mkrepo.rb to create a repo spec.
|
|
|
|
mkRepoJson = { packages ? [], images ? [], addons ? [] }: let
|
|
|
|
mkRepoRuby = (pkgs.ruby.withPackages (pkgs: with pkgs; [ slop nokogiri ]));
|
|
|
|
mkRepoRubyArguments = lib.lists.flatten [
|
|
|
|
(builtins.map (package: ["--packages" "${package}"]) packages)
|
|
|
|
(builtins.map (image: ["--images" "${image}"]) images)
|
|
|
|
(builtins.map (addon: ["--addons" "${addon}"]) addons)
|
|
|
|
];
|
|
|
|
in
|
|
|
|
stdenv.mkDerivation {
|
|
|
|
name = "androidenv-repo-json";
|
|
|
|
buildInputs = [ mkRepoRuby ];
|
|
|
|
preferLocalBuild = true;
|
|
|
|
unpackPhase = "true";
|
|
|
|
buildPhase = ''
|
|
|
|
ruby ${./mkrepo.rb} ${lib.escapeShellArgs mkRepoRubyArguments} > repo.json
|
|
|
|
'';
|
|
|
|
installPhase = ''
|
|
|
|
mv repo.json $out
|
|
|
|
'';
|
2018-11-27 19:36:27 +00:00
|
|
|
};
|
|
|
|
|
2020-11-14 02:18:52 +00:00
|
|
|
# Reads the repo JSON. If repoXmls is provided, will build a repo JSON into the Nix store.
|
|
|
|
repo = if repoXmls != null then
|
|
|
|
let
|
|
|
|
repoXmlSpec = {
|
|
|
|
packages = repoXmls.packages or [];
|
|
|
|
images = repoXmls.images or [];
|
|
|
|
addons = repoXmls.addons or [];
|
|
|
|
};
|
|
|
|
in
|
|
|
|
builtins.fromJSON (builtins.readFile "${mkRepoJson repoXmlSpec}")
|
|
|
|
else
|
|
|
|
builtins.fromJSON (builtins.readFile repoJson);
|
|
|
|
|
|
|
|
# Converts all 'archives' keys in a repo spec to fetchurl calls.
|
|
|
|
fetchArchives = attrSet:
|
|
|
|
lib.attrsets.mapAttrsRecursive
|
|
|
|
(path: value:
|
|
|
|
if (builtins.elemAt path ((builtins.length path) - 1)) == "archives" then
|
|
|
|
(builtins.listToAttrs
|
|
|
|
(builtins.map
|
|
|
|
(archive: lib.attrsets.nameValuePair archive.os (fetchurl { inherit (archive) url sha1; })) value))
|
|
|
|
else value
|
|
|
|
)
|
|
|
|
attrSet;
|
|
|
|
|
|
|
|
# Converts the repo attrset into fetch calls
|
|
|
|
packages = fetchArchives repo.packages;
|
|
|
|
system-images-packages = fetchArchives repo.images;
|
|
|
|
addons = {
|
|
|
|
addons = fetchArchives repo.addons;
|
|
|
|
extras = fetchArchives repo.extras;
|
2018-11-27 19:36:27 +00:00
|
|
|
};
|
|
|
|
|
2020-11-14 02:18:52 +00:00
|
|
|
# Converts a license name to a list of license texts.
|
|
|
|
mkLicenses = licenseName: repo.licenses.${licenseName};
|
|
|
|
|
|
|
|
# Converts a list of license names to a flattened list of license texts.
|
|
|
|
# Just used for displaying licenses.
|
|
|
|
mkLicenseTexts = licenseNames:
|
|
|
|
lib.lists.flatten
|
|
|
|
(builtins.map
|
|
|
|
(licenseName:
|
|
|
|
builtins.map
|
|
|
|
(licenseText: "--- ${licenseName} ---\n${licenseText}")
|
|
|
|
(mkLicenses licenseName))
|
|
|
|
licenseNames);
|
|
|
|
|
|
|
|
# Converts a license name to a list of license hashes.
|
|
|
|
mkLicenseHashes = licenseName:
|
|
|
|
builtins.map
|
|
|
|
(licenseText: builtins.hashString "sha1" licenseText)
|
|
|
|
(mkLicenses licenseName);
|
|
|
|
|
|
|
|
# The list of all license names we're accepting. Put android-sdk-license there
|
|
|
|
# by default.
|
|
|
|
licenseNames = lib.lists.unique ([
|
|
|
|
"android-sdk-license"
|
|
|
|
] ++ extraLicenses);
|
2018-11-27 19:36:27 +00:00
|
|
|
in
|
|
|
|
rec {
|
|
|
|
deployAndroidPackage = import ./deploy-androidpackage.nix {
|
|
|
|
inherit stdenv unzip;
|
|
|
|
};
|
|
|
|
|
|
|
|
platform-tools = import ./platform-tools.nix {
|
2019-08-17 09:48:09 +01:00
|
|
|
inherit deployAndroidPackage os autoPatchelfHook pkgs lib;
|
2019-09-09 00:38:31 +01:00
|
|
|
package = packages.platform-tools.${platformToolsVersion};
|
2018-11-27 19:36:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
build-tools = map (version:
|
|
|
|
import ./build-tools.nix {
|
2019-08-17 09:48:09 +01:00
|
|
|
inherit deployAndroidPackage os autoPatchelfHook makeWrapper pkgs pkgs_i686 lib;
|
2019-09-09 00:38:31 +01:00
|
|
|
package = packages.build-tools.${version};
|
2018-11-27 19:36:27 +00:00
|
|
|
}
|
|
|
|
) buildToolsVersions;
|
|
|
|
|
|
|
|
emulator = import ./emulator.nix {
|
2019-08-17 09:48:09 +01:00
|
|
|
inherit deployAndroidPackage os autoPatchelfHook makeWrapper pkgs pkgs_i686 lib;
|
2020-11-14 02:18:52 +00:00
|
|
|
package = packages.emulator.${emulatorVersion};
|
2018-11-27 19:36:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
platforms = map (version:
|
|
|
|
deployAndroidPackage {
|
|
|
|
inherit os;
|
2019-08-13 22:52:01 +01:00
|
|
|
package = packages.platforms.${version};
|
2018-11-27 19:36:27 +00:00
|
|
|
}
|
|
|
|
) platformVersions;
|
|
|
|
|
2018-11-27 21:31:35 +00:00
|
|
|
sources = map (version:
|
2018-11-27 19:36:27 +00:00
|
|
|
deployAndroidPackage {
|
|
|
|
inherit os;
|
2019-08-13 22:52:01 +01:00
|
|
|
package = packages.sources.${version};
|
2018-11-27 19:36:27 +00:00
|
|
|
}
|
2018-11-27 21:31:35 +00:00
|
|
|
) platformVersions;
|
2018-11-27 19:36:27 +00:00
|
|
|
|
2019-08-17 09:48:09 +01:00
|
|
|
system-images = lib.flatten (map (apiVersion:
|
2018-11-27 19:36:27 +00:00
|
|
|
map (type:
|
|
|
|
map (abiVersion:
|
2020-11-14 02:18:52 +00:00
|
|
|
if lib.hasAttrByPath [apiVersion type abiVersion] system-images-packages then
|
|
|
|
deployAndroidPackage {
|
|
|
|
inherit os;
|
|
|
|
package = system-images-packages.${apiVersion}.${type}.${abiVersion};
|
|
|
|
# Patch 'google_apis' system images so they're recognized by the sdk.
|
|
|
|
# Without this, `android list targets` shows 'Tag/ABIs : no ABIs' instead
|
|
|
|
# of 'Tag/ABIs : google_apis*/*' and the emulator fails with an ABI-related error.
|
|
|
|
patchInstructions = lib.optionalString (lib.hasPrefix "google_apis" type) ''
|
|
|
|
sed -i '/^Addon.Vendor/d' source.properties
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
else []
|
2018-11-27 19:36:27 +00:00
|
|
|
) abiVersions
|
|
|
|
) systemImageTypes
|
|
|
|
) platformVersions);
|
|
|
|
|
|
|
|
cmake = map (version:
|
|
|
|
import ./cmake.nix {
|
2019-08-17 09:48:09 +01:00
|
|
|
inherit deployAndroidPackage os autoPatchelfHook pkgs lib;
|
2019-09-09 00:38:31 +01:00
|
|
|
package = packages.cmake.${version};
|
2018-11-27 19:36:27 +00:00
|
|
|
}
|
|
|
|
) cmakeVersions;
|
|
|
|
|
|
|
|
ndk-bundle = import ./ndk-bundle {
|
2020-09-08 14:49:39 +01:00
|
|
|
inherit deployAndroidPackage os autoPatchelfHook makeWrapper pkgs pkgsHostHost lib platform-tools;
|
2019-09-09 00:38:31 +01:00
|
|
|
package = packages.ndk-bundle.${ndkVersion};
|
2018-11-27 19:36:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
google-apis = map (version:
|
|
|
|
deployAndroidPackage {
|
|
|
|
inherit os;
|
2019-08-13 22:52:01 +01:00
|
|
|
package = addons.addons.${version}.google_apis;
|
2018-11-27 19:36:27 +00:00
|
|
|
}
|
|
|
|
) (builtins.filter (platformVersion: platformVersion < "26") platformVersions); # API level 26 and higher include Google APIs by default
|
|
|
|
|
|
|
|
google-tv-addons = map (version:
|
|
|
|
deployAndroidPackage {
|
|
|
|
inherit os;
|
2019-08-13 22:52:01 +01:00
|
|
|
package = addons.addons.${version}.google_tv_addon;
|
2018-11-27 19:36:27 +00:00
|
|
|
}
|
|
|
|
) platformVersions;
|
|
|
|
|
|
|
|
# Function that automatically links all plugins for which multiple versions can coexist
|
|
|
|
linkPlugins = {name, plugins}:
|
2019-08-17 09:48:09 +01:00
|
|
|
lib.optionalString (plugins != []) ''
|
2018-11-27 19:36:27 +00:00
|
|
|
mkdir -p ${name}
|
2019-08-17 09:48:09 +01:00
|
|
|
${lib.concatMapStrings (plugin: ''
|
2018-11-27 19:36:27 +00:00
|
|
|
ln -s ${plugin}/libexec/android-sdk/${name}/* ${name}
|
|
|
|
'') plugins}
|
|
|
|
'';
|
|
|
|
|
|
|
|
# Function that automatically links a plugin for which only one version exists
|
|
|
|
linkPlugin = {name, plugin, check ? true}:
|
2019-08-17 09:48:09 +01:00
|
|
|
lib.optionalString check ''
|
2018-11-27 19:36:27 +00:00
|
|
|
ln -s ${plugin}/libexec/android-sdk/* ${name}
|
|
|
|
'';
|
|
|
|
|
|
|
|
# Links all plugins related to a requested platform
|
|
|
|
linkPlatformPlugins = {name, plugins, check}:
|
2019-08-17 09:48:09 +01:00
|
|
|
lib.optionalString check ''
|
2018-11-27 19:36:27 +00:00
|
|
|
mkdir -p ${name}
|
2019-08-17 09:48:09 +01:00
|
|
|
${lib.concatMapStrings (plugin: ''
|
2018-11-27 19:36:27 +00:00
|
|
|
ln -s ${plugin}/libexec/android-sdk/${name}/* ${name}
|
|
|
|
'') plugins}
|
|
|
|
''; # */
|
|
|
|
|
|
|
|
# This derivation deploys the tools package and symlinks all the desired
|
2020-11-14 02:18:52 +00:00
|
|
|
# plugins that we want to use. If the license isn't accepted, prints all the licenses
|
|
|
|
# requested and throws.
|
2019-01-30 02:13:41 +00:00
|
|
|
androidsdk = if !licenseAccepted then throw ''
|
2020-11-14 02:18:52 +00:00
|
|
|
${builtins.concatStringsSep "\n\n" (mkLicenseTexts licenseNames)}
|
|
|
|
|
|
|
|
You must accept the following licenses:
|
|
|
|
${lib.concatMapStringsSep "\n" (str: " - ${str}") licenseNames}
|
|
|
|
|
|
|
|
by setting nixpkgs config option 'android_sdk.accept_license = true;'.
|
2019-01-30 02:13:41 +00:00
|
|
|
'' else import ./tools.nix {
|
2019-08-17 09:48:09 +01:00
|
|
|
inherit deployAndroidPackage requireFile packages toolsVersion autoPatchelfHook makeWrapper os pkgs pkgs_i686 lib;
|
2018-11-27 19:36:27 +00:00
|
|
|
|
|
|
|
postInstall = ''
|
|
|
|
# Symlink all requested plugins
|
|
|
|
|
|
|
|
${linkPlugin { name = "platform-tools"; plugin = platform-tools; }}
|
|
|
|
${linkPlugins { name = "build-tools"; plugins = build-tools; }}
|
|
|
|
${linkPlugin { name = "emulator"; plugin = emulator; check = includeEmulator; }}
|
|
|
|
${linkPlugins { name = "platforms"; plugins = platforms; }}
|
|
|
|
${linkPlatformPlugins { name = "sources"; plugins = sources; check = includeSources; }}
|
|
|
|
${linkPlugins { name = "cmake"; plugins = cmake; }}
|
|
|
|
${linkPlugin { name = "ndk-bundle"; plugin = ndk-bundle; check = includeNDK; }}
|
|
|
|
|
2019-08-17 09:48:09 +01:00
|
|
|
${lib.optionalString includeSystemImages ''
|
2018-11-27 19:36:27 +00:00
|
|
|
mkdir -p system-images
|
2019-08-17 09:48:09 +01:00
|
|
|
${lib.concatMapStrings (system-image: ''
|
2018-11-27 19:36:27 +00:00
|
|
|
apiVersion=$(basename $(echo ${system-image}/libexec/android-sdk/system-images/*))
|
|
|
|
type=$(basename $(echo ${system-image}/libexec/android-sdk/system-images/*/*))
|
|
|
|
mkdir -p system-images/$apiVersion/$type
|
|
|
|
ln -s ${system-image}/libexec/android-sdk/system-images/$apiVersion/$type/* system-images/$apiVersion/$type
|
|
|
|
'') system-images}
|
|
|
|
''}
|
|
|
|
|
|
|
|
${linkPlatformPlugins { name = "add-ons"; plugins = google-apis; check = useGoogleAPIs; }}
|
|
|
|
${linkPlatformPlugins { name = "add-ons"; plugins = google-apis; check = useGoogleTVAddOns; }}
|
|
|
|
|
|
|
|
# Link extras
|
2019-08-17 09:48:09 +01:00
|
|
|
${lib.concatMapStrings (identifier:
|
2018-11-27 19:36:27 +00:00
|
|
|
let
|
2019-08-13 22:52:01 +01:00
|
|
|
path = addons.extras.${identifier}.path;
|
2018-11-27 19:36:27 +00:00
|
|
|
addon = deployAndroidPackage {
|
|
|
|
inherit os;
|
2019-08-13 22:52:01 +01:00
|
|
|
package = addons.extras.${identifier};
|
2018-11-27 19:36:27 +00:00
|
|
|
};
|
|
|
|
in
|
|
|
|
''
|
|
|
|
targetDir=$(dirname ${path})
|
|
|
|
mkdir -p $targetDir
|
|
|
|
ln -s ${addon}/libexec/android-sdk/${path} $targetDir
|
|
|
|
'') includeExtras}
|
|
|
|
|
|
|
|
# Expose common executables in bin/
|
|
|
|
mkdir -p $out/bin
|
|
|
|
find $PWD/tools -not -path '*/\.*' -type f -executable -mindepth 1 -maxdepth 1 | while read i
|
|
|
|
do
|
|
|
|
ln -s $i $out/bin
|
|
|
|
done
|
|
|
|
|
|
|
|
find $PWD/tools/bin -not -path '*/\.*' -type f -executable -mindepth 1 -maxdepth 1 | while read i
|
|
|
|
do
|
|
|
|
ln -s $i $out/bin
|
|
|
|
done
|
|
|
|
|
|
|
|
for i in ${platform-tools}/bin/*
|
|
|
|
do
|
|
|
|
ln -s $i $out/bin
|
|
|
|
done
|
2020-11-14 02:18:52 +00:00
|
|
|
|
|
|
|
# Write licenses
|
|
|
|
mkdir -p licenses
|
|
|
|
${lib.concatMapStrings (licenseName:
|
|
|
|
let
|
|
|
|
licenseHashes = builtins.concatStringsSep "\n" (mkLicenseHashes licenseName);
|
|
|
|
licenseHashFile = pkgs.writeText "androidenv-${licenseName}" licenseHashes;
|
|
|
|
in
|
|
|
|
''
|
|
|
|
ln -s ${licenseHashFile} licenses/${licenseName}
|
|
|
|
'') licenseNames}
|
2018-11-27 19:36:27 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|