diff --git a/nix/pkgs.nix b/nix/pkgs.nix index a8e3292474..9b178f42cb 100644 --- a/nix/pkgs.nix +++ b/nix/pkgs.nix @@ -17,9 +17,20 @@ let # Override some packages and utilities 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 # import nixpkgs with a config override (import nixpkgsSrc) { config = defaultConfig // config; + system = systemOverride; overlays = [ pkgsOverlay ]; } diff --git a/nix/pkgs/android-sdk/compose.nix b/nix/pkgs/android-sdk/compose.nix index 3f9e3c18c9..259daea044 100644 --- a/nix/pkgs/android-sdk/compose.nix +++ b/nix/pkgs/android-sdk/compose.nix @@ -3,7 +3,10 @@ # 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 # by setting android_sdk.accept_license = true. diff --git a/nix/scripts/build.sh b/nix/scripts/build.sh index 2c9cea1c6d..d9dd8f656a 100755 --- a/nix/scripts/build.sh +++ b/nix/scripts/build.sh @@ -25,7 +25,7 @@ cleanup() { # If you want to clean after every build set _NIX_CLEAN=true if [[ -n "${_NIX_CLEAN}" ]]; then - trap cleanup EXIT ERR INT QUIT + trap cleanup EXIT ERR INT QUIT fi # build output will end up under /nix, we have to extract it @@ -44,6 +44,12 @@ if [[ -z "${TARGET}" ]]; then exit 1 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. # NOTE: The --keep-failed flag can be used for debugging issues. nixOpts=( diff --git a/nix/scripts/shell.sh b/nix/scripts/shell.sh index 4c61a21ef6..0a64e1d182 100755 --- a/nix/scripts/shell.sh +++ b/nix/scripts/shell.sh @@ -1,6 +1,5 @@ #!/usr/bin/env bash -# # This script is used by the Makefile to have an implicit nix-shell. # The following environment variables modify the script behavior: # - TARGET: This attribute is passed via --attr to Nix, defining the scope. @@ -64,6 +63,12 @@ if [[ -n "${_NIX_PURE}" ]]; then pureDesc='pure ' 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 # Save derivation from being garbage collected