Using Nix for a multi-stage build with multiple languages involved

I have a project that I’m working on. It’s going to be multi-platform very soon.

The gist of the setup is… a Rust library that does all of the logic and networking and whatnot. Then a Rust+GTK UI (already started) and an Android UI (I have an android project, but it doesn’t talk to anything). The Android UI will need to talk to the Rust library via an FFI.

To make things a tiny bit easier, I’m going to snag Typeshare, which will run along with the Core compile in order to generate type definitions for Android from the Rust type definitions. That would just become a source file for the AndroidFFI, but it’s also a build step that needs doing.

In fact, the project would look like this:


I would be extremely, unbelievably happy if I could orchestrate the entire build with Nix. I would love to get a Nix artifact from the Core library, which then gets included in the Rust+GTK app and also gets included into my Kotlin FFI crate. I want to have the Kotlin FFI get cached as a Nix artifact and included in my Android application.

But, I see many, many problems with this and I would love advice on how to solve them:

  • Most developers don’t seem to even try doing incremental builds with Rust. Carnix is years unsupported, and I’m not clear on the current state of Cargo2nix. Crane treats all dependencies as a single blob… which isn’t awful but isn’t my preference, either.
  • While I have used Android-Studio to create a trivial Android app, I’m terrified of the hell I’m going to be in when I need to compile an FFI and then link to that FFI as well. The current Nixpkgs documentation for setting up an an android development environment is completely wrong, in that I’ve never actually gotten an environment in which gradle works. Sometimes it’s not even installed when I follow the instructions.

So… do you have

  • Any opinion on the status of partial building of Rust crates?
  • Any pointers on how to create an Android environment that I can include in a flake with a variety of additional tools?
  • Any pointers to documentation on setting up an Android FFI library?
  • Any pointers on building an Android FFI app which depends on a library?

I’m looking to build a nix flake that gives me a devShell with all of the tools, and for which I can define a kifu-android target and a kifu-gtk target.