diff --git a/pkgs/build-support/flutter/default.nix b/pkgs/build-support/flutter/default.nix index dd4341c675dc..ff6c6b31006f 100644 --- a/pkgs/build-support/flutter/default.nix +++ b/pkgs/build-support/flutter/default.nix @@ -14,16 +14,28 @@ # absolutely no mac support for now -{ pubGetScript ? "flutter pub get" +{ pubGetScript ? null , flutterBuildFlags ? [ ] , targetFlutterPlatform ? "linux" , extraWrapProgramArgs ? "" +, flutterMode ? null , ... }@args: let + hasEngine = flutter ? engine && flutter.engine != null && flutter.engine.meta.available; + flutterMode = args.flutterMode or (if hasEngine then flutter.engine.runtimeMode else "release"); + + flutterFlags = lib.optional hasEngine "--local-engine host_${flutterMode}${lib.optionalString (!flutter.engine.isOptimized) "_unopt"}"; + + flutterBuildFlags = [ + "--${flutterMode}" + ] ++ (args.flutterBuildFlags or []) ++ flutterFlags; + builderArgs = rec { universal = args // { + inherit flutterMode flutterFlags flutterBuildFlags; + sdkSetupScript = '' # Pub needs SSL certificates. Dart normally looks in a hardcoded path. # https://github.com/dart-lang/sdk/blob/3.1.0/runtime/bin/security_context_linux.cc#L48 @@ -46,11 +58,11 @@ let ''}/bin/dart" export HOME="$NIX_BUILD_TOP" - flutter config --no-analytics &>/dev/null # mute first-run - flutter config --enable-linux-desktop >/dev/null + flutter config $flutterFlags --no-analytics &>/dev/null # mute first-run + flutter config $flutterFlags --enable-linux-desktop >/dev/null ''; - inherit pubGetScript; + pubGetScript = args.pubGetScript or "flutter${lib.optionalString hasEngine " --local-engine $flutterMode"} pub get"; sdkSourceBuilders = { # https://github.com/dart-lang/pub/blob/68dc2f547d0a264955c1fa551fa0a0e158046494/lib/src/sdk/flutter.dart#L81 @@ -122,7 +134,7 @@ let mkdir -p build/flutter_assets/fonts - flutter build linux -v --release --split-debug-info="$debug" ${builtins.concatStringsSep " " (map (flag: "\"${flag}\"") flutterBuildFlags)} + flutter build linux -v --split-debug-info="$debug" $flutterBuildFlags runHook postBuild ''; @@ -131,7 +143,7 @@ let installPhase = universal.installPhase or '' runHook preInstall - built=build/linux/*/release/bundle + built=build/linux/*/$flutterMode/bundle mkdir -p $out/bin mv $built $out/app @@ -173,7 +185,7 @@ let mkdir -p build/flutter_assets/fonts - flutter build web -v --release ${builtins.concatStringsSep " " (map (flag: "\"${flag}\"") flutterBuildFlags)} + flutter build web -v $flutterBuildFlags runHook postBuild '';