Flutter dev with Nix

I’m starting work on an Android project that’s using flutter, with the possibility of extending it to iOS in the near future. I’d love to have a way to lock down the entire development environment for reproducible builds, but I’ve been burned trying to use Nix for such purposes in the past.

What’s the honest state of nix for this use case?

You might be able to use flutter.buildFlutterApplication to build a flutter app.

Personally, I haven’t done full flutter/Android builds using Nix yet. But for development it works pretty well, you can use Nix to compose a devshell that contains all of your Flutter, Android, Java, etc. dependencies for your environment.

You might want to look at the androidenv.composeAndroidPackages function. I also had to set a lot of environment variables to satisfy the flutter tooling.

pkgs.mkShell {
    <other stuff>
    ANDROID_HOME = "${android.androidsdk}/libexec/android-sdk";
    JAVA_HOME = my_jdk;
    ANDROID_JAVA_HOME = my_jdk;
    FLUTTER_SDK = pkgs.flutter;
    ANDROID_AVD_HOME = (toString ./.) + "/.android/avd";
    CHROME_EXECUTABLE = "${pkgs.chromium}/bin/chromium";
    GRADLE_OPTS = "-Dorg.gradle.project.android.aapt2FromMavenOverride=${android.androidsdk}/libexec/android-sdk/build-tools/33.0.2/aapt2";