Merge pull request #208380 from hadilq/androidenv/support-deplying-multiple-packages-in-one-derivation

androidenv: Support deploying multiple packages in one derivation

authored by Artturi and committed by GitHub a6c9e510 66626be3

+71 -49
+12 -1
pkgs/development/mobile/androidenv/compose-android-packages.nix
··· 112 ] ++ extraLicenses); 113 in 114 rec { 115 - deployAndroidPackage = callPackage ./deploy-androidpackage.nix { 116 }; 117 118 platform-tools = callPackage ./platform-tools.nix { 119 inherit deployAndroidPackage;
··· 112 ] ++ extraLicenses); 113 in 114 rec { 115 + deployAndroidPackages = callPackage ./deploy-androidpackages.nix { 116 + inherit stdenv lib mkLicenses; 117 }; 118 + deployAndroidPackage = ({package, os ? null, buildInputs ? [], patchInstructions ? "", meta ? {}, ...}@args: 119 + let 120 + extraParams = removeAttrs args [ "package" "os" "buildInputs" "patchInstructions" ]; 121 + in 122 + deployAndroidPackages ({ 123 + inherit os buildInputs meta; 124 + packages = [ package ]; 125 + patchesInstructions = { "${package.name}" = patchInstructions; }; 126 + } // extraParams 127 + )); 128 129 platform-tools = callPackage ./platform-tools.nix { 130 inherit deployAndroidPackage;
-46
pkgs/development/mobile/androidenv/deploy-androidpackage.nix
··· 1 - {stdenv, unzip}: 2 - {package, os ? null, buildInputs ? [], patchInstructions ? "", meta ? {}, ...}@args: 3 - 4 - let 5 - extraParams = removeAttrs args [ "package" "os" "buildInputs" "patchInstructions" ]; 6 - in 7 - stdenv.mkDerivation ({ 8 - pname = package.name; 9 - version = package.revision; 10 - src = if os != null && builtins.hasAttr os package.archives then package.archives.${os} else package.archives.all; 11 - buildInputs = [ unzip ] ++ buildInputs; 12 - preferLocalBuild = true; 13 - 14 - # Most Android Zip packages have a root folder, but some don't. We unpack 15 - # the zip file in a folder and we try to discover whether it has a single root 16 - # folder. If this is the case, we adjust the current working folder. 17 - unpackPhase = '' 18 - mkdir extractedzip 19 - cd extractedzip 20 - unpackFile "$src" 21 - if [ "$(find . -mindepth 1 -maxdepth 1 -type d | wc -l)" -eq 1 ] 22 - then 23 - cd "$(find . -mindepth 1 -maxdepth 1 -type d)" 24 - fi 25 - sourceRoot="$PWD" 26 - ''; 27 - 28 - installPhase = '' 29 - packageBaseDir=$out/libexec/android-sdk/${package.path} 30 - mkdir -p $packageBaseDir 31 - cd $packageBaseDir 32 - cp -a $sourceRoot/* . 33 - ${patchInstructions} 34 - ''; 35 - 36 - # We never attempt to strip. This is not required since we're doing binary 37 - # deployments. Moreover, some executables that have been patched with patchelf 38 - # may not work any longer after they have been stripped. 39 - dontStrip = true; 40 - dontPatchELF = true; 41 - dontAutoPatchelf = true; 42 - 43 - meta = { 44 - description = package.displayName; 45 - } // meta; 46 - } // extraParams)
···
+57
pkgs/development/mobile/androidenv/deploy-androidpackages.nix
···
··· 1 + {stdenv, lib, unzip, mkLicenses}: 2 + {packages, os ? null, nativeBuildInputs ? [], buildInputs ? [], patchesInstructions ? {}, meta ? {}, ...}@args: 3 + 4 + let 5 + extraParams = removeAttrs args [ "packages" "os" "buildInputs" "nativeBuildInputs" "patchesInstructions" ]; 6 + sortedPackages = builtins.sort (x: y: builtins.lessThan x.name y.name) packages; 7 + in 8 + stdenv.mkDerivation ({ 9 + inherit buildInputs; 10 + pname = lib.concatMapStringsSep "-" (package: package.name) sortedPackages; 11 + version = lib.concatMapStringsSep "-" (package: package.revision) sortedPackages; 12 + src = map (package: 13 + if os != null && builtins.hasAttr os package.archives then package.archives.${os} else package.archives.all 14 + ) packages; 15 + nativeBuildInputs = [ unzip ] ++ nativeBuildInputs; 16 + preferLocalBuild = true; 17 + 18 + unpackPhase = '' 19 + buildDir=$PWD 20 + i=0 21 + for srcArchive in $src; do 22 + extractedZip="extractedzip-$i" 23 + i=$((i+1)) 24 + cd "$buildDir" 25 + mkdir "$extractedZip" 26 + cd "$extractedZip" 27 + unpackFile "$srcArchive" 28 + done 29 + ''; 30 + 31 + installPhase = lib.concatStrings (lib.imap0 (i: package: '' 32 + cd $buildDir/extractedzip-${toString i} 33 + 34 + # Most Android Zip packages have a root folder, but some don't. We unpack 35 + # the zip file in a folder and we try to discover whether it has a single root 36 + # folder. If this is the case, we adjust the current working folder. 37 + if [ "$(find . -mindepth 1 -maxdepth 1 -type d | wc -l)" -eq 1 ]; then 38 + cd "$(find . -mindepth 1 -maxdepth 1 -type d)" 39 + fi 40 + extractedZip="$PWD" 41 + 42 + packageBaseDir=$out/libexec/android-sdk/${package.path} 43 + mkdir -p $packageBaseDir 44 + cd $packageBaseDir 45 + cp -a $extractedZip/* . 46 + ${patchesInstructions.${package.name}} 47 + '') packages); 48 + 49 + # Some executables that have been patched with patchelf may not work any longer after they have been stripped. 50 + dontStrip = true; 51 + dontPatchELF = true; 52 + dontAutoPatchelf = true; 53 + 54 + meta = { 55 + description = lib.concatMapStringsSep "\n" (package: package.displayName) packages; 56 + } // meta; 57 + } // extraParams)
+2 -2
pkgs/development/mobile/androidenv/examples/shell.nix
··· 7 sha256 = "1wg61h4gndm3vcprdcg7rc4s1v3jkm5xd7lw8r2f67w502y94gcy"; 8 }), 9 pkgs ? import nixpkgsSource { 10 - config.allowUnfree = true; 11 }, 12 */ 13 14 # If you want to use the in-tree version of nixpkgs: 15 pkgs ? import ../../../../.. { 16 - config.allowUnfree = true; 17 }, 18 19 config ? pkgs.config
··· 7 sha256 = "1wg61h4gndm3vcprdcg7rc4s1v3jkm5xd7lw8r2f67w502y94gcy"; 8 }), 9 pkgs ? import nixpkgsSource { 10 + config.allowUnfree = true; 11 }, 12 */ 13 14 # If you want to use the in-tree version of nixpkgs: 15 pkgs ? import ../../../../.. { 16 + config.allowUnfree = true; 17 }, 18 19 config ? pkgs.config