@@ -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+}