Hello everyone,
I’ve been using a specific flake.nix for my Flutter development for the last 3-4 months without any issues. However, recently after entering the development shell again with nix develop and trying to run my project on an Android emulator using flutter run, I’ve encountered a new error.
It seems that for some reason, Gradle is trying to create a file or directory inside the read-only /nix/store path, which causes the build to fail. Before these recent updates, everything was correctly being written to the project’s own build directory.
For more context, this is the Flutter version my flake is using, which I just updated today:
Flutter 3.35.2 • channel stable • https://github.com/flutter/flutter.git
Framework • revision nixpkgs000 () • 1970-01-01 00:00:00
Engine • revision a8bfdfc394 ()
Tools • Dart 3.9.0 • DevTools 2.48.0
And here is the full error log:
Launching lib/main.dart on sdk gphone64 x86 64 in debug mode...
FAILURE: Build failed with an exception.
* Where:
Settings file '/home/amir/FROMOLDPC/Project/FlutterProject/vsCodeProject/tourino/android/settings.gradle.kts' line: 20
* What went wrong:
Error resolving plugin [id: 'dev.flutter.flutter-plugin-loader', version: '1.0.0']
> A problem occurred configuring project ':gradle'.
> Could not create service of type OutputFilesRepository using ExecutionGradleServices.createOutputFilesRepository().
> Failed to create directory '/nix/store/f4zf4xz1zngg0d12wsfviiqljsrpxajs-flutter-wrapped-3.35.2-sdk-links/packages/flutter_tools/gradle/.gradle/buildOutputCleanup'
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.
BUILD FAILED in 3s
Error: Gradle task assembleDebug failed with exit code 1
Exited (1).
As you can see in the log, the main culprit seems to be this line:
Failed to create directory '/nix/store/f4zf4xz1zngg0d12wsfviiqljsrpxajs-flutter-wrapped-3.35.2-sdk-links/packages/flutter_tools/gradle/.gradle/buildOutputCleanup'
Here is the link to my flake.nix. I’ve included the necessary instructions inside it to test and create a new Flutter project to reproduce the issue:
https://github.com/Amir-Hossein-Azimi/flutter_nix_config
I’m not sure what the root cause is. It seems that with a recent update to the tooling (perhaps Flutter or Gradle), the read-only nature of the NixOS file system was not taken into consideration.
Has anyone else experienced this, or does anyone have a solution in mind? How can I force Gradle to write its files somewhere other than the /nix/store?
Thanks in advance for your time and help.