flutter: move flutter-tools' Gradle build files out of Nix Store #298683
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of changes
When building a Flutter Android app Gradle runs the following
includeBuild("${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle")
This line builds the gradle project located at that location. On NixOS this fails because the location is read-only and located at the Nix Store. More specifically, it fails when creating
.gradle
andbuild
at${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle
.To fix this we also need to consider the limitation that we can't change this line, since every Flutter app has this line. For example https://github.com/ReVanced/revanced-manager/blob/c209c32613700281b784b656766b6c04ca5b8c69/android/settings.gradle#L11.
This patch introduces an intermediate Gradle build step to alter the behavior of flutter_tools' Gradle project, specifically moving the creation of
build
and.gradle
directories to in$HOME/.cache/flutter/nix-flutter-tools-gradle/$engineShortRev
.This patch takes advantage of the fact settings.gradle takes priority over settings.gradle.kts to build the intermediate Gradle project when a Flutter app runs
includeBuild("${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle")
rootProject.buildFileName = "/dev/null"
so that the intermediate project doesn't usebuild.gradle.kts
that's in the same directory.The intermediate project makes a
settings.gradle
file in$HOME/.cache/flutter/nix-flutter-tools-gradle/<short engine rev>/
andincludeBuild
s it.This Gradle project will build the actual
packages/flutter_tools/gradle
project by settingrootProject.projectDir = new File("$settingsDir")
andapply from: new File("$settingsDir/settings.gradle.kts")
.Now the
.gradle
will be built in$HOME/.cache/flutter/nix-flutter-tools-gradle/<short engine rev>/
, butbuild
doesn't.To move
build
to$HOME/.cache/flutter/nix-flutter-tools-gradle/<short engine rev>/
as well, we need to setbuildDirectory
.fixes: #289936
Things done
nix.conf
? (See Nix manual)sandbox = relaxed
sandbox = true
nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)Add a 馃憤 reaction to pull requests you find important.