nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 164 lines 4.7 kB view raw
1{ 2 # To test your changes in androidEnv run `nix-shell android-sdk-with-emulator-shell.nix` 3 4 # If you copy this example out of nixpkgs, use these lines instead of the next. 5 # This example pins nixpkgs: https://nix.dev/tutorials/first-steps/towards-reproducibility-pinning-nixpkgs.html 6 /* 7 nixpkgsSource ? (fetchTarball { 8 name = "nixpkgs-20.09"; 9 url = "https://github.com/NixOS/nixpkgs/archive/20.09.tar.gz"; 10 sha256 = "1wg61h4gndm3vcprdcg7rc4s1v3jkm5xd7lw8r2f67w502y94gcy"; 11 }), 12 pkgs ? import nixpkgsSource { 13 config.allowUnfree = true; 14 }, 15 */ 16 17 # If you want to use the in-tree version of nixpkgs: 18 pkgs ? import ../../../../.. { 19 config.allowUnfree = true; 20 }, 21 22 licenseAccepted ? pkgs.callPackage ../license.nix { }, 23}: 24 25# Copy this file to your Android project. 26let 27 # If you copy this example out of nixpkgs, something like this will work: 28 /* 29 androidEnvNixpkgs = fetchTarball { 30 name = "androidenv"; 31 url = "https://github.com/NixOS/nixpkgs/archive/<fill me in from Git>.tar.gz"; 32 sha256 = "<fill me in with nix-prefetch-url --unpack>"; 33 }; 34 35 androidEnv = pkgs.callPackage "${androidEnvNixpkgs}/pkgs/development/mobile/androidenv" { 36 inherit pkgs; 37 licenseAccepted = true; 38 }; 39 */ 40 41 inherit (pkgs) lib; 42 43 # Otherwise, just use the in-tree androidenv: 44 androidEnv = pkgs.callPackage ./.. { 45 inherit pkgs licenseAccepted; 46 }; 47 48 sdkArgs = { 49 includeNDK = false; 50 includeSystemImages = false; 51 includeEmulator = false; 52 53 platformVersions = [ 54 "UpsideDownCake" 55 "36" 56 "36x" 57 "latest" 58 "CANARY" 59 ]; 60 61 # Accepting more licenses declaratively: 62 extraLicenses = [ 63 # Already accepted for you with the global accept_license = true or 64 # licenseAccepted = true on androidenv. 65 # "android-sdk-license" 66 67 # These aren't, but are useful for more uncommon setups. 68 "android-sdk-preview-license" 69 "android-googletv-license" 70 "android-sdk-arm-dbt-license" 71 "google-gdk-license" 72 "intel-android-extra-license" 73 "intel-android-sysimage-license" 74 "mips-android-sysimage-license" 75 ]; 76 }; 77 78 androidComposition = androidEnv.composeAndroidPackages sdkArgs; 79 androidSdk = androidComposition.androidsdk; 80 platformTools = androidComposition.platform-tools; 81 latestSdkVersion = lib.foldl' ( 82 s: x: if lib.strings.compareVersions (toString x) s > 0 then toString x else s 83 ) "0" androidComposition.platformVersions; 84 jdk = pkgs.jdk; 85in 86pkgs.mkShell { 87 name = "androidenv-example-without-emulator-demo"; 88 packages = [ 89 androidSdk 90 platformTools 91 jdk 92 ]; 93 94 LANG = "C.UTF-8"; 95 LC_ALL = "C.UTF-8"; 96 JAVA_HOME = jdk.home; 97 98 # Note: ANDROID_HOME is deprecated. Use ANDROID_SDK_ROOT. 99 ANDROID_SDK_ROOT = "${androidSdk}/libexec/android-sdk"; 100 101 shellHook = '' 102 # Write out local.properties for Android Studio. 103 cat <<EOF > local.properties 104 # This file was automatically generated by nix-shell. 105 sdk.dir=$ANDROID_SDK_ROOT 106 EOF 107 ''; 108 109 passthru.tests = { 110 shell-without-emulator-sdkmanager-packages-test = 111 pkgs.runCommand "shell-without-emulator-sdkmanager-packages-test" 112 { 113 nativeBuildInputs = [ 114 androidSdk 115 jdk 116 ]; 117 } 118 '' 119 output="$(sdkmanager --list)" 120 installed_packages_section=$(echo "''${output%%Available Packages*}" | awk 'NR>4 {print $1}') 121 echo "installed_packages_section: ''${installed_packages_section}" 122 123 packages=( 124 "build-tools" "cmdline-tools" \ 125 "platform-tools" "platforms;android-${toString latestSdkVersion}" 126 ) 127 128 for package in "''${packages[@]}"; do 129 if [[ ! $installed_packages_section =~ "$package" ]]; then 130 echo "$package package was not installed." 131 exit 1 132 fi 133 done 134 135 touch "$out" 136 ''; 137 138 shell-without-emulator-sdkmanager-excluded-packages-test = 139 pkgs.runCommand "shell-without-emulator-sdkmanager-excluded-packages-test" 140 { 141 nativeBuildInputs = [ 142 androidSdk 143 jdk 144 ]; 145 } 146 '' 147 output="$(sdkmanager --list)" 148 installed_packages_section=$(echo "''${output%%Available Packages*}" | awk 'NR>4 {print $1}') 149 150 excluded_packages=( 151 "emulator" "ndk" 152 ) 153 154 for package in "''${excluded_packages[@]}"; do 155 if [[ $installed_packages_section =~ "$package" ]]; then 156 echo "$package package was installed, while it was excluded!" 157 exit 1 158 fi 159 done 160 161 touch "$out" 162 ''; 163 }; 164}