nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{ lib, stdenv, fetchFromGitHub, gradle, jdk, makeWrapper, perl }:
2
3let
4 pname = "jadx";
5 version = "1.4.7";
6
7 src = fetchFromGitHub {
8 owner = "skylot";
9 repo = pname;
10 rev = "v${version}";
11 hash = "sha256-3t2e3WfH/ohkdGWlfV3t9oHJ1Q6YM6nSLOgmzgJEkls=";
12 };
13
14 deps = stdenv.mkDerivation {
15 name = "${pname}-deps";
16 inherit src;
17
18 nativeBuildInputs = [ gradle jdk perl ];
19
20 buildPhase = ''
21 export GRADLE_USER_HOME=$(mktemp -d)
22 export JADX_VERSION=${version}
23 gradle --no-daemon jar
24
25 # Apparently, Gradle won't cache the `compileOnlyApi` dependency
26 # `org.jetbrains:annotations:22.0.0` which is defined in
27 # `io.github.skylot:raung-common`. To make it available in the
28 # output, we patch `build.gradle` and run Gradle again.
29 substituteInPlace build.gradle \
30 --replace 'org.jetbrains:annotations:23.0.0' 'org.jetbrains:annotations:22.0.0'
31 gradle --no-daemon jar
32 '';
33
34 # Mavenize dependency paths
35 # e.g. org.codehaus.groovy/groovy/2.4.0/{hash}/groovy-2.4.0.jar -> org/codehaus/groovy/groovy/2.4.0/groovy-2.4.0.jar
36 installPhase = ''
37 find $GRADLE_USER_HOME/caches/modules-2 -type f -regex '.*\.\(jar\|pom\)' \
38 | perl -pe 's#(.*/([^/]+)/([^/]+)/([^/]+)/[0-9a-f]{30,40}/([^/\s]+))$# ($x = $2) =~ tr|\.|/|; "install -Dm444 $1 \$out/$x/$3/$4/$5" #e' \
39 | sh
40
41 # Work around okio-2.10.0 bug, fixed in 3.0. Remove "-jvm" from filename.
42 # https://github.com/square/okio/issues/954
43 mv $out/com/squareup/okio/okio/2.10.0/okio{-jvm,}-2.10.0.jar
44 '';
45
46 outputHashMode = "recursive";
47 outputHash = "sha256-QebPRmfLtXy4ZlyKeGC5XNzhMTsYI0X36My+nTFvQpM=";
48 };
49in stdenv.mkDerivation {
50 inherit pname version src;
51
52 nativeBuildInputs = [ gradle jdk makeWrapper ];
53
54 # Otherwise, Gradle fails with `java.net.SocketException: Operation not permitted`
55 __darwinAllowLocalNetworking = true;
56
57 buildPhase = ''
58 # The installDist Gradle build phase tries to copy some dependency .jar
59 # files multiple times into the build directory. This ends up failing when
60 # the dependencies are read directly from the Nix store since they are not
61 # marked as chmod +w. To work around this, get a local copy of the
62 # dependency store, and give write permissions.
63 depsDir=$(mktemp -d)
64 cp -R ${deps}/* $depsDir
65 chmod -R u+w $depsDir
66
67 gradleInit=$(mktemp)
68 cat >$gradleInit <<EOF
69 gradle.projectsLoaded {
70 rootProject.allprojects {
71 buildscript {
72 repositories {
73 clear()
74 maven { url '$depsDir' }
75 }
76 }
77 repositories {
78 clear()
79 maven { url '$depsDir' }
80 }
81 }
82 }
83
84 settingsEvaluated { settings ->
85 settings.pluginManagement {
86 repositories {
87 maven { url '$depsDir' }
88 }
89 }
90 }
91 EOF
92
93 export GRADLE_USER_HOME=$(mktemp -d)
94 export JADX_VERSION=${version}
95 gradle --offline --no-daemon --info --init-script $gradleInit pack
96 '';
97
98 installPhase = ''
99 mkdir $out $out/bin
100 cp -R build/jadx/lib $out
101 for prog in jadx jadx-gui; do
102 cp build/jadx/bin/$prog $out/bin
103 wrapProgram $out/bin/$prog --set JAVA_HOME ${jdk.home}
104 done
105 '';
106
107 meta = with lib; {
108 description = "Dex to Java decompiler";
109 longDescription = ''
110 Command line and GUI tools for produce Java source code from Android Dex
111 and Apk files.
112 '';
113 sourceProvenance = with sourceTypes; [
114 fromSource
115 binaryBytecode # deps
116 ];
117 license = licenses.asl20;
118 platforms = platforms.unix;
119 maintainers = with maintainers; [ delroth ];
120 };
121}