nix: fix Android builds on Darwin platforms

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 <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2025-10-24 17:25:44 +02:00
parent a8060c5600
commit cb472bc829
No known key found for this signature in database
GPG Key ID: FE65CD384D5BF7B4
2 changed files with 16 additions and 16 deletions

View File

@ -16,7 +16,11 @@ assert pkgs.lib.assertMsg ((src.submodules or true) == true)
let let
inherit (pkgs) stdenv lib writeScriptBin callPackage; 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"); version = substring 0 8 (src.sourceInfo.rev or "dirty");
@ -34,18 +38,18 @@ in stdenv.mkDerivation rec {
nativeBuildInputs = let nativeBuildInputs = let
# Fix for Nim compiler calling 'git rev-parse' and 'lsb_release'. # Fix for Nim compiler calling 'git rev-parse' and 'lsb_release'.
fakeGit = writeScriptBin "git" "echo ${version}"; fakeGit = writeScriptBin "git" "echo ${version}";
in in with pkgs; [
with pkgs; [
cmake cmake
which which
lsb-release
nim-unwrapped-2_2 nim-unwrapped-2_2
fakeGit fakeGit
] ++ optionals stdenv.isLinux [
pkgs.lsb-release
]; ];
# Environment variables required for Android builds ANDROID_SDK_ROOT = optionalString isAndroidBuild pkgs.androidPkgs.sdk;
ANDROID_SDK_ROOT = "${pkgs.androidPkgs.sdk}"; ANDROID_NDK_HOME = optionalString isAndroidBuild pkgs.androidPkgs.ndk;
ANDROID_NDK_HOME = "${pkgs.androidPkgs.ndk}";
NIMFLAGS = "-d:disableMarchNative -d:git_revision_override=${version}"; NIMFLAGS = "-d:disableMarchNative -d:git_revision_override=${version}";
XDG_CACHE_HOME = "/tmp"; XDG_CACHE_HOME = "/tmp";
@ -68,8 +72,7 @@ in stdenv.mkDerivation rec {
androidManifest = '' androidManifest = ''
<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\" package=\"org.waku.${pname}\" /> <manifest xmlns:android=\"http://schemas.android.com/apk/res/android\" package=\"org.waku.${pname}\" />
''; '';
containsAndroid = s: (match ".*android.*" s) != null; in if isAndroidBuild then ''
in if (any containsAndroid targets) then ''
mkdir -p $out/jni mkdir -p $out/jni
cp -r build/* $out/jni/ cp -r build/* $out/jni/
echo '${androidManifest}' > $out/jni/AndroidManifest.xml echo '${androidManifest}' > $out/jni/AndroidManifest.xml

View File

@ -5,9 +5,6 @@
{ androidenv, lib, stdenv }: { 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.
androidenv.composeAndroidPackages { androidenv.composeAndroidPackages {