Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

flutter: move flutter-tools' Gradle build files out of Nix Store #298683

Merged
merged 1 commit into from Mar 25, 2024

Conversation

FlafyDev
Copy link
Contributor

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 and build 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 use build.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>/ and includeBuilds it.
This Gradle project will build the actual packages/flutter_tools/gradle project by setting
rootProject.projectDir = new File("$settingsDir") and apply from: new File("$settingsDir/settings.gradle.kts").

Now the .gradle will be built in $HOME/.cache/flutter/nix-flutter-tools-gradle/<short engine rev>/, but build doesn't.
To move build to $HOME/.cache/flutter/nix-flutter-tools-gradle/<short engine rev>/ as well, we need to set buildDirectory.

fixes: #289936

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • 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
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.05 Release Notes (or backporting 23.05 and 23.11 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (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
  • Fits CONTRIBUTING.md.

Add a 馃憤 reaction to pull requests you find important.

@FlafyDev
Copy link
Contributor Author

FlafyDev commented Mar 24, 2024

Result of nixpkgs-review pr 298683 run on x86_64-linux 1

41 packages built:
  • expidus.calculator
  • expidus.calculator.debug
  • expidus.calculator.pubcache
  • expidus.file-manager
  • expidus.file-manager.debug
  • expidus.file-manager.pubcache
  • firmware-updater
  • firmware-updater.debug
  • firmware-updater.pubcache
  • flet-client-flutter
  • flet-client-flutter.debug
  • flet-client-flutter.pubcache
  • fluffychat
  • fluffychat-web
  • fluffychat-web.pubcache
  • fluffychat.debug
  • fluffychat.pubcache
  • flutter (flutter319 ,flutterPackages.stable ,flutterPackages.v3_19)
  • flutter313 (flutterPackages.v3_13)
  • flutter316 (flutterPackages.v3_16)
  • hover
  • intiface-central
  • intiface-central.debug
  • intiface-central.pubcache
  • localsend
  • localsend.debug
  • localsend.pubcache
  • python311Packages.flet
  • python311Packages.flet-runtime
  • python311Packages.flet-runtime.dist
  • python311Packages.flet.dist
  • python312Packages.flet
  • python312Packages.flet-runtime
  • python312Packages.flet-runtime.dist
  • python312Packages.flet.dist
  • rustdesk-flutter
  • rustdesk-flutter.debug
  • rustdesk-flutter.pubcache
  • yubioath-flutter
  • yubioath-flutter.debug
  • yubioath-flutter.pubcache

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/prs-ready-for-review/3032/3685

@mkg20001 mkg20001 merged commit 10bfb6d into NixOS:master Mar 25, 2024
26 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to build flutter app with flutter 3.19 new Gradle structure
4 participants