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 = ''