···11-{stdenv, unzip}:
22-{package, os ? null, buildInputs ? [], patchInstructions ? "", meta ? {}, ...}@args:
33-44-let
55- extraParams = removeAttrs args [ "package" "os" "buildInputs" "patchInstructions" ];
66-in
77-stdenv.mkDerivation ({
88- pname = package.name;
99- version = package.revision;
1010- src = if os != null && builtins.hasAttr os package.archives then package.archives.${os} else package.archives.all;
1111- buildInputs = [ unzip ] ++ buildInputs;
1212- preferLocalBuild = true;
1313-1414- # Most Android Zip packages have a root folder, but some don't. We unpack
1515- # the zip file in a folder and we try to discover whether it has a single root
1616- # folder. If this is the case, we adjust the current working folder.
1717- unpackPhase = ''
1818- mkdir extractedzip
1919- cd extractedzip
2020- unpackFile "$src"
2121- if [ "$(find . -mindepth 1 -maxdepth 1 -type d | wc -l)" -eq 1 ]
2222- then
2323- cd "$(find . -mindepth 1 -maxdepth 1 -type d)"
2424- fi
2525- sourceRoot="$PWD"
2626- '';
2727-2828- installPhase = ''
2929- packageBaseDir=$out/libexec/android-sdk/${package.path}
3030- mkdir -p $packageBaseDir
3131- cd $packageBaseDir
3232- cp -a $sourceRoot/* .
3333- ${patchInstructions}
3434- '';
3535-3636- # We never attempt to strip. This is not required since we're doing binary
3737- # deployments. Moreover, some executables that have been patched with patchelf
3838- # may not work any longer after they have been stripped.
3939- dontStrip = true;
4040- dontPatchELF = true;
4141- dontAutoPatchelf = true;
4242-4343- meta = {
4444- description = package.displayName;
4545- } // meta;
4646-} // extraParams)
···11+{stdenv, lib, unzip, mkLicenses}:
22+{packages, os ? null, nativeBuildInputs ? [], buildInputs ? [], patchesInstructions ? {}, meta ? {}, ...}@args:
33+44+let
55+ extraParams = removeAttrs args [ "packages" "os" "buildInputs" "nativeBuildInputs" "patchesInstructions" ];
66+ sortedPackages = builtins.sort (x: y: builtins.lessThan x.name y.name) packages;
77+in
88+stdenv.mkDerivation ({
99+ inherit buildInputs;
1010+ pname = lib.concatMapStringsSep "-" (package: package.name) sortedPackages;
1111+ version = lib.concatMapStringsSep "-" (package: package.revision) sortedPackages;
1212+ src = map (package:
1313+ if os != null && builtins.hasAttr os package.archives then package.archives.${os} else package.archives.all
1414+ ) packages;
1515+ nativeBuildInputs = [ unzip ] ++ nativeBuildInputs;
1616+ preferLocalBuild = true;
1717+1818+ unpackPhase = ''
1919+ buildDir=$PWD
2020+ i=0
2121+ for srcArchive in $src; do
2222+ extractedZip="extractedzip-$i"
2323+ i=$((i+1))
2424+ cd "$buildDir"
2525+ mkdir "$extractedZip"
2626+ cd "$extractedZip"
2727+ unpackFile "$srcArchive"
2828+ done
2929+ '';
3030+3131+ installPhase = lib.concatStrings (lib.imap0 (i: package: ''
3232+ cd $buildDir/extractedzip-${toString i}
3333+3434+ # Most Android Zip packages have a root folder, but some don't. We unpack
3535+ # the zip file in a folder and we try to discover whether it has a single root
3636+ # folder. If this is the case, we adjust the current working folder.
3737+ if [ "$(find . -mindepth 1 -maxdepth 1 -type d | wc -l)" -eq 1 ]; then
3838+ cd "$(find . -mindepth 1 -maxdepth 1 -type d)"
3939+ fi
4040+ extractedZip="$PWD"
4141+4242+ packageBaseDir=$out/libexec/android-sdk/${package.path}
4343+ mkdir -p $packageBaseDir
4444+ cd $packageBaseDir
4545+ cp -a $extractedZip/* .
4646+ ${patchesInstructions.${package.name}}
4747+ '') packages);
4848+4949+ # Some executables that have been patched with patchelf may not work any longer after they have been stripped.
5050+ dontStrip = true;
5151+ dontPatchELF = true;
5252+ dontAutoPatchelf = true;
5353+5454+ meta = {
5555+ description = lib.concatMapStringsSep "\n" (package: package.displayName) packages;
5656+ } // meta;
5757+} // extraParams)