From cb472bc8296f90a7b387860064df94b95a3e3f10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Fri, 24 Oct 2025 17:25:44 +0200 Subject: [PATCH] nix: fix Android builds on Darwin platforms MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The assert for Android NDK is obsolete. But we also can avoid fetching the Android dependencies when not building for Android. Also, lsb-release is a linux-only tool. Signed-off-by: Jakub SokoĊ‚owski --- nix/default.nix | 29 ++++++++++++++++------------- nix/pkgs/android-sdk/compose.nix | 3 --- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/nix/default.nix b/nix/default.nix index 01dd252..9d3eb8a 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -16,7 +16,11 @@ assert pkgs.lib.assertMsg ((src.submodules or true) == true) let inherit (pkgs) stdenv lib writeScriptBin callPackage; - inherit (lib) any match substring; + inherit (lib) any match substring optionals optionalString; + + # Check if build is for android platform. + containsAndroid = s: (match ".*android.*" s) != null; + isAndroidBuild = any containsAndroid targets; version = substring 0 8 (src.sourceInfo.rev or "dirty"); @@ -34,18 +38,18 @@ in stdenv.mkDerivation rec { nativeBuildInputs = let # Fix for Nim compiler calling 'git rev-parse' and 'lsb_release'. fakeGit = writeScriptBin "git" "echo ${version}"; - in - with pkgs; [ - cmake - which - lsb-release - nim-unwrapped-2_2 - fakeGit + in with pkgs; [ + cmake + which + nim-unwrapped-2_2 + fakeGit + ] ++ optionals stdenv.isLinux [ + pkgs.lsb-release ]; - # Environment variables required for Android builds - ANDROID_SDK_ROOT = "${pkgs.androidPkgs.sdk}"; - ANDROID_NDK_HOME = "${pkgs.androidPkgs.ndk}"; + ANDROID_SDK_ROOT = optionalString isAndroidBuild pkgs.androidPkgs.sdk; + ANDROID_NDK_HOME = optionalString isAndroidBuild pkgs.androidPkgs.ndk; + NIMFLAGS = "-d:disableMarchNative -d:git_revision_override=${version}"; XDG_CACHE_HOME = "/tmp"; @@ -68,8 +72,7 @@ in stdenv.mkDerivation rec { androidManifest = '' ''; - containsAndroid = s: (match ".*android.*" s) != null; - in if (any containsAndroid targets) then '' + in if isAndroidBuild then '' mkdir -p $out/jni cp -r build/* $out/jni/ echo '${androidManifest}' > $out/jni/AndroidManifest.xml diff --git a/nix/pkgs/android-sdk/compose.nix b/nix/pkgs/android-sdk/compose.nix index 90291d4..9a8536d 100644 --- a/nix/pkgs/android-sdk/compose.nix +++ b/nix/pkgs/android-sdk/compose.nix @@ -5,9 +5,6 @@ { 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. androidenv.composeAndroidPackages {