From bceccb7f707c0b0cfba7288cfcb11c4832ac1272 Mon Sep 17 00:00:00 2001 From: Hadi Date: Mon, 26 Dec 2022 12:07:48 -0500 Subject: [PATCH 1/4] androidenv: Replace deploy-androidpackage.nix with deploy-androidpackages.nix --- .../androidenv/compose-android-packages.nix | 13 ++++- .../androidenv/deploy-androidpackage.nix | 46 --------------- .../androidenv/deploy-androidpackages.nix | 58 +++++++++++++++++++ 3 files changed, 70 insertions(+), 47 deletions(-) delete mode 100644 pkgs/development/mobile/androidenv/deploy-androidpackage.nix create mode 100644 pkgs/development/mobile/androidenv/deploy-androidpackages.nix diff --git a/pkgs/development/mobile/androidenv/compose-android-packages.nix b/pkgs/development/mobile/androidenv/compose-android-packages.nix index 78635dce7f8f..a862aef1f3c1 100644 --- a/pkgs/development/mobile/androidenv/compose-android-packages.nix +++ b/pkgs/development/mobile/androidenv/compose-android-packages.nix @@ -112,8 +112,19 @@ let ] ++ extraLicenses); in rec { - deployAndroidPackage = callPackage ./deploy-androidpackage.nix { + deployAndroidPackages = callPackage ./deploy-androidpackages.nix { + inherit stdenv lib mkLicenses; }; + deployAndroidPackage = ({package, os ? null, buildInputs ? [], patchInstructions ? "", meta ? {}, ...}@args: + let + extraParams = removeAttrs args [ "package" "os" "buildInputs" "patchInstructions" ]; + in + deployAndroidPackages ({ + inherit os buildInputs meta; + packages = [ package ]; + patchesInstructions = { "${package.name}" = patchInstructions; }; + } // extraParams + )); platform-tools = callPackage ./platform-tools.nix { inherit deployAndroidPackage; diff --git a/pkgs/development/mobile/androidenv/deploy-androidpackage.nix b/pkgs/development/mobile/androidenv/deploy-androidpackage.nix deleted file mode 100644 index f23558ebc5c4..000000000000 --- a/pkgs/development/mobile/androidenv/deploy-androidpackage.nix +++ /dev/null @@ -1,46 +0,0 @@ -{stdenv, unzip}: -{package, os ? null, buildInputs ? [], patchInstructions ? "", meta ? {}, ...}@args: - -let - extraParams = removeAttrs args [ "package" "os" "buildInputs" "patchInstructions" ]; -in -stdenv.mkDerivation ({ - pname = package.name; - version = package.revision; - src = if os != null && builtins.hasAttr os package.archives then package.archives.${os} else package.archives.all; - buildInputs = [ unzip ] ++ buildInputs; - preferLocalBuild = true; - - # Most Android Zip packages have a root folder, but some don't. We unpack - # the zip file in a folder and we try to discover whether it has a single root - # folder. If this is the case, we adjust the current working folder. - unpackPhase = '' - mkdir extractedzip - cd extractedzip - unpackFile "$src" - if [ "$(find . -mindepth 1 -maxdepth 1 -type d | wc -l)" -eq 1 ] - then - cd "$(find . -mindepth 1 -maxdepth 1 -type d)" - fi - sourceRoot="$PWD" - ''; - - installPhase = '' - packageBaseDir=$out/libexec/android-sdk/${package.path} - mkdir -p $packageBaseDir - cd $packageBaseDir - cp -a $sourceRoot/* . - ${patchInstructions} - ''; - - # We never attempt to strip. This is not required since we're doing binary - # deployments. Moreover, some executables that have been patched with patchelf - # may not work any longer after they have been stripped. - dontStrip = true; - dontPatchELF = true; - dontAutoPatchelf = true; - - meta = { - description = package.displayName; - } // meta; -} // extraParams) diff --git a/pkgs/development/mobile/androidenv/deploy-androidpackages.nix b/pkgs/development/mobile/androidenv/deploy-androidpackages.nix new file mode 100644 index 000000000000..96eebe2bc954 --- /dev/null +++ b/pkgs/development/mobile/androidenv/deploy-androidpackages.nix @@ -0,0 +1,58 @@ +{stdenv, lib, unzip, mkLicenses}: +{packages, os ? null, buildInputs ? [], patchesInstructions ? {}, meta ? {}, ...}@args: + +let + extraParams = removeAttrs args [ "packages" "os" "buildInputs" "patchesInstructions" ]; + sortedPackages = builtins.sort (x: y: builtins.lessThan x.name y.name) packages; +in +stdenv.mkDerivation ({ + pname = lib.concatMapStringsSep "-" (package: package.name) sortedPackages; + version = lib.concatMapStringsSep "-" (package: package.revision) sortedPackages; + src = map (package: + if os != null && builtins.hasAttr os package.archives then package.archives.${os} else package.archives.all + ) packages; + buildInputs = [ unzip ] ++ buildInputs; + preferLocalBuild = true; + + unpackPhase = '' + buildDir=$PWD + i=0 + for srcArchive in $src; do + extractedZip="extractedzip-$i" + i=$((i+1)) + cd "$buildDir" + mkdir "$extractedZip" + cd "$extractedZip" + unpackFile "$srcArchive" + done + ''; + + installPhase = lib.concatStrings (lib.imap0 (i: package: '' + cd $buildDir/extractedzip-${toString i} + + # Most Android Zip packages have a root folder, but some don't. We unpack + # the zip file in a folder and we try to discover whether it has a single root + # folder. If this is the case, we adjust the current working folder. + if [ "$(find . -mindepth 1 -maxdepth 1 -type d | wc -l)" -eq 1 ]; then + cd "$(find . -mindepth 1 -maxdepth 1 -type d)" + fi + extractedZip="$PWD" + + packageBaseDir=$out/libexec/android-sdk/${package.path} + mkdir -p $packageBaseDir + cd $packageBaseDir + cp -a $extractedZip/* . + ${patchesInstructions.${package.name}} + '') packages); + + # We never attempt to strip. This is not required since we're doing binary + # deployments. Moreover, some executables that have been patched with patchelf + # may not work any longer after they have been stripped. + dontStrip = true; + dontPatchELF = true; + dontAutoPatchelf = true; + + meta = { + description = lib.concatMapStringsSep "\n" (package: package.displayName) packages; + } // meta; +} // extraParams) From d1a1f2fa06fac055a57b28f3e15db7f8a793574c Mon Sep 17 00:00:00 2001 From: Hadi Date: Sat, 31 Dec 2022 12:21:21 -0500 Subject: [PATCH 2/4] androidenv: Fix we are using 2 spaces to intend nix code in see: https://github.com/NixOS/nixpkgs/pull/208137#discussion_r1059518929 --- pkgs/development/mobile/androidenv/examples/shell.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/development/mobile/androidenv/examples/shell.nix b/pkgs/development/mobile/androidenv/examples/shell.nix index 44db11375ff8..36c3d4da0c8e 100644 --- a/pkgs/development/mobile/androidenv/examples/shell.nix +++ b/pkgs/development/mobile/androidenv/examples/shell.nix @@ -7,13 +7,13 @@ sha256 = "1wg61h4gndm3vcprdcg7rc4s1v3jkm5xd7lw8r2f67w502y94gcy"; }), pkgs ? import nixpkgsSource { - config.allowUnfree = true; + config.allowUnfree = true; }, */ # If you want to use the in-tree version of nixpkgs: pkgs ? import ../../../../.. { - config.allowUnfree = true; + config.allowUnfree = true; }, config ? pkgs.config From 2f06edee4f9dd193167b53abd22ea75f2aeee415 Mon Sep 17 00:00:00 2001 From: Hadi Date: Tue, 3 Jan 2023 11:05:57 -0500 Subject: [PATCH 3/4] Update pkgs/development/mobile/androidenv/deploy-androidpackages.nix Co-authored-by: Sandro --- pkgs/development/mobile/androidenv/deploy-androidpackages.nix | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pkgs/development/mobile/androidenv/deploy-androidpackages.nix b/pkgs/development/mobile/androidenv/deploy-androidpackages.nix index 96eebe2bc954..521101513ff2 100644 --- a/pkgs/development/mobile/androidenv/deploy-androidpackages.nix +++ b/pkgs/development/mobile/androidenv/deploy-androidpackages.nix @@ -45,9 +45,7 @@ stdenv.mkDerivation ({ ${patchesInstructions.${package.name}} '') packages); - # We never attempt to strip. This is not required since we're doing binary - # deployments. Moreover, some executables that have been patched with patchelf - # may not work any longer after they have been stripped. + # Some executables that have been patched with patchelf may not work any longer after they have been stripped. dontStrip = true; dontPatchELF = true; dontAutoPatchelf = true; From 8ca4470a5e72131b3687856cd60848dd46dda4a7 Mon Sep 17 00:00:00 2001 From: Hadi Date: Tue, 3 Jan 2023 18:15:27 -0500 Subject: [PATCH 4/4] androidenv: use unzip in nativeBuildInputs --- .../mobile/androidenv/deploy-androidpackages.nix | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkgs/development/mobile/androidenv/deploy-androidpackages.nix b/pkgs/development/mobile/androidenv/deploy-androidpackages.nix index 521101513ff2..d495f2afd466 100644 --- a/pkgs/development/mobile/androidenv/deploy-androidpackages.nix +++ b/pkgs/development/mobile/androidenv/deploy-androidpackages.nix @@ -1,17 +1,18 @@ {stdenv, lib, unzip, mkLicenses}: -{packages, os ? null, buildInputs ? [], patchesInstructions ? {}, meta ? {}, ...}@args: +{packages, os ? null, nativeBuildInputs ? [], buildInputs ? [], patchesInstructions ? {}, meta ? {}, ...}@args: let - extraParams = removeAttrs args [ "packages" "os" "buildInputs" "patchesInstructions" ]; + extraParams = removeAttrs args [ "packages" "os" "buildInputs" "nativeBuildInputs" "patchesInstructions" ]; sortedPackages = builtins.sort (x: y: builtins.lessThan x.name y.name) packages; in stdenv.mkDerivation ({ + inherit buildInputs; pname = lib.concatMapStringsSep "-" (package: package.name) sortedPackages; version = lib.concatMapStringsSep "-" (package: package.revision) sortedPackages; src = map (package: if os != null && builtins.hasAttr os package.archives then package.archives.${os} else package.archives.all ) packages; - buildInputs = [ unzip ] ++ buildInputs; + nativeBuildInputs = [ unzip ] ++ nativeBuildInputs; preferLocalBuild = true; unpackPhase = ''