From 5f6d29a70aafa0b16a23ae207cc31a4c15b99557 Mon Sep 17 00:00:00 2001 From: hacker1024 Date: Mon, 23 Oct 2023 02:51:25 +1100 Subject: [PATCH] flutter: Use JIT snapshot for flutter_tools --- .../compilers/flutter/flutter-tools.nix | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/pkgs/development/compilers/flutter/flutter-tools.nix b/pkgs/development/compilers/flutter/flutter-tools.nix index 156cbf75588a..23864cd0f245 100644 --- a/pkgs/development/compilers/flutter/flutter-tools.nix +++ b/pkgs/development/compilers/flutter/flutter-tools.nix @@ -1,4 +1,6 @@ { buildDartApplication +, git +, which , dart , version , flutterSrc @@ -11,7 +13,12 @@ buildDartApplication.override { inherit dart; } rec { pname = "flutter-tools"; inherit version; - dartOutputType = "kernel"; + + # The SDK normally uses a JIT snapshot, so we do as well. + # Previously, we used a kernel snapshot - but this was found to cause + # extremely strange behaviour at runtime (observed in `flutter precache`), + # where certain functions would not execute properly. + dartOutputType = "jit-snapshot"; src = flutterSrc; sourceRoot = "source/packages/flutter_tools"; @@ -24,6 +31,17 @@ buildDartApplication.override { inherit dart; } rec { dartEntryPoints."flutter_tools.snapshot" = "bin/flutter_tools.dart"; + # When the JIT snapshot is being built, the application needs to run. + # It attempts to generate configuration files, and relies on a few external + # tools. + nativeBuildInputs = [ git which ]; + preConfigure = '' + export HOME=. + export FLUTTER_ROOT="$NIX_BUILD_TOP/source" + mkdir -p "$FLUTTER_ROOT/bin/cache" + ln -s '${dart}' "$FLUTTER_ROOT/bin/cache/dart-sdk" + ''; + # The Dart wrapper launchers are useless for the Flutter tool - it is designed # to be launched from a snapshot by the SDK. postInstall = ''