git.iko.soy/typeable/nixpkgs
on master help sign in
gomobile: init at 2020-06-22

The Android SDK is provided by `nixpkgs`, and in case of the Status Project we build our app using that SDK in combination with gomobile since our protocol library is written in Go: https://github.com/golang/mobile This tool is quite powerful and allows you even to build entire applications in Go: https://pkg.go.dev/golang.org/x/mobile/cmd/gomobile#hdr-Compile_android_APK_and_iOS_app Signed-off-by: Jakub Sokołowski <jakub@status.im>

commitdd2a8245a15167b271854cff7df040f813d4084d authorJakub Sokołowski <jakub@status.im> dateThu 18 Mar 2021, 13:51 (6 years ago) parentc7bfba0
3 files changed+80
pkgs/development/mobile/gomobile/default.nix+61 pkgs/development/mobile/gomobile/resolve-nix-android-sdk.patch+15 pkgs/top-level/all-packages.nix+4
pkgs/development/mobile/gomobile/default.nixnew file+61
@@ -0,0 +1,61 @@
1+{ stdenv, lib, fetchgit, buildGoModule, zlib, makeWrapper, xcodeenv, androidenv
2+, xcodeWrapperArgs ? { }
3+, xcodeWrapper ? xcodeenv.composeXcodeWrapper xcodeWrapperArgs
4+, androidPkgs ? androidenv.composeAndroidPackages {
5+ includeNDK = true;
6+ ndkVersion = "21.3.6528147"; # WARNING: 22.0.7026061 is broken.
7+ } }:
8+
9+buildGoModule {
10+ pname = "gomobile";
11+ version = "unstable-2020-06-22";
12+
13+ vendorSha256 = "1n1338vqkc1n8cy94501n7jn3qbr28q9d9zxnq2b4rxsqjfc9l94";
14+
15+ src = fetchgit {
16+ # WARNING: Next commit removes support for ARM 32 bit builds for iOS
17+ rev = "33b80540585f2b31e503da24d6b2a02de3c53ff5";
18+ name = "gomobile";
19+ url = "https://go.googlesource.com/mobile";
20+ sha256 = "0c9map2vrv34wmaycsv71k4day3b0z5p16yzxmlp8amvqb38zwlm";
21+ };
22+
23+ subPackages = [ "bind" "cmd/gobind" "cmd/gomobile" ];
24+
25+ # Fails with: go: cannot find GOROOT directory
26+ doCheck = false;
27+
28+ patches = [ ./resolve-nix-android-sdk.patch ];
29+
30+ nativeBuildInputs = [ makeWrapper ]
31+ ++ lib.optionals stdenv.isDarwin [ xcodeWrapper ];
32+
33+ # Prevent a non-deterministic temporary directory from polluting the resulting object files
34+ postPatch = ''
35+ substituteInPlace cmd/gomobile/env.go --replace \
36+ 'tmpdir, err = ioutil.TempDir("", "gomobile-work-")' \
37+ 'tmpdir = filepath.Join(os.Getenv("NIX_BUILD_TOP"), "gomobile-work")' \
38+ --replace '"io/ioutil"' ""
39+ substituteInPlace cmd/gomobile/init.go --replace \
40+ 'tmpdir, err = ioutil.TempDir(gomobilepath, "work-")' \
41+ 'tmpdir = filepath.Join(os.Getenv("NIX_BUILD_TOP"), "work")'
42+ '';
43+
44+ # Necessary for GOPATH when using gomobile.
45+ postInstall = ''
46+ mkdir -p $out/src/golang.org/x
47+ ln -s $src $out/src/golang.org/x/mobile
48+ wrapProgram $out/bin/gomobile \
49+ --prefix LD_LIBRARY_PATH : "${lib.makeLibraryPath [ zlib ]}" \
50+ --prefix PATH : "${androidPkgs.androidsdk}/bin" \
51+ --set ANDROID_HOME "${androidPkgs.androidsdk}/libexec/android-sdk" \
52+ --set GOPATH $out
53+ '';
54+
55+ meta = with lib; {
56+ description = "A tool for building and running mobile apps written in Go";
57+ homepage = "https://pkg.go.dev/golang.org/x/mobile/cmd/gomobile";
58+ license = licenses.bsd3;
59+ maintainers = with maintainers; [ jakubgs ];
60+ };
61+}
pkgs/development/mobile/gomobile/resolve-nix-android-sdk.patchnew file+15
@@ -0,0 +1,15 @@
1+diff --git a/cmd/gomobile/bind_androidapp.go b/cmd/gomobile/bind_androidapp.go
2+index 3b01adc..76216fa 100644
3+--- a/cmd/gomobile/bind_androidapp.go
4++++ b/cmd/gomobile/bind_androidapp.go
5+@@ -372,6 +372,10 @@ func androidAPIPath() (string, error) {
6+ var apiVer int
7+ for _, fi := range fis {
8+ name := fi.Name()
9++ // Resolve symlinked directories (this is how the Nix Android SDK package is built)
10++ if fi2, err := os.Stat(filepath.Join(sdkDir.Name(), name)); err == nil {
11++ fi = fi2
12++ }
13+ if !fi.IsDir() || !strings.HasPrefix(name, "android-") {
14+ continue
15+ }
pkgs/top-level/all-packages.nix+4
@@ -1563,6 +1563,10 @@ in
15631563
15641564 xcodeenv = callPackage ../development/mobile/xcodeenv { };
15651565
1566+ gomobile = callPackage ../development/mobile/gomobile {
1567+ buildGoModule = buildGo115Module;
1568+ };
1569+
15661570 ssh-agents = callPackage ../tools/networking/ssh-agents { };
15671571
15681572 ssh-import-id = python3Packages.callPackage ../tools/admin/ssh-import-id { };