From c7bfba04eec7bf83b1d253e404f1b30d4908763f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Thu, 18 Mar 2021 12:06:23 +0100 Subject: [PATCH 1/2] maintainers: Add jakubgs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jakub Sokołowski --- maintainers/maintainer-list.nix | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/maintainers/maintainer-list.nix b/maintainers/maintainer-list.nix index 28413f04f8de..3b4dc8625d77 100644 --- a/maintainers/maintainer-list.nix +++ b/maintainers/maintainer-list.nix @@ -4401,6 +4401,12 @@ githubId = 5283991; name = "Jake Waksbaum"; }; + jakubgs = { + email = "jakub@gsokolowski.pl"; + github = "jakubgs"; + githubId = 2212681; + name = "Jakub Grzgorz Sokołowski"; + }; jamiemagee = { email = "jamie.magee@gmail.com"; github = "JamieMagee"; From dd2a8245a15167b271854cff7df040f813d4084d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Thu, 18 Mar 2021 13:51:43 +0100 Subject: [PATCH 2/2] gomobile: init at 2020-06-22 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- pkgs/development/mobile/gomobile/default.nix | 61 +++++++++++++++++++ .../gomobile/resolve-nix-android-sdk.patch | 15 +++++ pkgs/top-level/all-packages.nix | 4 ++ 3 files changed, 80 insertions(+) create mode 100644 pkgs/development/mobile/gomobile/default.nix create mode 100644 pkgs/development/mobile/gomobile/resolve-nix-android-sdk.patch diff --git a/pkgs/development/mobile/gomobile/default.nix b/pkgs/development/mobile/gomobile/default.nix new file mode 100644 index 000000000000..17b4e2fb3f62 --- /dev/null +++ b/pkgs/development/mobile/gomobile/default.nix @@ -0,0 +1,61 @@ +{ stdenv, lib, fetchgit, buildGoModule, zlib, makeWrapper, xcodeenv, androidenv +, xcodeWrapperArgs ? { } +, xcodeWrapper ? xcodeenv.composeXcodeWrapper xcodeWrapperArgs +, androidPkgs ? androidenv.composeAndroidPackages { + includeNDK = true; + ndkVersion = "21.3.6528147"; # WARNING: 22.0.7026061 is broken. + } }: + +buildGoModule { + pname = "gomobile"; + version = "unstable-2020-06-22"; + + vendorSha256 = "1n1338vqkc1n8cy94501n7jn3qbr28q9d9zxnq2b4rxsqjfc9l94"; + + src = fetchgit { + # WARNING: Next commit removes support for ARM 32 bit builds for iOS + rev = "33b80540585f2b31e503da24d6b2a02de3c53ff5"; + name = "gomobile"; + url = "https://go.googlesource.com/mobile"; + sha256 = "0c9map2vrv34wmaycsv71k4day3b0z5p16yzxmlp8amvqb38zwlm"; + }; + + subPackages = [ "bind" "cmd/gobind" "cmd/gomobile" ]; + + # Fails with: go: cannot find GOROOT directory + doCheck = false; + + patches = [ ./resolve-nix-android-sdk.patch ]; + + nativeBuildInputs = [ makeWrapper ] + ++ lib.optionals stdenv.isDarwin [ xcodeWrapper ]; + + # Prevent a non-deterministic temporary directory from polluting the resulting object files + postPatch = '' + substituteInPlace cmd/gomobile/env.go --replace \ + 'tmpdir, err = ioutil.TempDir("", "gomobile-work-")' \ + 'tmpdir = filepath.Join(os.Getenv("NIX_BUILD_TOP"), "gomobile-work")' \ + --replace '"io/ioutil"' "" + substituteInPlace cmd/gomobile/init.go --replace \ + 'tmpdir, err = ioutil.TempDir(gomobilepath, "work-")' \ + 'tmpdir = filepath.Join(os.Getenv("NIX_BUILD_TOP"), "work")' + ''; + + # Necessary for GOPATH when using gomobile. + postInstall = '' + mkdir -p $out/src/golang.org/x + ln -s $src $out/src/golang.org/x/mobile + wrapProgram $out/bin/gomobile \ + --prefix LD_LIBRARY_PATH : "${lib.makeLibraryPath [ zlib ]}" \ + --prefix PATH : "${androidPkgs.androidsdk}/bin" \ + --set ANDROID_HOME "${androidPkgs.androidsdk}/libexec/android-sdk" \ + --set GOPATH $out + ''; + + meta = with lib; { + description = "A tool for building and running mobile apps written in Go"; + homepage = "https://pkg.go.dev/golang.org/x/mobile/cmd/gomobile"; + license = licenses.bsd3; + maintainers = with maintainers; [ jakubgs ]; + }; +} diff --git a/pkgs/development/mobile/gomobile/resolve-nix-android-sdk.patch b/pkgs/development/mobile/gomobile/resolve-nix-android-sdk.patch new file mode 100644 index 000000000000..cc143e3a447c --- /dev/null +++ b/pkgs/development/mobile/gomobile/resolve-nix-android-sdk.patch @@ -0,0 +1,15 @@ +diff --git a/cmd/gomobile/bind_androidapp.go b/cmd/gomobile/bind_androidapp.go +index 3b01adc..76216fa 100644 +--- a/cmd/gomobile/bind_androidapp.go ++++ b/cmd/gomobile/bind_androidapp.go +@@ -372,6 +372,10 @@ func androidAPIPath() (string, error) { + var apiVer int + for _, fi := range fis { + name := fi.Name() ++ // Resolve symlinked directories (this is how the Nix Android SDK package is built) ++ if fi2, err := os.Stat(filepath.Join(sdkDir.Name(), name)); err == nil { ++ fi = fi2 ++ } + if !fi.IsDir() || !strings.HasPrefix(name, "android-") { + continue + } diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index dd92369eaba2..4bc2befee377 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -1563,6 +1563,10 @@ in xcodeenv = callPackage ../development/mobile/xcodeenv { }; + gomobile = callPackage ../development/mobile/gomobile { + buildGoModule = buildGo115Module; + }; + ssh-agents = callPackage ../tools/networking/ssh-agents { }; ssh-import-id = python3Packages.callPackage ../tools/admin/ssh-import-id { };