nix: refactor android sdk package

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2020-04-22 19:05:18 +02:00
parent 548fe04f54
commit 68b9b18cae
No known key found for this signature in database
GPG Key ID: 4EF064D0E6D63020
18 changed files with 163 additions and 135 deletions

View File

@ -1,61 +0,0 @@
#
# This Nix expression centralizes the configuration for the Android development environment
#
{ stdenv, config, callPackage, androidenv, openjdk, mkShell }:
let
androidComposition = androidenv.composeAndroidPackages {
toolsVersion = "26.1.1";
platformToolsVersion = "29.0.6";
buildToolsVersions = [ "29.0.2" ];
includeEmulator = false;
platformVersions = [ "29" ];
includeSources = false;
includeDocs = false;
includeSystemImages = false;
systemImageTypes = [ "default" ];
lldbVersions = [ "3.1.4508709" ];
cmakeVersions = [ "3.10.2" ];
includeNDK = true;
ndkVersion = "21.0.6113669";
useGoogleAPIs = false;
useGoogleTVAddOns = false;
includeExtras = [ "extras;android;m2repository" "extras;google;m2repository" ];
};
licensedAndroidEnv = stdenv.mkDerivation rec {
name = "licensed-android-sdk";
version = "licensed";
phases = [ "installPhase" "licensePhase" ];
installPhase = ''
mkdir -p $out/libexec/android-sdk
ln -s "${androidComposition.androidsdk}/bin" $out/bin
for d in ${androidComposition.androidsdk}/libexec/android-sdk/*; do
ln -s $d $out/$(basename $d)
done
'';
licensePhase = stdenv.lib.optionalString config.android_sdk.accept_license ''
mkdir -p $out/licenses
echo -e "\n601085b94cd77f0b54ff86406957099ebe79c4d6" > "$out/licenses/android-googletv-license"
echo -e "\n24333f8a63b6825ea9c5514f83c2829b004d1fee" > "$out/licenses/android-sdk-license"
echo -e "\n84831b9409646a918e30573bab4c9c91346d8abd" > "$out/licenses/android-sdk-preview-license"
echo -e "\nd975f751698a77b662f1254ddbeed3901e976f5a" > "$out/licenses/intel-android-extra-license"
echo -e "\n33b6a2b64607f11b759f320ef9dff4ae5c47d97a" > "$out/licenses/google-gdk-license"
'';
};
shell = mkShell {
shellHook = ''
export JAVA_HOME="${openjdk}"
export ANDROID_HOME="${licensedAndroidEnv}"
export ANDROID_SDK_ROOT="$ANDROID_HOME"
export ANDROID_NDK_ROOT="${androidComposition.androidsdk}/libexec/android-sdk/ndk-bundle"
export ANDROID_NDK_HOME="$ANDROID_NDK_ROOT"
export ANDROID_NDK="$ANDROID_NDK_ROOT"
export PATH="$ANDROID_HOME/bin:$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools:$ANDROID_HOME/build-tools:$PATH"
'';
};
in {
drv = licensedAndroidEnv;
inherit androidComposition shell;
}

View File

@ -1,9 +1,8 @@
{ config, lib, callPackage, mkShell, mergeSh, androidenv, flock, lsof, openjdk, gradle_5,
status-go, localMavenRepoBuilder, projectNodePackage }:
{ config, lib, callPackage, mkShell, mergeSh, flock, lsof, openjdk, gradle_5,
status-go, localMavenRepoBuilder, projectNodePackage, androidPkgs, androidShell }:
let
gradle = gradle_5; # Currently 5.6.4
androidEnv = callPackage ./android-env.nix { };
leinProjectDeps = import ../../lein/lein-project-deps.nix { };
# Import a jsbundle compiled out of clojure codebase
@ -22,12 +21,10 @@ let
# TARGETS
release = callPackage ./targets/release-android.nix {
inherit config gradle mavenAndNpmDeps jsbundle status-go watchmanFactory;
androidEnvShellHook = androidEnv.shell.shellHook;
};
generate-maven-and-npm-deps-shell = callPackage ./maven-and-npm-deps/maven/shell.nix {
inherit gradle projectNodePackage status-go;
androidEnvShellHook = androidEnv.shell.shellHook;
};
buildInputs = [
@ -39,24 +36,23 @@ let
in {
# TARGETS
inherit release jsbundle generate-maven-and-npm-deps-shell buildInputs;
inherit (androidEnv) androidComposition;
shell = mergeSh
(mkShell {
inherit buildInputs;
inputsFrom = [ release gradle ];
shellHook = ''
export ANDROID_SDK_ROOT="${androidPkgs}"
export ANDROID_NDK_ROOT="${androidPkgs}/ndk-bundle"
# check if node modules changed and if so install them
$STATUS_REACT_HOME/nix/mobile/reset-node_modules.sh \
"${mavenAndNpmDeps.drv}/project"
'';
})
(lib.catAttrs "shell" [ status-go mavenAndNpmDeps androidEnv ]);
(lib.catAttrs "shell" [ status-go mavenAndNpmDeps androidShell ]);
env = {
shell = mkShell {
buildInputs = [ androidEnv.drv ];
inherit (androidEnv.shell) shellHook;
};
shell = androidShell;
};
}

View File

@ -1,20 +1,13 @@
{ mkShell, curl, flock, git, gradle, jq, maven, nodejs,
projectNodePackage, androidEnvShellHook, status-go }:
{ mergeSh, mkShell, curl, flock, git, gradle, jq, maven, nodejs,
projectNodePackage, androidShell, status-go }:
mkShell {
mergeSh (mkShell {
buildInputs = [
curl
flock # used in reset-node_modules.sh
git
gradle
jq
maven
nodejs
curl flock # used in reset-node_modules.sh
git gradle jq maven nodejs
projectNodePackage
];
shellHook = ''
${androidEnvShellHook}
${status-go.shell.shellHook}
$STATUS_REACT_HOME/nix/mobile/reset-node_modules.sh "${projectNodePackage}"
'';
}
}) [ status-go.shell androidShell ]

View File

@ -0,0 +1,14 @@
#
# This Nix expression centralizes the configuration
# for the Android development environment.
#
{ callPackage }:
let
pkgs = callPackage ./pkgs.nix { };
shell = callPackage ./shell.nix { };
licensedPkgs = callPackage ./licensed.nix { };
in {
inherit pkgs licensedPkgs shell;
}

View File

@ -0,0 +1,26 @@
{ config, stdenv, callPackage }:
let
androidPkgs = callPackage ./pkgs.nix { };
in
# Licensed Android Environment as a separate derivation
stdenv.mkDerivation rec {
name = "licensed-android-sdk";
version = "licensed";
phases = [ "installPhase" "licensePhase" ];
installPhase = ''
mkdir -p $out/libexec/android-sdk
ln -s "${androidPkgs.androidsdk}/bin" $out/bin
for d in ${androidPkgs.androidsdk}/libexec/android-sdk/*; do
ln -s $d $out/$(basename $d)
done
'';
licensePhase = stdenv.lib.optionalString config.android_sdk.accept_license ''
mkdir -p $out/licenses
echo -e "\n601085b94cd77f0b54ff86406957099ebe79c4d6" > "$out/licenses/android-googletv-license"
echo -e "\n24333f8a63b6825ea9c5514f83c2829b004d1fee" > "$out/licenses/android-sdk-license"
echo -e "\n84831b9409646a918e30573bab4c9c91346d8abd" > "$out/licenses/android-sdk-preview-license"
echo -e "\nd975f751698a77b662f1254ddbeed3901e976f5a" > "$out/licenses/intel-android-extra-license"
echo -e "\n33b6a2b64607f11b759f320ef9dff4ae5c47d97a" > "$out/licenses/google-gdk-license"
'';
}

View File

@ -0,0 +1,28 @@
#
# This Nix expression centralizes the configuration
# for the Android development environment.
#
{ stdenv, config, callPackage, androidenv, openjdk, mkShell }:
androidenv.composeAndroidPackages {
toolsVersion = "26.1.1";
platformToolsVersion = "29.0.6";
buildToolsVersions = [ "29.0.2" ];
includeEmulator = false;
platformVersions = [ "29" ];
includeSources = false;
includeDocs = false;
includeSystemImages = false;
systemImageTypes = [ "default" ];
lldbVersions = [ "3.1.4508709" ];
cmakeVersions = [ "3.10.2" ];
includeNDK = true;
ndkVersion = "21.0.6113669";
useGoogleAPIs = false;
useGoogleTVAddOns = false;
includeExtras = [
"extras;android;m2repository"
"extras;google;m2repository"
];
}

View File

@ -0,0 +1,21 @@
{ mkShell, callPackage, openjdk }:
let
licensedPkgs = callPackage ./licensed.nix { };
in
mkShell {
shellHook = ''
export JAVA_HOME="${openjdk}"
export ANDROID_HOME="${licensedPkgs}"
export ANDROID_SDK_ROOT="${licensedPkgs}"
export ANDROID_NDK_ROOT="${licensedPkgs}/ndk-bundle"
export PATH="$ANDROID_HOME/bin:$PATH"
export PATH="$ANDROID_NDK_ROOT:$PATH"
export PATH="$ANDROID_SDK_ROOT/tools:$PATH"
export PATH="$ANDROID_SDK_ROOT/tools/bin:$PATH"
export PATH="$ANDROID_SDK_ROOT/platform-tools:$PATH"
export PATH="$ANDROID_SDK_ROOT/build-tools:$PATH"
'';
}

View File

@ -1,6 +1,6 @@
{ stdenv, lib, config, callPackage,
mkFilter, bash, file, gnumake, watchmanFactory, gradle,
androidEnvShellHook, mavenAndNpmDeps,
androidPkgs, mavenAndNpmDeps,
nodejs, openjdk, jsbundle, status-go, unzip, zlib }:
{ secrets-file ? "", # Path to the file containing secret environment variables
@ -111,13 +111,15 @@ in stdenv.mkDerivation {
adhocEnvVars = optionalString stdenv.isLinux "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${makeLibraryPath [ zlib ]}";
capitalizedBuildType = toUpper (substring 0 1 buildType) + substring 1 (-1) buildType;
in ''
export ANDROID_SDK_ROOT="${androidPkgs}"
export ANDROID_NDK_ROOT="${androidPkgs}/ndk-bundle"
export STATUS_REACT_HOME=$PWD
export HOME=$sourceRoot
${exportEnvVars}
${if secrets-file != "" then "source ${secrets-file}" else ""}
${androidEnvShellHook}
${concatStrings (catAttrs "shellHook" [ mavenAndNpmDeps.shell status-go.shell ])}
# fix permissions so gradle can create directories

View File

@ -1,41 +1,38 @@
{ config, lib, stdenvNoCC, callPackage, status-go,
localMavenRepoBuilder, composeXcodeWrapper, mkShell, mergeSh }:
{ config, lib, stdenvNoCC, callPackage, mkShell,
status-go, mergeSh, xcodeWrapper }:
let
inherit (lib) catAttrs concatStrings optional unique;
xcodewrapperArgs = {
version = "11.4.1";
};
xcodeWrapper = composeXcodeWrapper xcodewrapperArgs;
projectNodePackage = callPackage ./node-package.nix { };
localMavenRepoBuilder = callPackage ../tools/maven/maven-repo-builder.nix { };
fastlane = callPackage ./fastlane { };
androidPlatform = callPackage ./android {
android = callPackage ./android {
inherit localMavenRepoBuilder projectNodePackage;
status-go = status-go.android;
};
iosPlatform = callPackage ./ios {
ios = callPackage ./ios {
inherit xcodeWrapper projectNodePackage fastlane;
status-go = status-go.ios;
};
selectedSources = [
fastlane
status-go.android
status-go.ios
androidPlatform
iosPlatform
fastlane
android
ios
];
projectNodePackage = callPackage ./node-package.nix { inherit (lib) importJSON; };
in {
buildInputs = unique (catAttrs "buildInputs" selectedSources);
shell = mergeSh (mkShell {}) (catAttrs "shell" selectedSources);
# CHILD DERIVATIONS
android = androidPlatform;
ios = iosPlatform;
# TARGETS
inherit fastlane xcodeWrapper;
inherit android ios fastlane;
}

View File

@ -1,4 +1,4 @@
{ importJSON, fetchFromGitHub, pkgs, nodejs, yarn }:
{ lib, fetchFromGitHub, pkgs, nodejs, yarn }:
let
yarn2nix = import (fetchFromGitHub {
@ -10,7 +10,7 @@ let
}) { inherit pkgs nodejs yarn; };
yarnLock = ../../mobile/js_files/yarn.lock;
packageJSON = ../../mobile/js_files/package.json;
packageJSONContent = importJSON packageJSON;
packageJSONContent = lib.importJSON packageJSON;
# Create a yarn package for our project that contains all the dependecies, so that we have a
# known good node_modules folder that we can use later on

View File

@ -25,16 +25,24 @@ let
permittedInsecurePackages = [ "openssl-1.0.2u" ];
# Override some package versions
packageOverrides = pkgs: rec {
inherit (pkgs) callPackage stdenv stdenvNoCC xcodeenv;
# utilities
mkFilter = import ./tools/mkFilter.nix { inherit (pkgs.stdenv) lib; };
mkShell = import ./tools/mkShell.nix { inherit pkgs; stdenv = pkgs.stdenvNoCC; };
mergeSh = import ./tools/mergeSh.nix { inherit (pkgs.stdenv) lib; };
mkFilter = import ./tools/mkFilter.nix { inherit (stdenv) lib; };
mkShell = import ./tools/mkShell.nix { inherit pkgs; stdenv = stdenvNoCC; };
mergeSh = import ./tools/mergeSh.nix { inherit (stdenv) lib; };
# android environement
androidEnvCustom = callPackage ./mobile/android/sdk { };
androidPkgs = androidEnvCustom.licensedPkgs;
androidShell = androidEnvCustom.shell;
# custom packages
xcodeWrapper = xcodeenv.composeXcodeWrapper { version = "11.4.1"; };
openjdk = pkgs.openjdk8_headless;
nodejs = pkgs.nodejs-12_x;
yarn = pkgs.yarn.override { inherit nodejs; };
go = pkgs.callPackage ./patched-go { baseGo = pkgs.go_1_14; };
go = callPackage ./patched-go { baseGo = pkgs.go_1_14; };
# custom builders
buildGoPackage = pkgs.buildGo114Package.override { inherit go; };

View File

@ -23,7 +23,9 @@ function cleanup() {
fi
}
trap cleanup EXIT ERR INT QUIT
if [[ -z "${_NIX_NO_CLEAN}" ]]; then
trap cleanup EXIT ERR INT QUIT
fi
# build output will end up under /nix, we have to extract it
function extractResults() {

View File

@ -1,5 +1,5 @@
{ config, stdenv, callPackage, mkShell, mergeSh,
fetchFromGitHub, mkFilter, openjdk, androidPkgs, xcodeWrapper }:
fetchFromGitHub, mkFilter, openjdk, androidPkgs }:
let
inherit (stdenv.lib)
@ -9,11 +9,21 @@ let
envFlags = callPackage ../tools/envParser.nix { };
enableNimbus = (attrByPath ["STATUS_GO_ENABLE_NIMBUS"] "0" envFlags) != "0";
utils = callPackage ./utils.nix { inherit xcodeWrapper; };
gomobile = callPackage ./gomobile { inherit (androidPkgs) platform-tools; inherit xcodeWrapper utils; };
nimbus = if enableNimbus then callPackage ./nimbus { } else { wrappers-android = { }; };
buildStatusGoDesktopLib = callPackage ./build-desktop-status-go.nix { inherit xcodeWrapper utils; };
buildStatusGoMobileLib = callPackage ./build-mobile-status-go.nix { inherit gomobile xcodeWrapper utils androidPkgs; };
utils = callPackage ./utils.nix { };
gomobile = callPackage ./gomobile { inherit utils; };
nimbus =
if enableNimbus then callPackage ./nimbus { }
else { wrappers-android = { }; };
buildStatusGoDesktopLib = callPackage ./desktop {
inherit utils;
};
buildStatusGoMobileLib = callPackage ./mobile {
inherit gomobile utils androidPkgs;
};
srcData =
# If config.status-im.status-go.src-override is defined, instruct Nix to use that path to build status-go
if (attrByPath ["status-im" "status-go" "src-override"] "" config) != "" then rec {
@ -60,8 +70,8 @@ let
android = rec {
name = "android";
envVars = [
"ANDROID_HOME=${androidPkgs.androidsdk}/libexec/android-sdk"
"ANDROID_NDK_HOME=${androidPkgs.ndk-bundle}/libexec/android-sdk/ndk-bundle"
"ANDROID_HOME=${androidPkgs}"
"ANDROID_NDK_HOME=${androidPkgs}/ndk-bundle"
"PATH=${makeBinPath [ openjdk ]}:$PATH"
];
gomobileExtraFlags = [ "-androidapi 23" ];

View File

@ -7,7 +7,7 @@
hostSystem } @ args':
let
buildStatusGo = callPackage ./build-status-go.nix {
buildStatusGo = callPackage ../build.nix {
inherit buildGoPackage go xcodeWrapper utils;
};

View File

@ -1,5 +1,5 @@
{ stdenv, callPackage, utils, fetchgit, buildGoPackage,
ncurses5, zlib, makeWrapper, patchelf, platform-tools, xcodeWrapper
ncurses5, zlib, makeWrapper, patchelf, androidPkgs, xcodeWrapper
}:
let
@ -24,7 +24,7 @@ in buildGoPackage rec {
patches = [ ./resolve-nix-android-sdk.patch ];
postPatch = ''
substituteInPlace cmd/gomobile/install.go --replace "\`adb\`" "\`${platform-tools}/bin/adb\`"
substituteInPlace cmd/gomobile/install.go --replace "\`adb\`" "\`${androidPkgs}/bin/adb\`"
# Prevent a non-deterministic temporary directory from polluting the resulting object files
substituteInPlace cmd/gomobile/env.go \

View File

@ -10,7 +10,7 @@
let
inherit (stdenv.lib) concatStringsSep makeBinPath optional optionals;
buildStatusGo = callPackage ./build-status-go.nix {
buildStatusGo = callPackage ../build.nix {
inherit buildGoPackage go xcodeWrapper utils;
};

View File

@ -3,25 +3,17 @@
pkgs ? import ./pkgs.nix { inherit config; }
}:
with pkgs;
let
localMavenRepoBuilder = callPackage ./tools/maven/maven-repo-builder.nix {
inherit stdenv;
};
inherit (pkgs) stdenv callPackage;
status-go = callPackage ./status-go {
inherit (mobile) xcodeWrapper;
androidPkgs = mobile.android.androidComposition;
};
status-go = callPackage ./status-go { };
desktop = callPackage ./desktop {
inherit darwin;
status-go = status-go.desktop;
};
mobile = callPackage ./mobile {
inherit status-go localMavenRepoBuilder;
inherit (xcodeenv) composeXcodeWrapper;
inherit status-go;
};
in {
inherit mobile desktop status-go;