nix: fix Android SDK on Darwin with nixpkgs system override

Android SDK in nixpkg doesn't support `aarch64-darwin`, for details see
https://github.com/status-im/status-mobile/issues/12794

The workaround was to run terminal application with Rosetta or make with `aarch` tool.

This PR overrides system architecture to always be `x86_64` for Android shell and build targets ran by make.
CI is not affected as it runs `nix` directly.

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Anton Iakimov 2023-06-09 14:51:33 +02:00
parent 6d6e6b1eff
commit 5dcd64c478
No known key found for this signature in database
GPG Key ID: AD7E5196382127EA
4 changed files with 28 additions and 3 deletions

View File

@ -17,9 +17,20 @@ let
# Override some packages and utilities # Override some packages and utilities
pkgsOverlay = import ./overlay.nix; pkgsOverlay = import ./overlay.nix;
# Fix for lack of Android SDK for M1 Macs.
systemOverride = let
inherit (builtins) currentSystem getEnv;
envSystemOverride = getEnv "NIXPKGS_SYSTEM_OVERRIDE";
in
if envSystemOverride != "" then
envSystemOverride
else
currentSystem;
in in
# import nixpkgs with a config override # import nixpkgs with a config override
(import nixpkgsSrc) { (import nixpkgsSrc) {
config = defaultConfig // config; config = defaultConfig // config;
system = systemOverride;
overlays = [ pkgsOverlay ]; overlays = [ pkgsOverlay ];
} }

View File

@ -3,7 +3,10 @@
# for the Android development environment. # for the Android development environment.
# #
{ androidenv }: { androidenv, lib, stdenv }:
assert lib.assertMsg (stdenv.system != "aarch64-darwin")
"aarch64-darwin not supported for Android SDK. Use: NIXPKGS_SYSTEM_OVERRIDE=x86_64-darwin";
# The "android-sdk-license" license is accepted # The "android-sdk-license" license is accepted
# by setting android_sdk.accept_license = true. # by setting android_sdk.accept_license = true.

View File

@ -25,7 +25,7 @@ cleanup() {
# If you want to clean after every build set _NIX_CLEAN=true # If you want to clean after every build set _NIX_CLEAN=true
if [[ -n "${_NIX_CLEAN}" ]]; then if [[ -n "${_NIX_CLEAN}" ]]; then
trap cleanup EXIT ERR INT QUIT trap cleanup EXIT ERR INT QUIT
fi fi
# build output will end up under /nix, we have to extract it # build output will end up under /nix, we have to extract it
@ -44,6 +44,12 @@ if [[ -z "${TARGET}" ]]; then
exit 1 exit 1
fi fi
# Hack fix for missing Android SDK for aarch64 on Darwin. See systemOverride in `nix/pkgs.nix`.
if [[ "${TARGET}" =~ ^(targets.status-go.mobile.android|targets.mobile.android.release)$ ]]; then
os=$(uname -s | tr '[:upper:]' '[:lower:]')
export NIXPKGS_SYSTEM_OVERRIDE="x86_64-${os}"
fi
# Some defaults flags, --pure could be optional in the future. # Some defaults flags, --pure could be optional in the future.
# NOTE: The --keep-failed flag can be used for debugging issues. # NOTE: The --keep-failed flag can be used for debugging issues.
nixOpts=( nixOpts=(

View File

@ -1,6 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
#
# This script is used by the Makefile to have an implicit nix-shell. # This script is used by the Makefile to have an implicit nix-shell.
# The following environment variables modify the script behavior: # The following environment variables modify the script behavior:
# - TARGET: This attribute is passed via --attr to Nix, defining the scope. # - TARGET: This attribute is passed via --attr to Nix, defining the scope.
@ -64,6 +63,12 @@ if [[ -n "${_NIX_PURE}" ]]; then
pureDesc='pure ' pureDesc='pure '
fi fi
# Hack fix for missing Android SDK for aarch64 on Darwin. See systemOverride in `nix/pkgs.nix`.
if [[ "${TARGET}" =~ ^(android-sdk|android|gradle|keytool|status-go)$ ]]; then
os=$(uname -s | tr '[:upper:]' '[:lower:]')
export NIXPKGS_SYSTEM_OVERRIDE="x86_64-${os}"
fi
echo -e "${GRN}Configuring ${pureDesc}Nix shell for target '${TARGET}'...${RST}" 1>&2 echo -e "${GRN}Configuring ${pureDesc}Nix shell for target '${TARGET}'...${RST}" 1>&2
# Save derivation from being garbage collected # Save derivation from being garbage collected