Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at netboot-syslinux-multiplatform 151 lines 4.9 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/towards-reproducibility-pinning-nixpkgs.html 6 /*nixpkgsSource ? (builtins.fetchTarball { 7 name = "nixpkgs-20.09"; 8 url = "https://github.com/NixOS/nixpkgs/archive/20.09.tar.gz"; 9 sha256 = "1wg61h4gndm3vcprdcg7rc4s1v3jkm5xd7lw8r2f67w502y94gcy"; 10 }), 11 pkgs ? import nixpkgsSource { 12 config.allowUnfree = true; 13 }, 14 */ 15 16 # If you want to use the in-tree version of nixpkgs: 17 pkgs ? import ../../../../.. { 18 config.allowUnfree = true; 19 }, 20 21 config ? pkgs.config 22}: 23 24# Copy this file to your Android project. 25let 26 # Declaration of versions for everything. This is useful since these 27 # versions may be used in multiple places in this Nix expression. 28 android = { 29 platforms = [ "33" ]; 30 systemImageTypes = [ "google_apis" ]; 31 abis = [ "arm64-v8a" "x86_64" ]; 32 }; 33 34 # If you copy this example out of nixpkgs, something like this will work: 35 /*androidEnvNixpkgs = fetchTarball { 36 name = "androidenv"; 37 url = "https://github.com/NixOS/nixpkgs/archive/<fill me in from Git>.tar.gz"; 38 sha256 = "<fill me in with nix-prefetch-url --unpack>"; 39 }; 40 41 androidEnv = pkgs.callPackage "${androidEnvNixpkgs}/pkgs/development/mobile/androidenv" { 42 inherit config pkgs; 43 licenseAccepted = true; 44 };*/ 45 46 # Otherwise, just use the in-tree androidenv: 47 androidEnv = pkgs.callPackage ./.. { 48 inherit config pkgs; 49 # You probably need to uncomment below line to express consent. 50 # licenseAccepted = true; 51 }; 52 53 sdkArgs = { 54 platformVersions = android.platforms; 55 abiVersions = android.abis; 56 systemImageTypes = android.systemImageTypes; 57 58 includeSystemImages = true; 59 includeEmulator = true; 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 androidEmulator = androidEnv.emulateApp { 80 name = "android-sdk-emulator-demo"; 81 sdkExtraArgs = sdkArgs; 82 }; 83 androidSdk = androidComposition.androidsdk; 84 platformTools = androidComposition.platform-tools; 85 jdk = pkgs.jdk; 86in 87pkgs.mkShell rec { 88 name = "androidenv-demo"; 89 packages = [ androidSdk platformTools androidEmulator jdk pkgs.android-studio ]; 90 91 LANG = "C.UTF-8"; 92 LC_ALL = "C.UTF-8"; 93 JAVA_HOME = jdk.home; 94 95 # Note: ANDROID_HOME is deprecated. Use ANDROID_SDK_ROOT. 96 ANDROID_SDK_ROOT = "${androidSdk}/libexec/android-sdk"; 97 ANDROID_NDK_ROOT = "${ANDROID_SDK_ROOT}/ndk-bundle"; 98 99 shellHook = '' 100 # Write out local.properties for Android Studio. 101 cat <<EOF > local.properties 102 # This file was automatically generated by nix-shell. 103 sdk.dir=$ANDROID_SDK_ROOT 104 ndk.dir=$ANDROID_NDK_ROOT 105 EOF 106 ''; 107 108 passthru.tests = { 109 110 shell-with-emulator-sdkmanager-packages-test = pkgs.runCommand "shell-with-emulator-sdkmanager-packages-test" { 111 nativeBuildInputs = [ androidSdk jdk ]; 112 } '' 113 output="$(sdkmanager --list)" 114 installed_packages_section=$(echo "''${output%%Available Packages*}" | awk 'NR>4 {print $1}') 115 echo "installed_packages_section: ''${installed_packages_section}" 116 117 packages=( 118 "build-tools;33.0.2" "cmdline-tools;9.0" \ 119 "emulator" "patcher;v4" "platform-tools" "platforms;android-33" \ 120 "system-images;android-33;google_apis;arm64-v8a" \ 121 "system-images;android-33;google_apis;x86_64" 122 ) 123 124 for package in "''${packages[@]}"; do 125 if [[ ! $installed_packages_section =~ "$package" ]]; then 126 echo "$package package was not installed." 127 exit 1 128 fi 129 done 130 131 touch "$out" 132 ''; 133 134 shell-with-emulator-avdmanager-create-avd-test = pkgs.runCommand "shell-with-emulator-avdmanager-create-avd-test" { 135 nativeBuildInputs = [ androidSdk androidEmulator jdk ]; 136 } '' 137 avdmanager delete avd -n testAVD || true 138 echo "" | avdmanager create avd --force --name testAVD --package 'system-images;android-33;google_apis;x86_64' 139 result=$(avdmanager list avd) 140 141 if [[ ! $result =~ "Name: testAVD" ]]; then 142 echo "avdmanager couldn't create the avd! The output is :''${result}" 143 exit 1 144 fi 145 146 avdmanager delete avd -n testAVD || true 147 touch "$out" 148 ''; 149 }; 150} 151