···1+diff --git a/packages/flutter_tools/lib/src/runner/flutter_command.dart b/packages/flutter_tools/lib/src/runner/flutter_command.dart
2+index e4e474ab6e..5548599802 100644
3+--- a/packages/flutter_tools/lib/src/runner/flutter_command.dart
4++++ b/packages/flutter_tools/lib/src/runner/flutter_command.dart
5+@@ -1693,7 +1693,7 @@ Run 'flutter -h' (or 'flutter <command> -h') for available flutter commands and
6+7+ // Populate the cache. We call this before pub get below so that the
8+ // sky_engine package is available in the flutter cache for pub to find.
9+- if (shouldUpdateCache) {
10++ if (false) {
11+ // First always update universal artifacts, as some of these (e.g.
12+ // ios-deploy on macOS) are required to determine `requiredArtifacts`.
13+ final bool offline;
14+diff --git a/packages/flutter_tools/lib/src/runner/flutter_command_runner.dart b/packages/flutter_tools/lib/src/runner/flutter_command_runner.dart
15+index a1104da..1749d65 100644
16+--- a/packages/flutter_tools/lib/src/runner/flutter_command_runner.dart
17++++ b/packages/flutter_tools/lib/src/runner/flutter_command_runner.dart
18+@@ -444,12 +444,8 @@ class FlutterCommandRunner extends CommandRunner<void> {
19+ globals.analytics.suppressTelemetry();
20+ }
21+22+- globals.flutterVersion.ensureVersionFile();
23+ final bool machineFlag =
24+ topLevelResults[FlutterGlobalOptions.kMachineFlag] as bool? ?? false;
25+- if (await _shouldCheckForUpdates(topLevelResults, topLevelMachineFlag: machineFlag)) {
26+- await globals.flutterVersion.checkFlutterVersionFreshness();
27+- }
28+29+ // See if the user specified a specific device.
30+ final String? specifiedDeviceId =
···1+From 6df275df3b8694daf16302b407520e3b1dee6724 Mon Sep 17 00:00:00 2001
2+From: Philip Hayes <philiphayes9@gmail.com>
3+Date: Thu, 12 Sep 2024 13:23:00 -0700
4+Subject: [PATCH] fix: cleanup xcode_backend.sh to fix iOS build w/
5+ `NixOS/nixpkgs` flutter
6+7+This patch cleans up `xcode_backend.sh`. It now effectively just runs
8+`exec $FLUTTER_ROOT/bin/dart ./xcode_backend.dart`.
9+10+The previous `xcode_backend.sh` tries to discover `$FLUTTER_ROOT` from
11+argv[0], even though its presence is already guaranteed (the wrapped
12+`xcode_backend.dart` also relies on this env).
13+14+When using nixpkgs flutter, the flutter SDK directory is composed of several
15+layers, joined together using symlinks (called a `symlinkJoin`). Without this
16+patch, the auto-discover traverses the symlinks into the wrong layer, and so it
17+uses an "unwrapped" `dart` command instead of a "wrapped" dart that sets some
18+important envs/flags (like `$FLUTTER_ROOT`).
19+20+Using the "unwrapped" dart then manifests in this error when compiling, since
21+it doesn't see the ios build-support artifacts:
22+23+```
24+$ flutter run -d iphone
25+Running Xcode build...
26+Xcode build done. 6.4s
27+Failed to build iOS app
28+Error (Xcode): Target debug_unpack_ios failed: Error: Flutter failed to create a directory at "/<nix-store>/XXXX-flutter-3.24.1-unwrapped/bin/cache/artifacts".
29+```
30+---
31+ packages/flutter_tools/bin/xcode_backend.sh | 25 ++++-----------------
32+ 1 file changed, 4 insertions(+), 21 deletions(-)
33+34+diff --git a/packages/flutter_tools/bin/xcode_backend.sh b/packages/flutter_tools/bin/xcode_backend.sh
35+index 2889d7c8e4..48b9d06c6e 100755
36+--- a/packages/flutter_tools/bin/xcode_backend.sh
37++++ b/packages/flutter_tools/bin/xcode_backend.sh
38+@@ -6,24 +6,7 @@
39+ # exit on error, or usage of unset var
40+ set -euo pipefail
41+42+-# Needed because if it is set, cd may print the path it changed to.
43+-unset CDPATH
44+-
45+-function follow_links() (
46+- cd -P "$(dirname -- "$1")"
47+- file="$PWD/$(basename -- "$1")"
48+- while [[ -h "$file" ]]; do
49+- cd -P "$(dirname -- "$file")"
50+- file="$(readlink -- "$file")"
51+- cd -P "$(dirname -- "$file")"
52+- file="$PWD/$(basename -- "$file")"
53+- done
54+- echo "$file"
55+-)
56+-
57+-PROG_NAME="$(follow_links "${BASH_SOURCE[0]}")"
58+-BIN_DIR="$(cd "${PROG_NAME%/*}" ; pwd -P)"
59+-FLUTTER_ROOT="$BIN_DIR/../../.."
60+-DART="$FLUTTER_ROOT/bin/dart"
61+-
62+-"$DART" "$BIN_DIR/xcode_backend.dart" "$@"
63++# Run `dart ./xcode_backend.dart` with the dart from $FLUTTER_ROOT.
64++dart="${FLUTTER_ROOT}/bin/dart"
65++xcode_backend_dart="${BASH_SOURCE[0]%.sh}.dart"
66++exec "${dart}" "${xcode_backend_dart}" "$@"
67+--
68+2.46.0
69+
···1+This patch introduces an intermediate Gradle build step to alter the behavior
2+of flutter_tools' Gradle project, specifically moving the creation of `build`
3+and `.gradle` directories from within the Nix Store to somewhere in `$HOME/.cache/flutter/nix-flutter-tools-gradle/$engineShortRev`.
4+5+Without this patch, flutter_tools' Gradle project tries to generate `build` and `.gradle`
6+directories within the Nix Store. Resulting in read-only errors when trying to build a
7+Flutter Android app at runtime.
8+9+This patch takes advantage of the fact settings.gradle takes priority over settings.gradle.kts to build the intermediate Gradle project
10+when a Flutter app runs `includeBuild("${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle")`
11+12+`rootProject.buildFileName = "/dev/null"` so that the intermediate project doesn't use `build.gradle.kts` that's in the same directory.
13+14+The intermediate project makes a `settings.gradle` file in `$HOME/.cache/flutter/nix-flutter-tools-gradle/<short engine rev>/` and `includeBuild`s it.
15+This Gradle project will build the actual `packages/flutter_tools/gradle` project by setting
16+`rootProject.projectDir = new File("$settingsDir")` and `apply from: new File("$settingsDir/settings.gradle.kts")`.
17+18+Now the `.gradle` will be built in `$HOME/.cache/flutter/nix-flutter-tools-gradle/<short engine rev>/`, but `build` doesn't.
19+To move `build` to `$HOME/.cache/flutter/nix-flutter-tools-gradle/<short engine rev>/` as well, we need to set `buildDirectory`.
20+diff --git a/packages/flutter_tools/gradle/settings.gradle b/packages/flutter_tools/gradle/settings.gradle
21+new file mode 100644
22+index 0000000000..b2485c94b4
23+--- /dev/null
24++++ b/packages/flutter_tools/gradle/settings.gradle
25+@@ -0,0 +1,19 @@
26++rootProject.buildFileName = "/dev/null"
27++
28++def engineShortRev = (new File("$settingsDir/../../../bin/internal/engine.version")).text.take(10)
29++def dir = new File("$System.env.HOME/.cache/flutter/nix-flutter-tools-gradle/$engineShortRev")
30++dir.mkdirs()
31++def file = new File(dir, "settings.gradle")
32++
33++file.text = """
34++rootProject.projectDir = new File("$settingsDir")
35++apply from: new File("$settingsDir/settings.gradle.kts")
36++
37++gradle.allprojects { project ->
38++ project.beforeEvaluate {
39++ project.layout.buildDirectory = new File("$dir/build")
40++ }
41++}
42++"""
43++
44++includeBuild(dir)