I am a week in trying to build a flutter project using NixOS. I have tried devenv with half a dozen configurations. I have tried oven a dozen flakes. I tried installing flutter through my configuration.nix file. I’ve tried half a dozen ways to bring in this PR:
master ← hacker1024:flutter/gradle-8.9-fix
opened 11:13AM - 01 Jun 25 UTC
Recent versions of Gradle have broken Android builds with our Flutter package.
…
- Gradle 8.9 started reading the project cache directory earlier, so our existing hack of changing it in `build.gradle.kts` stopped working
- Gradle 8.11 fixes [KT-58223](https://youtrack.jetbrains.com/issue/KT-58223), creating a another dedicated directory in the read-only Flutter plugin project root in the process
This PR solves both of these issues by introducing a `flutter_tools` patch to add Gradle command-line arguments that change these problematic paths. These are harmless on older Gradle versions.
The patch is larger than I would have liked, because `flutter_tools` had no existing concept of common arguments that get applied to every Gradle command. Unfortunately, there isn't really a better way to fix this AFAIK.
Also see https://github.com/flutter/flutter/issues/169824.
Resolves #395096.
CC @NixOS/flutter
## Things done
- Built on platform(s)
- [x] x86_64-linux
- [ ] aarch64-linux
- [ ] x86_64-darwin
- [ ] aarch64-darwin
- For non-Linux: Is sandboxing enabled in `nix.conf`? (See [Nix manual](https://nixos.org/manual/nix/stable/command-ref/conf-file.html))
- [ ] `sandbox = relaxed`
- [ ] `sandbox = true`
- [ ] Tested, as applicable:
- [NixOS test(s)](https://nixos.org/manual/nixos/unstable/index.html#sec-nixos-tests) (look inside [nixos/tests](https://github.com/NixOS/nixpkgs/blob/master/nixos/tests))
- and/or [package tests](https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md#package-tests)
- or, for functions and "core" functionality, tests in [lib/tests](https://github.com/NixOS/nixpkgs/blob/master/lib/tests) or [pkgs/test](https://github.com/NixOS/nixpkgs/blob/master/pkgs/test)
- made sure NixOS tests are [linked](https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md#linking-nixos-module-tests-to-a-package) to the relevant packages
- [ ] Tested compilation of all packages that depend on this change using `nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"`. Note: all changes have to be committed, also see [nixpkgs-review usage](https://github.com/Mic92/nixpkgs-review#usage)
- [x] Tested basic functionality of all binary files (usually in `./result/bin/`)
- [Nixpkgs 25.11 Release Notes](https://github.com/NixOS/nixpkgs/blob/master/doc/release-notes/rl-2511.section.md) (or backporting [24.11](https://github.com/NixOS/nixpkgs/blob/master/nixos/doc/release-notes/rl-2411.section.md) and [25.05](https://github.com/NixOS/nixpkgs/blob/master/doc/manual/release-notes/rl-2505.section.md) Nixpkgs Release notes)
- [ ] (Package updates) Added a release notes entry if the change is major or breaking
- [NixOS 25.11 Release Notes](https://github.com/NixOS/nixpkgs/blob/master/nixos/doc/manual/release-notes/rl-2511.section.md) (or backporting [24.11](https://github.com/NixOS/nixpkgs/blob/master/nixos/doc/manual/release-notes/rl-2411.section.md) and [25.05](https://github.com/NixOS/nixpkgs/blob/master/nixos/doc/manual/release-notes/rl-2505.section.md) NixOS Release notes)
- [ ] (Module updates) Added a release notes entry if the change is significant
- [ ] (Module addition) Added a release notes entry if adding a new NixOS module
- [x] Fits [CONTRIBUTING.md](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md).
---
Add a :+1: [reaction] to [pull requests you find important].
[reaction]: https://github.blog/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/
[pull requests you find important]: https://github.com/NixOS/nixpkgs/pulls?q=is%3Aopen+sort%3Areactions-%2B1-desc
If you have reproducible instructions that work, maybe even just a repo with a sample project and associated flake, I would greatly appreciate it. The only next step I can think of at this point is to switch OS and that seems excessive.
1 Like
I really am not sure what the big fuss is about. A bog-standard Java + Android SDK + Flutter installation should work just fine.
{ pkgs ? import (builtins.fetchTarball "https://github.com/hacker1024/nixpkgs/archive/flutter/gradle-8.9-fix.tar.gz") {
config = {
allowUnfree = true;
android_sdk.accept_license = true;
};
}
}:
with pkgs;
let
androidComposition = androidenv.composeAndroidPackages {
buildToolsVersions = [ "34.0.0" ];
platformVersions = [ "35" ];
includeNDK = true;
ndkVersions = [ "26.3.11579264" ];
cmakeVersions = [ "3.22.1" ];
};
in
mkShell {
packages = [
jre
flutter
];
env = rec {
ANDROID_HOME = "${androidComposition.androidsdk}/libexec/android-sdk";
GRADLE_OPTS = "-Dorg.gradle.project.android.aapt2FromMavenOverride=${ANDROID_HOME}/build-tools/${lib.getVersion (builtins.elemAt androidComposition.build-tools 0)}/aapt2";
};
}
Hey, thanks for responding. I’m confused. The use of mkShell makes me think this is intended to be used as a flake? But when I try to use it as such, I get:
error:
… while evaluating the file '/nix/store/j68hhwlkj9xg5vadvdksl9f0cgixrj9d-source/flake.nix':
error: file '/nix/store/j68hhwlkj9xg5vadvdksl9f0cgixrj9d-source/flake.nix' must be an attribute set
limwa
June 12, 2025, 3:02pm
4
Bit of a shameless plug, but I’m building a repository with templates for tools and frameworks that I use often. I’ve created one for flutter here: nix-registry/templates/flutter/flake.nix at e60c03afa75634044286dff678fec3547e8cda65 · limwa/nix-registry · GitHub
You can use this template by copying the files in the flutter folder to your project or by running nix flake init -t github:limwa/nix-registry#flutter. For this command, you might need to use nix --extra-experimental-features "nix-command flakes" flake init -t github:limwa/nix-registry#flutter instead, if you don’t have those experimental features enabled in your Nix config.
Finally, the template is compatible with nix-shell and is tested daily to ensure it still works with the latest nixpkgs version (Flutter Template · Workflow runs · limwa/nix-registry · GitHub ).
Depending on the flutter project you’re working on, you might need to change the versions of the components in the Android SDK in flake.nix, but the versions in the template work out of the box for a newly created Flutter project using flutter create.
Mkshell works in a shell.nix which you can use via nix-shell
You can have a mkshell in flake.nix like devShells.<somename> = mkshell ... which you can use via nix develop
Thanks for self-promoting. That worked for me! Had to fiddle with it for my pre-existing project, but it worked!
1 Like