diff options
Diffstat (limited to 'pkgs/development/mobile')
-rw-r--r-- | pkgs/development/mobile/androidenv/androidndk-pkgs.nix | 82 | ||||
-rw-r--r-- | pkgs/development/mobile/androidenv/default.nix | 15 | ||||
-rw-r--r-- | pkgs/development/mobile/imgpatchtools/default.nix | 30 |
3 files changed, 127 insertions, 0 deletions
diff --git a/pkgs/development/mobile/androidenv/androidndk-pkgs.nix b/pkgs/development/mobile/androidenv/androidndk-pkgs.nix new file mode 100644 index 000000000000..19fc0dc812d8 --- /dev/null +++ b/pkgs/development/mobile/androidenv/androidndk-pkgs.nix @@ -0,0 +1,82 @@ +{ lib, hostPlatform, targetPlatform +, makeWrapper +, runCommand, wrapBintoolsWith, wrapCCWith +, buildAndroidndk, androidndk, targetAndroidndkPkgs +}: + +let + # Mapping from a platform to information needed to unpack NDK stuff for that + # platform. + # + # N.B. The Android NDK uses slightly different LLVM-style platform triples + # than we do. We don't just use theirs because ours are less ambiguous and + # some builds need that clarity. + ndkInfoFun = { config, ... }: { + "x86_64-unknown-linux-gnu" = { + double = "linux-x86_64"; + }; + "arm-unknown-linux-androideabi" = { + arch = "arm"; + triple = "arm-linux-androideabi"; + gccVer = "4.8"; + }; + "aarch64-unknown-linux-android" = { + arch = "arm64"; + triple = "aarch64-linux-android"; + gccVer = "4.9"; + }; + }.${config} or + (throw "Android NDK doesn't support ${config}, as far as we know"); + + hostInfo = ndkInfoFun hostPlatform; + targetInfo = ndkInfoFun targetPlatform; + +in + +rec { + # Misc tools + binaries = let + ndkBinDir = + "${androidndk}/libexec/${androidndk.name}/toolchains/${targetInfo.triple}-${targetInfo.gccVer}/prebuilt/${hostInfo.double}/bin"; + in runCommand "ndk-gcc-binutils" { + isGNU = true; # for cc-wrapper + nativeBuildInputs = [ makeWrapper ]; + propgatedBuildInputs = [ androidndk ]; + } '' + mkdir -p $out/bin + for prog in ${ndkBinDir}/${targetInfo.triple}-*; do + prog_suffix=$(basename $prog | sed 's/${targetInfo.triple}-//') + ln -s $prog $out/bin/${targetPlatform.config}-$prog_suffix + done + ''; + + binutils = wrapBintoolsWith { + bintools = binaries; + libc = targetAndroidndkPkgs.libraries; + }; + + gcc = wrapCCWith { + cc = binaries; + bintools = binutils; + libc = targetAndroidndkPkgs.libraries; + extraBuildCommands = + # GCC 4.9 is the first relase with "-fstack-protector" + lib.optionalString (lib.versionOlder targetInfo.gccVer "4.9") '' + sed -E \ + -i $out/nix-support/add-hardening.sh \ + -e 's|(-fstack-protector)-strong|\1|g' + ''; + }; + + # Bionic lib C and other libraries. + # + # We use androidndk from the previous stage, else we waste time or get cycles + # cross-compiling packages to wrap incorrectly wrap binaries we don't include + # anyways. + libraries = { + name = "bionic-prebuilt"; + type = "derivation"; + outPath = "${buildAndroidndk}/libexec/${buildAndroidndk.name}/platforms/android-21/arch-${hostInfo.arch}/usr/"; + drvPath = throw "fake derivation, build ${buildAndroidndk} to use"; + }; +} diff --git a/pkgs/development/mobile/androidenv/default.nix b/pkgs/development/mobile/androidenv/default.nix index 3891ea4c6be2..b77cc68fa0e8 100644 --- a/pkgs/development/mobile/androidenv/default.nix +++ b/pkgs/development/mobile/androidenv/default.nix @@ -242,4 +242,19 @@ rec { inherit (pkgs) stdenv; inherit androidsdk; }; + + androidndkPkgs = import ./androidndk-pkgs.nix { + inherit (buildPackages) + makeWrapper; + inherit (pkgs) + lib hostPlatform targetPlatform + runCommand wrapBintoolsWith wrapCCWith; + # buildPackages.foo rather than buildPackages.buildPackages.foo would work, + # but for splicing messing up on infinite recursion for the variants we + # *dont't* use. Using this workaround, but also making a test to ensure + # these two really are the same. + buildAndroidndk = buildPackages.buildPackages.androidenv.androidndk; + inherit androidndk; + targetAndroidndkPkgs = targetPackages.androidenv.androidndkPkgs; + }; } diff --git a/pkgs/development/mobile/imgpatchtools/default.nix b/pkgs/development/mobile/imgpatchtools/default.nix new file mode 100644 index 000000000000..9cee1c9e5dee --- /dev/null +++ b/pkgs/development/mobile/imgpatchtools/default.nix @@ -0,0 +1,30 @@ +{ stdenv, fetchzip, bzip2, openssl, zlib }: + +stdenv.mkDerivation rec { + name = "imgpatchtools-${version}"; + version = "0.3"; + + src = fetchzip { + url = "https://github.com/erfanoabdi/imgpatchtools/archive/${version}.tar.gz"; + sha256 = "1cwp1hfhip252dz0mbkhrsrkws6m15k359n4amw2vfnglnls8czd"; + }; + + buildInputs = [ bzip2 openssl zlib ]; + + installPhase = "install -Dt $out/bin bin/*"; + + meta = with stdenv.lib; { + description = "Tools to manipulate Android OTA archives"; + longDescription = '' + This package is useful for Android development. In particular, it can be + used to extract ext4 /system image from Android distribution ZIP archives + such as those distributed by LineageOS and Replicant, via BlockImageUpdate + utility. It also includes other, related, but arguably more advanced tools + for OTA manipulation. + ''; + homepage = https://github.com/erfanoabdi/imgpatchtools; + license = licenses.gpl3; + maintainers = with maintainers; [ yegortimoshenko ]; + platforms = platforms.linux; + }; +} |