77, platformToolsVersion ? "35.0.2"
88, buildToolsVersions ? [ "35.0.0" ]
99, includeEmulator ? false
10- , emulatorVersion ? "35.3.10 "
10+ , emulatorVersion ? "35.5.2 "
1111, platformVersions ? [ ]
1212, includeSources ? false
1313, includeSystemImages ? false
2727
2828let
2929 # Determine the Android os identifier from Nix's system identifier
30- os = if stdenv . hostPlatform . isLinux then "linux"
31- else if stdenv . hostPlatform . isDarwin then "macosx"
32- else throw "No Android SDK tarballs are available for system architecture: ${ stdenv . system } " ;
30+ os = {
31+ x86_64-linux = "linux" ;
32+ x86_64-darwin = "macosx" ;
33+ aarch64-linux = "linux" ;
34+ aarch64-darwin = "macosx" ;
35+ } . ${ stdenv . hostPlatform . system } or "all" ;
36+
37+ # Determine the Android arch identifier from Nix's system identifier
38+ arch = {
39+ x86_64-linux = "x64" ;
40+ x86_64-darwin = "x64" ;
41+ aarch64-linux = "aarch64" ;
42+ aarch64-darwin = "aarch64" ;
43+ } . ${ stdenv . hostPlatform . system } or "all" ;
3344
3445 # Uses mkrepo.rb to create a repo spec.
3546 mkRepoJson = { packages ? [ ] , images ? [ ] , addons ? [ ] } : let
7182 lib . attrsets . mapAttrsRecursive
7283 ( path : value :
7384 if ( builtins . elemAt path ( ( builtins . length path ) - 1 ) ) == "archives" then
74- ( builtins . listToAttrs
75- ( builtins . map
76- ( archive : lib . attrsets . nameValuePair archive . os ( fetchurl { inherit ( archive ) url sha1 ; } ) ) value ) )
85+ let
86+ validArchives = builtins . filter ( archive :
87+ let
88+ isTargetOs = if builtins . hasAttr "os" archive then
89+ archive . os == os || archive . os == "all" else true ;
90+ isTargetArc = if builtins . hasAttr "arch" archive then
91+ archive . arch == arch || archive . arch == "all" else true ;
92+ in
93+ isTargetOs && isTargetArc
94+ ) value ;
95+ in
96+ lib . warnIf ( builtins . length validArchives == 0 )
97+ "No valid archives for ${ lib . concatMapStringsSep "." ( x : ''"${ x } "'' ) path } for os=${ os } , arch=${ arch } "
98+ ( lib . optionals ( builtins . length validArchives > 0 )
99+ ( lib . last ( map ( archive :
100+ ( fetchurl { inherit ( archive ) url sha1 ; } )
101+ ) validArchives ) ) )
77102 else value
78103 )
79104 attrSet ;
@@ -117,12 +142,12 @@ rec {
117142 inherit stdenv lib mkLicenses ;
118143 } ;
119144
120- deployAndroidPackage = ( { package , os ? null , buildInputs ? [ ] , patchInstructions ? "" , meta ? { } , ...} @args :
145+ deployAndroidPackage = ( { package , buildInputs ? [ ] , patchInstructions ? "" , meta ? { } , ...} @args :
121146 let
122147 extraParams = removeAttrs args [ "package" "os" "buildInputs" "patchInstructions" ] ;
123148 in
124149 deployAndroidPackages ( {
125- inherit os buildInputs meta ;
150+ inherit buildInputs ;
126151 packages = [ package ] ;
127152 patchesInstructions = { "${ package . name } " = patchInstructions ; } ;
128153 } // extraParams
@@ -139,8 +164,7 @@ rec {
139164 '' ;
140165
141166 platform-tools = callPackage ./platform-tools.nix {
142- inherit deployAndroidPackage ;
143- os = if stdenv . system == "aarch64-darwin" then "macosx" else os ; # "macosx" is a universal binary here
167+ inherit deployAndroidPackage os ;
144168 package = check-version packages "platform-tools" platformToolsVersion ;
145169 } ;
146170
@@ -176,14 +200,12 @@ rec {
176200
177201 platforms = map ( version :
178202 deployAndroidPackage {
179- inherit os ;
180203 package = check-version packages "platforms" version ;
181204 }
182205 ) platformVersions ;
183206
184207 sources = map ( version :
185208 deployAndroidPackage {
186- inherit os ;
187209 package = check-version packages "sources" version ;
188210 }
189211 ) platformVersions ;
@@ -218,7 +240,6 @@ rec {
218240 in
219241 lib . optionals ( availablePackages != [ ] )
220242 ( deployAndroidPackages {
221- inherit os ;
222243 packages = availablePackages ;
223244 patchesInstructions = instructions ;
224245 } )
@@ -247,14 +268,12 @@ rec {
247268
248269 google-apis = map ( version :
249270 deployAndroidPackage {
250- inherit os ;
251271 package = ( check-version addons "addons" version ) . google_apis ;
252272 }
253273 ) ( builtins . filter ( platformVersion : platformVersion < "26" ) platformVersions ) ; # API level 26 and higher include Google APIs by default
254274
255275 google-tv-addons = map ( version :
256276 deployAndroidPackage {
257- inherit os ;
258277 package = ( check-version addons "addons" version ) . google_tv_addon ;
259278 }
260279 ) platformVersions ;
0 commit comments