androidenv: nixfmt

+47 -20
pkgs/development/mobile/androidenv/build-tools.nix
···
-
{deployAndroidPackage, lib, stdenv, package, os, arch, autoPatchelfHook, makeWrapper, pkgs, pkgsi686Linux, postInstall, meta}:
+
{
+
deployAndroidPackage,
+
lib,
+
stdenv,
+
package,
+
os,
+
arch,
+
autoPatchelfHook,
+
makeWrapper,
+
pkgs,
+
pkgsi686Linux,
+
postInstall,
+
meta,
+
}:
deployAndroidPackage {
inherit package os arch;
-
nativeBuildInputs = [ makeWrapper ]
-
++ lib.optionals (os == "linux") [ autoPatchelfHook ];
-
buildInputs = lib.optionals (os == "linux") [ pkgs.glibc pkgs.zlib pkgs.ncurses5 pkgs.libcxx ]
-
++ lib.optionals (os == "linux" && stdenv.isx86_64) (with pkgsi686Linux; [ glibc zlib ncurses5 ]);
-
patchInstructions = ''
-
${lib.optionalString (os == "linux") ''
-
addAutoPatchelfSearchPath $packageBaseDir/lib
-
if [[ -d $packageBaseDir/lib64 ]]; then
-
addAutoPatchelfSearchPath $packageBaseDir/lib64
-
autoPatchelf --no-recurse $packageBaseDir/lib64
-
fi
-
autoPatchelf --no-recurse $packageBaseDir
-
''}
+
nativeBuildInputs = [ makeWrapper ] ++ lib.optionals (os == "linux") [ autoPatchelfHook ];
+
buildInputs =
+
lib.optionals (os == "linux") [
+
pkgs.glibc
+
pkgs.zlib
+
pkgs.ncurses5
+
pkgs.libcxx
+
]
+
++ lib.optionals (os == "linux" && stdenv.isx86_64) (
+
with pkgsi686Linux;
+
[
+
glibc
+
zlib
+
ncurses5
+
]
+
);
+
patchInstructions =
+
''
+
${lib.optionalString (os == "linux") ''
+
addAutoPatchelfSearchPath $packageBaseDir/lib
+
if [[ -d $packageBaseDir/lib64 ]]; then
+
addAutoPatchelfSearchPath $packageBaseDir/lib64
+
autoPatchelf --no-recurse $packageBaseDir/lib64
+
fi
+
autoPatchelf --no-recurse $packageBaseDir
+
''}
-
${lib.optionalString (lib.toInt (lib.versions.major package.revision) < 33) ''
-
wrapProgram $PWD/mainDexClasses \
-
--prefix PATH : ${pkgs.jdk8}/bin
-
''}
+
${lib.optionalString (lib.toInt (lib.versions.major package.revision) < 33) ''
+
wrapProgram $PWD/mainDexClasses \
+
--prefix PATH : ${pkgs.jdk8}/bin
+
''}
-
cd $out/libexec/android-sdk
-
'' + postInstall;
+
cd $out/libexec/android-sdk
+
''
+
+ postInstall;
noAuditTmpdir = true; # The checker script gets confused by the build-tools path that is incorrectly identified as a reference to /build
inherit meta;
+16 -2
pkgs/development/mobile/androidenv/cmake.nix
···
-
{deployAndroidPackage, lib, package, os, arch, autoPatchelfHook, pkgs, stdenv, meta}:
+
{
+
deployAndroidPackage,
+
lib,
+
package,
+
os,
+
arch,
+
autoPatchelfHook,
+
pkgs,
+
stdenv,
+
meta,
+
}:
deployAndroidPackage {
inherit package os arch;
nativeBuildInputs = lib.optionals stdenv.hostPlatform.isLinux [ autoPatchelfHook ];
-
buildInputs = lib.optionals (os == "linux") [ pkgs.stdenv.cc.libc pkgs.stdenv.cc.cc pkgs.ncurses5 ];
+
buildInputs = lib.optionals (os == "linux") [
+
pkgs.stdenv.cc.libc
+
pkgs.stdenv.cc.cc
+
pkgs.ncurses5
+
];
patchInstructions = lib.optionalString (os == "linux") ''
autoPatchelf $packageBaseDir/bin
'';
+513 -276
pkgs/development/mobile/androidenv/compose-android-packages.nix
···
-
{ callPackage, stdenv, stdenvNoCC, lib, fetchurl, ruby, writeText
-
, licenseAccepted ? false, meta
+
{
+
callPackage,
+
stdenv,
+
stdenvNoCC,
+
lib,
+
fetchurl,
+
ruby,
+
writeText,
+
licenseAccepted ? false,
+
meta,
}:
-
{ repoJson ? ./repo.json
-
, repoXmls ? null
-
, repo ? (
-
# Reads the repo JSON. If repoXmls is provided, will build a repo JSON into the Nix store.
-
if repoXmls != null then
-
let
-
# Uses mkrepo.rb to create a repo spec.
-
mkRepoJson = { packages ? [], images ? [], addons ? [] }: let
-
mkRepoRuby = (ruby.withPackages (pkgs: with pkgs; [ slop nokogiri ]));
-
mkRepoRubyArguments = lib.lists.flatten [
-
(map (package: ["--packages" "${package}"]) packages)
-
(map (image: ["--images" "${image}"]) images)
-
(map (addon: ["--addons" "${addon}"]) addons)
-
];
+
{
+
repoJson ? ./repo.json,
+
repoXmls ? null,
+
repo ? (
+
# Reads the repo JSON. If repoXmls is provided, will build a repo JSON into the Nix store.
+
if repoXmls != null then
+
let
+
# Uses mkrepo.rb to create a repo spec.
+
mkRepoJson =
+
{
+
packages ? [ ],
+
images ? [ ],
+
addons ? [ ],
+
}:
+
let
+
mkRepoRuby = (
+
ruby.withPackages (
+
pkgs: with pkgs; [
+
slop
+
nokogiri
+
]
+
)
+
);
+
mkRepoRubyArguments = lib.lists.flatten [
+
(map (package: [
+
"--packages"
+
"${package}"
+
]) packages)
+
(map (image: [
+
"--images"
+
"${image}"
+
]) images)
+
(map (addon: [
+
"--addons"
+
"${addon}"
+
]) addons)
+
];
+
in
+
stdenvNoCC.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
+
'';
+
};
+
repoXmlSpec = {
+
packages = repoXmls.packages or [ ];
+
images = repoXmls.images or [ ];
+
addons = repoXmls.addons or [ ];
+
};
in
-
stdenvNoCC.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
-
'';
-
};
-
repoXmlSpec = {
-
packages = repoXmls.packages or [];
-
images = repoXmls.images or [];
-
addons = repoXmls.addons or [];
-
};
-
in
lib.importJSON "${mkRepoJson repoXmlSpec}"
-
else
-
lib.importJSON repoJson
-
)
-
, cmdLineToolsVersion ? repo.latest.cmdline-tools
-
, toolsVersion ? repo.latest.tools
-
, platformToolsVersion ? repo.latest.platform-tools
-
, buildToolsVersions ? [ repo.latest.build-tools ]
-
, includeEmulator ? false
-
, emulatorVersion ? repo.latest.emulator
-
, platformVersions ? [ repo.latest.platforms ]
-
, includeSources ? false
-
, includeSystemImages ? false
-
, systemImageTypes ? [ "google_apis" "google_apis_playstore" ]
-
, abiVersions ? [ "x86" "x86_64" "armeabi-v7a" "arm64-v8a" ]
+
else
+
lib.importJSON repoJson
+
),
+
cmdLineToolsVersion ? repo.latest.cmdline-tools,
+
toolsVersion ? repo.latest.tools,
+
platformToolsVersion ? repo.latest.platform-tools,
+
buildToolsVersions ? [ repo.latest.build-tools ],
+
includeEmulator ? false,
+
emulatorVersion ? repo.latest.emulator,
+
platformVersions ? [ repo.latest.platforms ],
+
includeSources ? false,
+
includeSystemImages ? false,
+
systemImageTypes ? [
+
"google_apis"
+
"google_apis_playstore"
+
],
+
abiVersions ? [
+
"x86"
+
"x86_64"
+
"armeabi-v7a"
+
"arm64-v8a"
+
],
# cmake has precompiles on x86_64 and Darwin platforms. Default to true there for compatibility.
-
, includeCmake ? stdenv.hostPlatform.isx86_64 || stdenv.hostPlatform.isDarwin
-
, cmakeVersions ? [ repo.latest.cmake ]
-
, includeNDK ? false
-
, ndkVersion ? repo.latest.ndk
-
, ndkVersions ? [ ndkVersion ]
-
, useGoogleAPIs ? false
-
, useGoogleTVAddOns ? false
-
, includeExtras ? []
-
, extraLicenses ? []
+
includeCmake ? stdenv.hostPlatform.isx86_64 || stdenv.hostPlatform.isDarwin,
+
cmakeVersions ? [ repo.latest.cmake ],
+
includeNDK ? false,
+
ndkVersion ? repo.latest.ndk,
+
ndkVersions ? [ ndkVersion ],
+
useGoogleAPIs ? false,
+
useGoogleTVAddOns ? false,
+
includeExtras ? [ ],
+
extraLicenses ? [ ],
}:
let
# Determine the Android os identifier from Nix's system identifier
-
os = {
+
os =
+
{
x86_64-linux = "linux";
x86_64-darwin = "macosx";
aarch64-linux = "linux";
aarch64-darwin = "macosx";
-
}.${stdenv.hostPlatform.system} or "all";
+
}
+
.${stdenv.hostPlatform.system} or "all";
# Determine the Android arch identifier from Nix's system identifier
-
arch = {
+
arch =
+
{
x86_64-linux = "x64";
x86_64-darwin = "x64";
aarch64-linux = "aarch64";
aarch64-darwin = "aarch64";
-
}.${stdenv.hostPlatform.system} or "all";
+
}
+
.${stdenv.hostPlatform.system} or "all";
# 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
-
let
-
validArchives = builtins.filter (archive:
-
let
-
isTargetOs = if builtins.hasAttr "os" archive then
-
archive.os == os || archive.os == "all" else true;
-
isTargetArch = if builtins.hasAttr "arch" archive then
-
archive.arch == arch || archive.arch == "all" else true;
-
in
-
isTargetOs && isTargetArch
-
) value;
-
packageInfo = lib.attrByPath (lib.sublist 0 (builtins.length path - 1) path) null attrSet;
-
in
-
lib.optionals (builtins.length validArchives > 0)
-
(lib.last (map (archive:
+
fetchArchives =
+
attrSet:
+
lib.attrsets.mapAttrsRecursive (
+
path: value:
+
if (builtins.elemAt path (builtins.length path - 1)) == "archives" then
+
let
+
validArchives = builtins.filter (
+
archive:
+
let
+
isTargetOs =
+
if builtins.hasAttr "os" archive then archive.os == os || archive.os == "all" else true;
+
isTargetArch =
+
if builtins.hasAttr "arch" archive then archive.arch == arch || archive.arch == "all" else true;
+
in
+
isTargetOs && isTargetArch
+
) value;
+
packageInfo = lib.attrByPath (lib.sublist 0 (builtins.length path - 1) path) null attrSet;
+
in
+
lib.optionals (builtins.length validArchives > 0) (
+
lib.last (
+
map (
+
archive:
(fetchurl {
inherit (archive) url sha1;
passthru = {
info = packageInfo;
};
})
-
) validArchives))
-
else value
-
) attrSet;
+
) validArchives
+
)
+
)
+
else
+
value
+
) attrSet;
# Converts the repo attrset into fetch calls.
allArchives = {
···
# and add recurseIntoAttrs to all of them.
allPackages =
let
-
liftedArchives = lib.attrsets.mapAttrsRecursiveCond
-
(value: !(builtins.hasAttr "archives" value))
-
(path: value:
-
if (value.archives or null) != null && (value.archives or [ ]) != [ ] then
-
lib.dontRecurseIntoAttrs value.archives
-
else
-
null
-
) allArchives;
+
liftedArchives = lib.attrsets.mapAttrsRecursiveCond (value: !(builtins.hasAttr "archives" value)) (
+
path: value:
+
if (value.archives or null) != null && (value.archives or [ ]) != [ ] then
+
lib.dontRecurseIntoAttrs value.archives
+
else
+
null
+
) allArchives;
# Creates a version key from a name.
# Converts things like 'extras;google;auto' to 'extras-google-auto'
-
toVersionKey = name:
+
toVersionKey =
+
name:
lib.optionalString (lib.match "^[0-9].*" name != null) "v"
-
+ lib.concatStringsSep "_" (lib.splitVersion (lib.replaceStrings [ ";" ] [ "-" ] name));
+
+ lib.concatStringsSep "_" (lib.splitVersion (lib.replaceStrings [ ";" ] [ "-" ] name));
-
recurse = lib.mapAttrs'
-
(name: value:
-
if builtins.isAttrs value && (value.recurseForDerivations or true) then
-
lib.nameValuePair (toVersionKey name) (lib.recurseIntoAttrs (recurse value))
-
else
-
lib.nameValuePair (toVersionKey name) value
-
);
+
recurse = lib.mapAttrs' (
+
name: value:
+
if builtins.isAttrs value && (value.recurseForDerivations or true) then
+
lib.nameValuePair (toVersionKey name) (lib.recurseIntoAttrs (recurse value))
+
else
+
lib.nameValuePair (toVersionKey name) value
+
);
in
lib.recurseIntoAttrs (recurse liftedArchives);
···
# 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);
+
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);
+
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);
+
licenseNames = lib.lists.unique (
+
[
+
"android-sdk-license"
+
]
+
++ extraLicenses
+
);
# put a much nicer error message that includes the available options.
-
check-version = packages: package: version:
+
check-version =
+
packages: package: version:
if lib.hasAttrByPath [ package version ] packages then
packages.${package}.${version}
else
throw ''
The version ${version} is missing in package ${package}.
-
The only available versions are ${builtins.concatStringsSep ", " (builtins.attrNames packages.${package})}.
+
The only available versions are ${
+
builtins.concatStringsSep ", " (builtins.attrNames packages.${package})
+
}.
'';
# Returns true if we should link the specified plugins.
-
shouldLink = check: packages:
+
shouldLink =
+
check: packages:
assert builtins.isList packages;
if check == true then
true
···
false
else if check == null || check == "if-supported" then
let
-
hasSrc = package: package.src != null && (builtins.isList package.src -> builtins.length package.src > 0);
+
hasSrc =
+
package: package.src != null && (builtins.isList package.src -> builtins.length package.src > 0);
in
-
packages != [] && lib.all hasSrc packages
+
packages != [ ] && lib.all hasSrc packages
else
throw "Invalid argument ${toString check}; use true, false, or null/if-supported";
# Function that automatically links all plugins for which multiple versions can coexist
-
linkPlugins = {name, plugins, check ? true}:
+
linkPlugins =
+
{
+
name,
+
plugins,
+
check ? true,
+
}:
lib.optionalString (shouldLink check plugins) ''
mkdir -p ${name}
${lib.concatMapStrings (plugin: ''
···
'';
# Function that automatically links all NDK plugins.
-
linkNdkPlugins = {name, plugins, rootName ? name, check ? true}:
+
linkNdkPlugins =
+
{
+
name,
+
plugins,
+
rootName ? name,
+
check ? true,
+
}:
lib.optionalString (shouldLink check plugins) ''
mkdir -p ${rootName}
${lib.concatMapStrings (plugin: ''
···
'';
# Function that automatically links the default NDK plugin.
-
linkNdkPlugin = {name, plugin, check}:
-
lib.optionalString (shouldLink check [plugin]) ''
+
linkNdkPlugin =
+
{
+
name,
+
plugin,
+
check,
+
}:
+
lib.optionalString (shouldLink check [ plugin ]) ''
ln -s ${plugin}/libexec/android-sdk/${name} ${name}
'';
# Function that automatically links a plugin for which only one version exists
-
linkPlugin = {name, plugin, check ? true}:
-
lib.optionalString (shouldLink check [plugin]) ''
+
linkPlugin =
+
{
+
name,
+
plugin,
+
check ? true,
+
}:
+
lib.optionalString (shouldLink check [ plugin ]) ''
ln -s ${plugin}/libexec/android-sdk/${name} ${name}
'';
-
linkSystemImages = { images, check }: lib.optionalString (shouldLink check images) ''
-
mkdir -p system-images
-
${lib.concatMapStrings (system-image: ''
-
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
-
ln -s ${system-image}/libexec/android-sdk/system-images/$apiVersion/$type system-images/$apiVersion/$type
-
'') images}
-
'';
+
linkSystemImages =
+
{ images, check }:
+
lib.optionalString (shouldLink check images) ''
+
mkdir -p system-images
+
${lib.concatMapStrings (system-image: ''
+
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
+
ln -s ${system-image}/libexec/android-sdk/system-images/$apiVersion/$type system-images/$apiVersion/$type
+
'') images}
+
'';
# Links all plugins related to a requested platform
-
linkPlatformPlugins = {name, plugins, check}:
+
linkPlatformPlugins =
+
{
+
name,
+
plugins,
+
check,
+
}:
lib.optionalString (shouldLink check plugins) ''
mkdir -p ${name}
${lib.concatMapStrings (plugin: ''
···
in
lib.recurseIntoAttrs rec {
deployAndroidPackages = callPackage ./deploy-androidpackages.nix {
-
inherit stdenv lib mkLicenses meta os arch;
+
inherit
+
stdenv
+
lib
+
mkLicenses
+
meta
+
os
+
arch
+
;
};
-
deployAndroidPackage = ({package, buildInputs ? [], patchInstructions ? "", meta ? {}, ...}@args:
+
deployAndroidPackage = (
+
{
+
package,
+
buildInputs ? [ ],
+
patchInstructions ? "",
+
meta ? { },
+
...
+
}@args:
let
-
extraParams = removeAttrs args [ "package" "os" "arch" "buildInputs" "patchInstructions" ];
+
extraParams = removeAttrs args [
+
"package"
+
"os"
+
"arch"
+
"buildInputs"
+
"patchInstructions"
+
];
in
-
deployAndroidPackages ({
-
inherit buildInputs;
-
packages = [ package ];
-
patchesInstructions = { "${package.name}" = patchInstructions; };
-
} // extraParams
-
));
+
deployAndroidPackages (
+
{
+
inherit buildInputs;
+
packages = [ package ];
+
patchesInstructions = {
+
"${package.name}" = patchInstructions;
+
};
+
}
+
// extraParams
+
)
+
);
all = allPackages;
platform-tools = callPackage ./platform-tools.nix {
-
inherit deployAndroidPackage os arch meta;
+
inherit
+
deployAndroidPackage
+
os
+
arch
+
meta
+
;
package = check-version allArchives.packages "platform-tools" platformToolsVersion;
};
tools = callPackage ./tools.nix {
-
inherit deployAndroidPackage os arch meta;
+
inherit
+
deployAndroidPackage
+
os
+
arch
+
meta
+
;
package = check-version allArchives.packages "tools" toolsVersion;
postInstall = ''
-
${linkPlugin { name = "platform-tools"; plugin = platform-tools; }}
-
${linkPlugin { name = "emulator"; plugin = emulator; check = includeEmulator; }}
+
${linkPlugin {
+
name = "platform-tools";
+
plugin = platform-tools;
+
}}
+
${linkPlugin {
+
name = "emulator";
+
plugin = emulator;
+
check = includeEmulator;
+
}}
'';
};
-
build-tools = map (version:
+
build-tools = map (
+
version:
callPackage ./build-tools.nix {
-
inherit deployAndroidPackage os arch meta;
+
inherit
+
deployAndroidPackage
+
os
+
arch
+
meta
+
;
package = check-version allArchives.packages "build-tools" version;
postInstall = ''
-
${linkPlugin { name = "tools"; plugin = tools; check = toolsVersion != null; }}
+
${linkPlugin {
+
name = "tools";
+
plugin = tools;
+
check = toolsVersion != null;
+
}}
'';
}
) buildToolsVersions;
-
emulator =
-
callPackage ./emulator.nix {
-
inherit deployAndroidPackage os arch meta;
-
package = check-version allArchives.packages "emulator" emulatorVersion;
+
emulator = callPackage ./emulator.nix {
+
inherit
+
deployAndroidPackage
+
os
+
arch
+
meta
+
;
+
package = check-version allArchives.packages "emulator" emulatorVersion;
-
postInstall = ''
-
${linkSystemImages { images = system-images; check = includeSystemImages; }}
-
'';
-
};
+
postInstall = ''
+
${linkSystemImages {
+
images = system-images;
+
check = includeSystemImages;
+
}}
+
'';
+
};
-
platforms = map (version:
+
platforms = map (
+
version:
deployAndroidPackage {
package = check-version allArchives.packages "platforms" version;
}
) platformVersions;
-
sources = map (version:
+
sources = map (
+
version:
deployAndroidPackage {
package = check-version allArchives.packages "sources" version;
}
) platformVersions;
-
system-images = lib.flatten (map (apiVersion:
-
map (type:
-
# Deploy all system images with the same systemImageType in one derivation to avoid the `null` problem below
-
# with avdmanager when trying to create an avd!
-
#
-
# ```
-
# $ yes "" | avdmanager create avd --force --name testAVD --package 'system-images;android-33;google_apis;x86_64'
-
# Error: Package path is not valid. Valid system image paths are:
-
# null
-
# ```
-
let
-
availablePackages = map (abiVersion:
-
allArchives.system-images.${apiVersion}.${type}.${abiVersion}
-
) (builtins.filter (abiVersion:
-
lib.hasAttrByPath [apiVersion type abiVersion] allArchives.system-images
-
) abiVersions);
+
system-images = lib.flatten (
+
map (
+
apiVersion:
+
map (
+
type:
+
# Deploy all system images with the same systemImageType in one derivation to avoid the `null` problem below
+
# with avdmanager when trying to create an avd!
+
#
+
# ```
+
# $ yes "" | avdmanager create avd --force --name testAVD --package 'system-images;android-33;google_apis;x86_64'
+
# Error: Package path is not valid. Valid system image paths are:
+
# null
+
# ```
+
let
+
availablePackages =
+
map (abiVersion: allArchives.system-images.${apiVersion}.${type}.${abiVersion})
+
(
+
builtins.filter (
+
abiVersion: lib.hasAttrByPath [ apiVersion type abiVersion ] allArchives.system-images
+
) abiVersions
+
);
-
instructions = builtins.listToAttrs (map (package: {
-
name = package.name;
-
value = lib.optionalString (lib.hasPrefix "google_apis" type) ''
-
# 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.
-
sed -i '/^Addon.Vendor/d' source.properties
-
'';
-
}) availablePackages
-
);
-
in
-
lib.optionals (availablePackages != [])
-
(deployAndroidPackages {
+
instructions = builtins.listToAttrs (
+
map (package: {
+
name = package.name;
+
value = lib.optionalString (lib.hasPrefix "google_apis" type) ''
+
# 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.
+
sed -i '/^Addon.Vendor/d' source.properties
+
'';
+
}) availablePackages
+
);
+
in
+
lib.optionals (availablePackages != [ ]) (deployAndroidPackages {
packages = availablePackages;
patchesInstructions = instructions;
})
-
) systemImageTypes
-
) platformVersions);
+
) systemImageTypes
+
) platformVersions
+
);
-
cmake = map (version:
+
cmake = map (
+
version:
callPackage ./cmake.nix {
-
inherit deployAndroidPackage os arch meta;
+
inherit
+
deployAndroidPackage
+
os
+
arch
+
meta
+
;
package = check-version allArchives.packages "cmake" version;
}
) cmakeVersions;
# All NDK bundles.
-
ndk-bundles = let
-
# Creates a NDK bundle.
-
makeNdkBundle = package:
-
callPackage ./ndk-bundle {
-
inherit deployAndroidPackage os arch platform-tools meta package;
-
};
-
in lib.flatten (
-
map (version:
-
let
-
package = makeNdkBundle (allArchives.packages.ndk-bundle.${ndkVersion} or allArchives.packages.ndk.${ndkVersion});
-
in
-
lib.optional (shouldLink includeNDK [package]) package
-
) ndkVersions
-
);
+
ndk-bundles =
+
let
+
# Creates a NDK bundle.
+
makeNdkBundle =
+
package:
+
callPackage ./ndk-bundle {
+
inherit
+
deployAndroidPackage
+
os
+
arch
+
platform-tools
+
meta
+
package
+
;
+
};
+
in
+
lib.flatten (
+
map (
+
version:
+
let
+
package = makeNdkBundle (
+
allArchives.packages.ndk-bundle.${ndkVersion} or allArchives.packages.ndk.${ndkVersion}
+
);
+
in
+
lib.optional (shouldLink includeNDK [ package ]) package
+
) ndkVersions
+
);
# The "default" NDK bundle.
-
ndk-bundle = if ndk-bundles == [] then null else lib.head ndk-bundles;
+
ndk-bundle = if ndk-bundles == [ ] then null else lib.head ndk-bundles;
# Makes a Google API bundle.
-
google-apis = map (version:
+
google-apis = map (
+
version:
deployAndroidPackage {
package = (check-version allArchives "addons" version).google_apis;
}
) (builtins.filter (platformVersion: lib.versionOlder platformVersion "26") platformVersions); # API level 26 and higher include Google APIs by default
-
google-tv-addons = map (version:
+
google-tv-addons = map (
+
version:
deployAndroidPackage {
package = (check-version allArchives "addons" version).google_tv_addon;
}
···
# This derivation deploys the tools package and symlinks all the desired
# plugins that we want to use. If the license isn't accepted, prints all the licenses
# requested and throws.
-
androidsdk = if !licenseAccepted then throw ''
-
${builtins.concatStringsSep "\n\n" (mkLicenseTexts licenseNames)}
+
androidsdk =
+
if !licenseAccepted then
+
throw ''
+
${builtins.concatStringsSep "\n\n" (mkLicenseTexts licenseNames)}
-
You must accept the following licenses:
-
${lib.concatMapStringsSep "\n" (str: " - ${str}") licenseNames}
+
You must accept the following licenses:
+
${lib.concatMapStringsSep "\n" (str: " - ${str}") licenseNames}
-
a)
-
by setting nixpkgs config option 'android_sdk.accept_license = true;'.
-
b)
-
by an environment variable for a single invocation of the nix tools.
-
$ export NIXPKGS_ACCEPT_ANDROID_SDK_LICENSE=1
-
'' else callPackage ./cmdline-tools.nix {
-
inherit deployAndroidPackage os arch meta;
+
a)
+
by setting nixpkgs config option 'android_sdk.accept_license = true;'.
+
b)
+
by an environment variable for a single invocation of the nix tools.
+
$ export NIXPKGS_ACCEPT_ANDROID_SDK_LICENSE=1
+
''
+
else
+
callPackage ./cmdline-tools.nix {
+
inherit
+
deployAndroidPackage
+
os
+
arch
+
meta
+
;
-
package = cmdline-tools-package;
+
package = cmdline-tools-package;
-
postInstall = ''
-
# Symlink all requested plugins
-
${linkPlugin { name = "platform-tools"; plugin = platform-tools; }}
-
${linkPlugin { name = "tools"; plugin = tools; check = toolsVersion != null; }}
-
${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; check = includeCmake; }}
-
${linkNdkPlugins { name = "ndk-bundle"; rootName = "ndk"; plugins = ndk-bundles; check = includeNDK; }}
-
${linkNdkPlugin { name = "ndk-bundle"; plugin = ndk-bundle; check = includeNDK; }}
-
${linkSystemImages { images = system-images; check = includeSystemImages; }}
-
${linkPlatformPlugins { name = "add-ons"; plugins = google-apis; check = useGoogleAPIs; }}
-
${linkPlatformPlugins { name = "add-ons"; plugins = google-tv-addons; check = useGoogleTVAddOns; }}
+
postInstall = ''
+
# Symlink all requested plugins
+
${linkPlugin {
+
name = "platform-tools";
+
plugin = platform-tools;
+
}}
+
${linkPlugin {
+
name = "tools";
+
plugin = tools;
+
check = toolsVersion != null;
+
}}
+
${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;
+
check = includeCmake;
+
}}
+
${linkNdkPlugins {
+
name = "ndk-bundle";
+
rootName = "ndk";
+
plugins = ndk-bundles;
+
check = includeNDK;
+
}}
+
${linkNdkPlugin {
+
name = "ndk-bundle";
+
plugin = ndk-bundle;
+
check = includeNDK;
+
}}
+
${linkSystemImages {
+
images = system-images;
+
check = includeSystemImages;
+
}}
+
${linkPlatformPlugins {
+
name = "add-ons";
+
plugins = google-apis;
+
check = useGoogleAPIs;
+
}}
+
${linkPlatformPlugins {
+
name = "add-ons";
+
plugins = google-tv-addons;
+
check = useGoogleTVAddOns;
+
}}
-
# Link extras
-
${lib.concatMapStrings (identifier:
-
let
-
package = allArchives.extras.${identifier};
-
path = package.path;
-
extras = callPackage ./extras.nix {
-
inherit deployAndroidPackage package os arch meta;
-
};
-
in
-
''
-
targetDir=$(dirname ${path})
-
mkdir -p $targetDir
-
ln -s ${extras}/libexec/android-sdk/${path} $targetDir
-
'') includeExtras}
+
# Link extras
+
${lib.concatMapStrings (
+
identifier:
+
let
+
package = allArchives.extras.${identifier};
+
path = package.path;
+
extras = callPackage ./extras.nix {
+
inherit
+
deployAndroidPackage
+
package
+
os
+
arch
+
meta
+
;
+
};
+
in
+
''
+
targetDir=$(dirname ${path})
+
mkdir -p $targetDir
+
ln -s ${extras}/libexec/android-sdk/${path} $targetDir
+
''
+
) includeExtras}
-
# Expose common executables in bin/
-
mkdir -p $out/bin
+
# Expose common executables in bin/
+
mkdir -p $out/bin
-
for i in ${platform-tools}/bin/*; do
-
ln -s $i $out/bin
-
done
+
for i in ${platform-tools}/bin/*; do
+
ln -s $i $out/bin
+
done
-
${lib.optionalString (shouldLink includeEmulator [emulator]) ''
-
for i in ${emulator}/bin/*; do
-
ln -s $i $out/bin
-
done
-
''}
+
${lib.optionalString (shouldLink includeEmulator [ emulator ]) ''
+
for i in ${emulator}/bin/*; do
+
ln -s $i $out/bin
+
done
+
''}
-
find $ANDROID_SDK_ROOT/${cmdline-tools-package.path}/bin -type f -executable | while read i; do
-
ln -s $i $out/bin
-
done
+
find $ANDROID_SDK_ROOT/${cmdline-tools-package.path}/bin -type f -executable | while read i; do
+
ln -s $i $out/bin
+
done
-
# Write licenses
-
mkdir -p licenses
-
${lib.concatMapStrings (licenseName:
-
let
-
licenseHashes = builtins.concatStringsSep "\n" (mkLicenseHashes licenseName);
-
licenseHashFile = writeText "androidenv-${licenseName}" licenseHashes;
-
in
-
''
-
ln -s ${licenseHashFile} licenses/${licenseName}
-
'') licenseNames}
-
'';
-
};
+
# Write licenses
+
mkdir -p licenses
+
${lib.concatMapStrings (
+
licenseName:
+
let
+
licenseHashes = builtins.concatStringsSep "\n" (mkLicenseHashes licenseName);
+
licenseHashFile = writeText "androidenv-${licenseName}" licenseHashes;
+
in
+
''
+
ln -s ${licenseHashFile} licenses/${licenseName}
+
''
+
) licenseNames}
+
'';
+
};
}
+2 -1
pkgs/development/mobile/androidenv/default.nix
···
lib,
config,
pkgs ? import <nixpkgs> { },
-
licenseAccepted ? config.android_sdk.accept_license or (builtins.getEnv "NIXPKGS_ACCEPT_ANDROID_SDK_LICENSE" == "1"),
+
licenseAccepted ?
+
config.android_sdk.accept_license or (builtins.getEnv "NIXPKGS_ACCEPT_ANDROID_SDK_LICENSE" == "1"),
}:
lib.recurseIntoAttrs rec {
+121 -85
pkgs/development/mobile/androidenv/deploy-androidpackages.nix
···
-
{stdenv, lib, unzip, mkLicenses, os, arch, meta}:
-
{packages, nativeBuildInputs ? [], buildInputs ? [], patchesInstructions ? {}, ...}@args:
+
{
+
stdenv,
+
lib,
+
unzip,
+
mkLicenses,
+
os,
+
arch,
+
meta,
+
}:
+
{
+
packages,
+
nativeBuildInputs ? [ ],
+
buildInputs ? [ ],
+
patchesInstructions ? { },
+
...
+
}@args:
let
-
extraParams = removeAttrs args [ "packages" "os" "buildInputs" "nativeBuildInputs" "patchesInstructions" ];
+
extraParams = removeAttrs args [
+
"packages"
+
"os"
+
"buildInputs"
+
"nativeBuildInputs"
+
"patchesInstructions"
+
];
sortedPackages = builtins.sort (x: y: builtins.lessThan x.name y.name) packages;
-
mkXmlAttrs = attrs:
-
lib.concatStrings (lib.mapAttrsToList (name: value: " ${name}=\"${value}\"") attrs);
-
mkXmlValues = attrs:
-
lib.concatStrings (lib.mapAttrsToList (name: value:
-
let
-
tag = builtins.head (builtins.match "([^:]+).*" name);
-
in
+
mkXmlAttrs =
+
attrs: lib.concatStrings (lib.mapAttrsToList (name: value: " ${name}=\"${value}\"") attrs);
+
mkXmlValues =
+
attrs:
+
lib.concatStrings (
+
lib.mapAttrsToList (
+
name: value:
+
let
+
tag = builtins.head (builtins.match "([^:]+).*" name);
+
in
if builtins.typeOf value == "string" then "<${tag}>${value}</${tag}>" else mkXmlDoc name value
-
) attrs);
-
mkXmlDoc = name: doc:
-
let
-
tag = builtins.head (builtins.match "([^:]+).*" name);
-
hasXmlAttrs = builtins.hasAttr "element-attributes" doc;
-
xmlValues = removeAttrs doc [ "element-attributes" ];
-
hasXmlValues = builtins.length (builtins.attrNames xmlValues) > 0;
-
in
-
if hasXmlAttrs && hasXmlValues then "<${tag}${mkXmlAttrs doc.element-attributes}>${mkXmlValues xmlValues }</${tag}>"
-
else if hasXmlAttrs && !hasXmlValues then "<${tag}${mkXmlAttrs doc.element-attributes}/>"
-
else if !hasXmlAttrs && hasXmlValues then "<${tag}>${mkXmlValues xmlValues}</${tag}>"
-
else "<${tag}/>";
+
) attrs
+
);
+
mkXmlDoc =
+
name: doc:
+
let
+
tag = builtins.head (builtins.match "([^:]+).*" name);
+
hasXmlAttrs = builtins.hasAttr "element-attributes" doc;
+
xmlValues = removeAttrs doc [ "element-attributes" ];
+
hasXmlValues = builtins.length (builtins.attrNames xmlValues) > 0;
+
in
+
if hasXmlAttrs && hasXmlValues then
+
"<${tag}${mkXmlAttrs doc.element-attributes}>${mkXmlValues xmlValues}</${tag}>"
+
else if hasXmlAttrs && !hasXmlValues then
+
"<${tag}${mkXmlAttrs doc.element-attributes}/>"
+
else if !hasXmlAttrs && hasXmlValues then
+
"<${tag}>${mkXmlValues xmlValues}</${tag}>"
+
else
+
"<${tag}/>";
mkXmlPackage = package: ''
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:repository
···
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<license id="${package.license}" type="text">${lib.concatStringsSep "---" (mkLicenses package.license)}</license>
<localPackage path="${builtins.replaceStrings [ "/" ] [ ";" ] package.path}" obsolete="${
-
if (lib.hasAttrByPath [ "obsolete" ] package)
-
then package.obsolete else "false"
-
}">
+
if (lib.hasAttrByPath [ "obsolete" ] package) then package.obsolete else "false"
+
}">
${mkXmlDoc "type-details" package.type-details}
${mkXmlDoc "revision" package.revision-details}
-
${lib.optionalString (lib.hasAttrByPath [ "dependencies" ] package)
-
(mkXmlDoc "dependencies" package.dependencies)
-
}
+
${lib.optionalString (lib.hasAttrByPath [ "dependencies" ] package) (
+
mkXmlDoc "dependencies" package.dependencies
+
)}
<display-name>${package.displayName}</display-name>
<uses-license ref="${package.license}"/>
</localPackage>
</ns2:repository>
'';
in
-
stdenv.mkDerivation ({
-
inherit buildInputs;
-
pname = "android-sdk-${lib.concatMapStringsSep "-" (package: package.name) sortedPackages}";
-
version = lib.concatMapStringsSep "-" (package: package.revision) sortedPackages;
-
src = lib.flatten (map (package: package.archives) packages);
-
inherit os arch;
-
nativeBuildInputs = [ unzip ] ++ nativeBuildInputs;
-
preferLocalBuild = true;
+
stdenv.mkDerivation (
+
{
+
inherit buildInputs;
+
pname = "android-sdk-${lib.concatMapStringsSep "-" (package: package.name) sortedPackages}";
+
version = lib.concatMapStringsSep "-" (package: package.revision) sortedPackages;
+
src = lib.flatten (map (package: package.archives) packages);
+
inherit os arch;
+
nativeBuildInputs = [ unzip ] ++ nativeBuildInputs;
+
preferLocalBuild = true;
-
unpackPhase = ''
-
runHook preUnpack
-
if [ -z "$src" ]; then
-
echo "$pname did not have any sources available for os=$os, arch=$arch." >&2
-
echo "Are packages available for this architecture?" >&2
-
exit 1
-
fi
-
buildDir=$PWD
-
i=0
-
for srcArchive in $src; do
-
extractedZip="extractedzip-$i"
-
i=$((i+1))
-
cd "$buildDir"
-
mkdir "$extractedZip"
-
cd "$extractedZip"
-
unpackFile "$srcArchive"
-
done
-
runHook postUnpack
-
'';
+
unpackPhase = ''
+
runHook preUnpack
+
if [ -z "$src" ]; then
+
echo "$pname did not have any sources available for os=$os, arch=$arch." >&2
+
echo "Are packages available for this architecture?" >&2
+
exit 1
+
fi
+
buildDir=$PWD
+
i=0
+
for srcArchive in $src; do
+
extractedZip="extractedzip-$i"
+
i=$((i+1))
+
cd "$buildDir"
+
mkdir "$extractedZip"
+
cd "$extractedZip"
+
unpackFile "$srcArchive"
+
done
+
runHook postUnpack
+
'';
-
installPhase = ''
-
runHook preInstall
-
'' + lib.concatStrings (lib.imap0 (i: package: ''
-
cd $buildDir/extractedzip-${toString i}
+
installPhase =
+
''
+
runHook preInstall
+
''
+
+ lib.concatStrings (
+
lib.imap0 (i: package: ''
+
cd $buildDir/extractedzip-${toString i}
-
# Most Android Zip packages have a root folder, but some don't. We unpack
-
# the zip file in a folder and we try to discover whether it has a single root
-
# folder. If this is the case, we adjust the current working folder.
-
if [ "$(find . -mindepth 1 -maxdepth 1 -type d | wc -l)" -eq 1 ]; then
-
cd "$(find . -mindepth 1 -maxdepth 1 -type d)"
-
fi
-
extractedZip="$PWD"
+
# Most Android Zip packages have a root folder, but some don't. We unpack
+
# the zip file in a folder and we try to discover whether it has a single root
+
# folder. If this is the case, we adjust the current working folder.
+
if [ "$(find . -mindepth 1 -maxdepth 1 -type d | wc -l)" -eq 1 ]; then
+
cd "$(find . -mindepth 1 -maxdepth 1 -type d)"
+
fi
+
extractedZip="$PWD"
-
packageBaseDir=$out/libexec/android-sdk/${package.path}
-
mkdir -p $packageBaseDir
-
cd $packageBaseDir
-
cp -a $extractedZip/* .
-
${patchesInstructions.${package.name}}
+
packageBaseDir=$out/libexec/android-sdk/${package.path}
+
mkdir -p $packageBaseDir
+
cd $packageBaseDir
+
cp -a $extractedZip/* .
+
${patchesInstructions.${package.name}}
-
if [ ! -f $packageBaseDir/package.xml ]; then
-
cat << EOF > $packageBaseDir/package.xml
-
${mkXmlPackage package}
-
EOF
-
fi
-
'') packages) + ''
-
runHook postInstall
-
'';
+
if [ ! -f $packageBaseDir/package.xml ]; then
+
cat << EOF > $packageBaseDir/package.xml
+
${mkXmlPackage package}
+
EOF
+
fi
+
'') packages
+
)
+
+ ''
+
runHook postInstall
+
'';
-
# Some executables that have been patched with patchelf may not work any longer after they have been stripped.
-
dontStrip = true;
-
dontPatchELF = true;
-
dontAutoPatchelf = true;
+
# Some executables that have been patched with patchelf may not work any longer after they have been stripped.
+
dontStrip = true;
+
dontPatchELF = true;
+
dontAutoPatchelf = true;
-
inherit meta;
-
} // extraParams)
+
inherit meta;
+
}
+
// extraParams
+
)
+46 -26
pkgs/development/mobile/androidenv/emulator.nix
···
-
{ deployAndroidPackage, lib, stdenv, package, os, arch, autoPatchelfHook, makeWrapper, pkgs, pkgsi686Linux, postInstall, meta }:
+
{
+
deployAndroidPackage,
+
lib,
+
stdenv,
+
package,
+
os,
+
arch,
+
autoPatchelfHook,
+
makeWrapper,
+
pkgs,
+
pkgsi686Linux,
+
postInstall,
+
meta,
+
}:
deployAndroidPackage {
inherit package os arch;
-
nativeBuildInputs = [ makeWrapper ]
-
++ lib.optionals (os == "linux") [ autoPatchelfHook ];
-
buildInputs = lib.optionals (os == "linux") (with pkgs; [
-
glibc
-
libcxx
-
libGL
-
libpulseaudio
-
libtiff
-
libuuid
-
zlib
-
libbsd
-
ncurses5
-
libdrm
-
stdenv.cc.cc
-
expat
-
freetype
-
nss
-
nspr
-
alsa-lib
-
]) ++ (with pkgs.xorg; [
+
nativeBuildInputs = [ makeWrapper ] ++ lib.optionals (os == "linux") [ autoPatchelfHook ];
+
buildInputs =
+
lib.optionals (os == "linux") (
+
with pkgs;
+
[
+
glibc
+
libcxx
+
libGL
+
libpulseaudio
+
libtiff
+
libuuid
+
zlib
+
libbsd
+
ncurses5
+
libdrm
+
stdenv.cc.cc
+
expat
+
freetype
+
nss
+
nspr
+
alsa-lib
+
]
+
)
+
++ (with pkgs.xorg; [
libX11
libXext
libXdamage
···
libICE
libSM
libxkbfile
-
]) ++ lib.optional (os == "linux" && stdenv.isx86_64) pkgsi686Linux.glibc;
+
])
+
++ lib.optional (os == "linux" && stdenv.isx86_64) pkgsi686Linux.glibc;
patchInstructions = lib.optionalString (os == "linux") ''
addAutoPatchelfSearchPath $packageBaseDir/lib
addAutoPatchelfSearchPath $packageBaseDir/lib64
···
# Wrap emulator so that it can load required libraries at runtime
wrapProgram $out/libexec/android-sdk/emulator/emulator \
-
--prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath [
-
pkgs.dbus
-
pkgs.systemd
-
]} \
+
--prefix LD_LIBRARY_PATH : ${
+
lib.makeLibraryPath [
+
pkgs.dbus
+
pkgs.systemd
+
]
+
} \
--set QT_XKB_CONFIG_ROOT ${pkgs.xkeyboard_config}/share/X11/xkb \
--set QTCOMPOSE ${pkgs.xorg.libX11.out}/share/X11/locale
+17 -14
pkgs/development/mobile/androidenv/examples/shell-with-emulator.nix
···
jdk
];
}
-
(pkgs.lib.optionalString emulatorSupported ''
-
export ANDROID_USER_HOME=$PWD/.android
-
mkdir -p $ANDROID_USER_HOME
+
(
+
pkgs.lib.optionalString emulatorSupported ''
+
export ANDROID_USER_HOME=$PWD/.android
+
mkdir -p $ANDROID_USER_HOME
-
avdmanager delete avd -n testAVD || true
-
echo "" | avdmanager create avd --force --name testAVD --package 'system-images;android-35;google_apis;x86_64'
-
result=$(avdmanager list avd)
+
avdmanager delete avd -n testAVD || true
+
echo "" | avdmanager create avd --force --name testAVD --package 'system-images;android-35;google_apis;x86_64'
+
result=$(avdmanager list avd)
-
if [[ ! $result =~ "Name: testAVD" ]]; then
-
echo "avdmanager couldn't create the avd! The output is :''${result}"
-
exit 1
-
fi
+
if [[ ! $result =~ "Name: testAVD" ]]; then
+
echo "avdmanager couldn't create the avd! The output is :''${result}"
+
exit 1
+
fi
-
avdmanager delete avd -n testAVD || true
-
'' + ''
-
touch $out
-
'');
+
avdmanager delete avd -n testAVD || true
+
''
+
+ ''
+
touch $out
+
''
+
);
};
}
+116 -80
pkgs/development/mobile/androidenv/examples/shell.nix
···
{
# If you copy this example out of nixpkgs, use these lines instead of the next.
# This example pins nixpkgs: https://nix.dev/tutorials/first-steps/towards-reproducibility-pinning-nixpkgs.html
-
/*nixpkgsSource ? (builtins.fetchTarball {
-
name = "nixpkgs-20.09";
-
url = "https://github.com/NixOS/nixpkgs/archive/20.09.tar.gz";
-
sha256 = "1wg61h4gndm3vcprdcg7rc4s1v3jkm5xd7lw8r2f67w502y94gcy";
-
}),
-
pkgs ? import nixpkgsSource {
-
config.allowUnfree = true;
-
},
+
/*
+
nixpkgsSource ? (builtins.fetchTarball {
+
name = "nixpkgs-20.09";
+
url = "https://github.com/NixOS/nixpkgs/archive/20.09.tar.gz";
+
sha256 = "1wg61h4gndm3vcprdcg7rc4s1v3jkm5xd7lw8r2f67w502y94gcy";
+
}),
+
pkgs ? import nixpkgsSource {
+
config.allowUnfree = true;
+
},
*/
# If you want to use the in-tree version of nixpkgs:
···
# Copy this file to your Android project.
let
# If you copy this example out of nixpkgs, something like this will work:
-
/*androidEnvNixpkgs = fetchTarball {
-
name = "androidenv";
-
url = "https://github.com/NixOS/nixpkgs/archive/<fill me in from Git>.tar.gz";
-
sha256 = "<fill me in with nix-prefetch-url --unpack>";
-
};
+
/*
+
androidEnvNixpkgs = fetchTarball {
+
name = "androidenv";
+
url = "https://github.com/NixOS/nixpkgs/archive/<fill me in from Git>.tar.gz";
+
sha256 = "<fill me in with nix-prefetch-url --unpack>";
+
};
-
androidEnv = pkgs.callPackage "${androidEnvNixpkgs}/pkgs/development/mobile/androidenv" {
-
inherit config pkgs;
-
licenseAccepted = true;
-
};*/
+
androidEnv = pkgs.callPackage "${androidEnvNixpkgs}/pkgs/development/mobile/androidenv" {
+
inherit config pkgs;
+
licenseAccepted = true;
+
};
+
*/
# Otherwise, just use the in-tree androidenv:
androidEnv = pkgs.callPackage ./.. {
···
includeNDK = "if-supported";
useGoogleAPIs = true;
-
platformVersions = [ "23" "24" "25" "26" "27" "28" "29" "30" "31" "32" "33" "34" "35" ];
+
platformVersions = [
+
"23"
+
"24"
+
"25"
+
"26"
+
"27"
+
"28"
+
"29"
+
"30"
+
"31"
+
"32"
+
"33"
+
"34"
+
"35"
+
];
# If you want to use a custom repo JSON:
# repoJson = ../repo.json;
# If you want to use custom repo XMLs:
-
/*repoXmls = {
-
packages = [ ../xml/repository2-1.xml ];
-
images = [
-
../xml/android-sys-img2-1.xml
-
../xml/android-tv-sys-img2-1.xml
-
../xml/android-wear-sys-img2-1.xml
-
../xml/android-wear-cn-sys-img2-1.xml
-
../xml/google_apis-sys-img2-1.xml
-
../xml/google_apis_playstore-sys-img2-1.xml
+
/*
+
repoXmls = {
+
packages = [ ../xml/repository2-1.xml ];
+
images = [
+
../xml/android-sys-img2-1.xml
+
../xml/android-tv-sys-img2-1.xml
+
../xml/android-wear-sys-img2-1.xml
+
../xml/android-wear-cn-sys-img2-1.xml
+
../xml/google_apis-sys-img2-1.xml
+
../xml/google_apis_playstore-sys-img2-1.xml
+
];
+
addons = [ ../xml/addon2-1.xml ];
+
};
+
*/
+
+
includeExtras =
+
[
+
"extras;google;gcm"
+
]
+
++ pkgs.lib.optionals includeAuto [
+
"extras;google;auto"
];
-
addons = [ ../xml/addon2-1.xml ];
-
};*/
-
-
includeExtras = [
-
"extras;google;gcm"
-
] ++ pkgs.lib.optionals includeAuto [
-
"extras;google;auto"
-
];
# Accepting more licenses declaratively:
extraLicenses = [
···
in
pkgs.mkShell rec {
name = "androidenv-demo";
-
packages = [ androidSdk platformTools jdk ];
+
packages = [
+
androidSdk
+
platformTools
+
jdk
+
];
LANG = "C.UTF-8";
LC_ALL = "C.UTF-8";
···
passthru.tests = {
-
shell-sdkmanager-licenses-test = pkgs.runCommand "shell-sdkmanager-licenses-test" {
-
nativeBuildInputs = [ androidSdk jdk ];
-
} ''
-
if [[ ! "$(sdkmanager --licenses)" =~ "All SDK package licenses accepted." ]]; then
-
echo "At least one of SDK package licenses are not accepted."
-
exit 1
-
fi
-
touch $out
-
'';
+
shell-sdkmanager-licenses-test =
+
pkgs.runCommand "shell-sdkmanager-licenses-test"
+
{
+
nativeBuildInputs = [
+
androidSdk
+
jdk
+
];
+
}
+
''
+
if [[ ! "$(sdkmanager --licenses)" =~ "All SDK package licenses accepted." ]]; then
+
echo "At least one of SDK package licenses are not accepted."
+
exit 1
+
fi
+
touch $out
+
'';
-
shell-sdkmanager-packages-test = pkgs.runCommand "shell-sdkmanager-packages-test" {
-
nativeBuildInputs = [ androidSdk jdk ];
-
} ''
-
output="$(sdkmanager --list)"
-
installed_packages_section=$(echo "''${output%%Available Packages*}" | awk 'NR>4 {print $1}')
+
shell-sdkmanager-packages-test =
+
pkgs.runCommand "shell-sdkmanager-packages-test"
+
{
+
nativeBuildInputs = [
+
androidSdk
+
jdk
+
];
+
}
+
''
+
output="$(sdkmanager --list)"
+
installed_packages_section=$(echo "''${output%%Available Packages*}" | awk 'NR>4 {print $1}')
-
# FIXME couldn't find platforms;android-34, even though it's in the correct directory!! sdkmanager's bug?!
-
packages=(
-
"build-tools" "platform-tools" \
-
"platforms;android-23" "platforms;android-24" "platforms;android-25" "platforms;android-26" \
-
"platforms;android-27" "platforms;android-28" "platforms;android-29" "platforms;android-30" \
-
"platforms;android-31" "platforms;android-32" "platforms;android-33" "platforms;android-35" \
-
"sources;android-23" "sources;android-24" "sources;android-25" "sources;android-26" \
-
"sources;android-27" "sources;android-28" "sources;android-29" "sources;android-30" \
-
"sources;android-31" "sources;android-32" "sources;android-33" "sources;android-34" \
-
"sources;android-35" \
-
"system-images;android-28;google_apis_playstore;x86_64" \
-
"system-images;android-29;google_apis_playstore;x86_64" \
-
"system-images;android-30;google_apis_playstore;x86_64" \
-
"system-images;android-31;google_apis_playstore;x86_64" \
-
"system-images;android-32;google_apis_playstore;x86_64" \
-
"system-images;android-33;google_apis_playstore;x86_64" \
-
"system-images;android-34;google_apis;x86_64" \
-
"system-images;android-35;google_apis;x86_64" \
-
"extras;google;gcm"
-
)
-
${pkgs.lib.optionalString includeAuto ''packages+=("extras;google;auto")''}
+
# FIXME couldn't find platforms;android-34, even though it's in the correct directory!! sdkmanager's bug?!
+
packages=(
+
"build-tools" "platform-tools" \
+
"platforms;android-23" "platforms;android-24" "platforms;android-25" "platforms;android-26" \
+
"platforms;android-27" "platforms;android-28" "platforms;android-29" "platforms;android-30" \
+
"platforms;android-31" "platforms;android-32" "platforms;android-33" "platforms;android-35" \
+
"sources;android-23" "sources;android-24" "sources;android-25" "sources;android-26" \
+
"sources;android-27" "sources;android-28" "sources;android-29" "sources;android-30" \
+
"sources;android-31" "sources;android-32" "sources;android-33" "sources;android-34" \
+
"sources;android-35" \
+
"system-images;android-28;google_apis_playstore;x86_64" \
+
"system-images;android-29;google_apis_playstore;x86_64" \
+
"system-images;android-30;google_apis_playstore;x86_64" \
+
"system-images;android-31;google_apis_playstore;x86_64" \
+
"system-images;android-32;google_apis_playstore;x86_64" \
+
"system-images;android-33;google_apis_playstore;x86_64" \
+
"system-images;android-34;google_apis;x86_64" \
+
"system-images;android-35;google_apis;x86_64" \
+
"extras;google;gcm"
+
)
+
${pkgs.lib.optionalString includeAuto ''packages+=("extras;google;auto")''}
-
for package in "''${packages[@]}"; do
-
if [[ ! $installed_packages_section =~ "$package" ]]; then
-
echo "$package package was not installed."
-
exit 1
-
fi
-
done
+
for package in "''${packages[@]}"; do
+
if [[ ! $installed_packages_section =~ "$package" ]]; then
+
echo "$package package was not installed."
+
exit 1
+
fi
+
done
-
touch "$out"
-
'';
+
touch "$out"
+
'';
};
}
-
+39 -10
pkgs/development/mobile/androidenv/ndk-bundle/default.nix
···
-
{ stdenv, lib, pkgs, pkgsHostHost, makeWrapper, autoPatchelfHook
-
, deployAndroidPackage, package, os, arch, platform-tools, meta
+
{
+
stdenv,
+
lib,
+
pkgs,
+
pkgsHostHost,
+
makeWrapper,
+
autoPatchelfHook,
+
deployAndroidPackage,
+
package,
+
os,
+
arch,
+
platform-tools,
+
meta,
}:
let
-
runtime_paths = lib.makeBinPath (with pkgsHostHost; [
-
coreutils file findutils gawk gnugrep gnused jdk python3 which
-
]) + ":${platform-tools}/platform-tools";
+
runtime_paths =
+
lib.makeBinPath (
+
with pkgsHostHost;
+
[
+
coreutils
+
file
+
findutils
+
gawk
+
gnugrep
+
gnused
+
jdk
+
python3
+
which
+
]
+
)
+
+ ":${platform-tools}/platform-tools";
in
deployAndroidPackage rec {
inherit package os arch;
-
nativeBuildInputs = [ makeWrapper ]
-
++ lib.optionals stdenv.hostPlatform.isLinux [ autoPatchelfHook ];
+
nativeBuildInputs = [
+
makeWrapper
+
] ++ lib.optionals stdenv.hostPlatform.isLinux [ autoPatchelfHook ];
autoPatchelfIgnoreMissingDeps = [ "*" ];
-
buildInputs = lib.optionals (os == "linux") [ pkgs.zlib pkgs.libcxx (lib.getLib stdenv.cc.cc) ];
+
buildInputs = lib.optionals (os == "linux") [
+
pkgs.zlib
+
pkgs.libcxx
+
(lib.getLib stdenv.cc.cc)
+
];
patchElfBnaries = ''
# Patch the executables of the toolchains, but not the libraries -- they are needed for crosscompiling
···
done
'';
-
patchInstructions = patchOsAgnostic
-
+ lib.optionalString stdenv.hostPlatform.isLinux patchElfBnaries;
+
patchInstructions =
+
patchOsAgnostic + lib.optionalString stdenv.hostPlatform.isLinux patchElfBnaries;
noAuditTmpdir = true; # Audit script gets invoked by the build/ component in the path for the make standalone script
+30 -14
pkgs/development/mobile/androidenv/platform-tools.nix
···
-
{deployAndroidPackage, lib, package, os, arch, autoPatchelfHook, pkgs, meta}:
+
{
+
deployAndroidPackage,
+
lib,
+
package,
+
os,
+
arch,
+
autoPatchelfHook,
+
pkgs,
+
meta,
+
}:
deployAndroidPackage {
inherit package os arch;
nativeBuildInputs = lib.optionals (os == "linux") [ autoPatchelfHook ];
-
buildInputs = lib.optionals (os == "linux") [ pkgs.glibc (lib.getLib pkgs.stdenv.cc.cc) pkgs.zlib pkgs.ncurses5 ];
+
buildInputs = lib.optionals (os == "linux") [
+
pkgs.glibc
+
(lib.getLib pkgs.stdenv.cc.cc)
+
pkgs.zlib
+
pkgs.ncurses5
+
];
-
patchInstructions = lib.optionalString (os == "linux") ''
-
addAutoPatchelfSearchPath $packageBaseDir/lib64
-
autoPatchelf --no-recurse $packageBaseDir/lib64
-
autoPatchelf --no-recurse $packageBaseDir
-
'' + ''
-
mkdir -p $out/bin
-
cd $out/bin
-
find $out/libexec/android-sdk/platform-tools -type f -executable -mindepth 1 -maxdepth 1 -not -name sqlite3 | while read i
-
do
-
ln -s $i
-
done
-
'';
+
patchInstructions =
+
lib.optionalString (os == "linux") ''
+
addAutoPatchelfSearchPath $packageBaseDir/lib64
+
autoPatchelf --no-recurse $packageBaseDir/lib64
+
autoPatchelf --no-recurse $packageBaseDir
+
''
+
+ ''
+
mkdir -p $out/bin
+
cd $out/bin
+
find $out/libexec/android-sdk/platform-tools -type f -executable -mindepth 1 -maxdepth 1 -not -name sqlite3 | while read i
+
do
+
ln -s $i
+
done
+
'';
inherit meta;
}
+49 -10
pkgs/development/mobile/androidenv/tools.nix
···
-
{deployAndroidPackage, lib, stdenv, package, os, arch, autoPatchelfHook, makeWrapper, pkgs, pkgsi686Linux, postInstall, meta}:
+
{
+
deployAndroidPackage,
+
lib,
+
stdenv,
+
package,
+
os,
+
arch,
+
autoPatchelfHook,
+
makeWrapper,
+
pkgs,
+
pkgsi686Linux,
+
postInstall,
+
meta,
+
}:
deployAndroidPackage {
name = "androidsdk-tools";
inherit package os arch;
-
nativeBuildInputs = [ makeWrapper ]
-
++ lib.optionals (os == "linux") [ autoPatchelfHook ];
+
nativeBuildInputs = [ makeWrapper ] ++ lib.optionals (os == "linux") [ autoPatchelfHook ];
buildInputs = lib.optional (os == "linux") (
-
(with pkgs; [ glibc freetype fontconfig fontconfig.lib
-
stdenv.cc.cc.libgcc or null # fix for https://github.com/NixOS/nixpkgs/issues/226357
-
])
-
++ (with pkgs.xorg; [ libX11 libXrender libXext ])
-
++ lib.optionals (os == "linux" && stdenv.isx86_64) (with pkgsi686Linux; [ glibc xorg.libX11 xorg.libXrender xorg.libXext fontconfig.lib freetype zlib ])
-
);
+
(with pkgs; [
+
glibc
+
freetype
+
fontconfig
+
fontconfig.lib
+
stdenv.cc.cc.libgcc or null # fix for https://github.com/NixOS/nixpkgs/issues/226357
+
])
+
++ (with pkgs.xorg; [
+
libX11
+
libXrender
+
libXext
+
])
+
++ lib.optionals (os == "linux" && stdenv.isx86_64) (
+
with pkgsi686Linux;
+
[
+
glibc
+
xorg.libX11
+
xorg.libXrender
+
xorg.libXext
+
fontconfig.lib
+
freetype
+
zlib
+
]
+
)
+
);
patchInstructions = ''
${lib.optionalString (os == "linux") ''
···
# Wrap monitor script
wrapProgram $PWD/monitor \
--prefix PATH : ${pkgs.jdk8}/bin \
-
--prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath (with pkgs; [ xorg.libX11 xorg.libXtst ])}
+
--prefix LD_LIBRARY_PATH : ${
+
lib.makeLibraryPath (
+
with pkgs;
+
[
+
xorg.libX11
+
xorg.libXtst
+
]
+
)
+
}
# Patch all script shebangs
patchShebangs .