about summary refs log tree commit diff
path: root/pkgs/development/compilers/flutter/flutter.nix
diff options
context:
space:
mode:
authorhacker1024 <hacker1024@users.sourceforge.net>2023-10-22 17:21:36 +1100
committerMaciej Krüger <mkg20001@gmail.com>2023-12-21 11:44:07 +0100
commitee289896a7cd0ea4d8a34f3cc5ca282a98ec3e54 (patch)
treed028ad271a8f507f7c6f3fb87056a73be60ad49a /pkgs/development/compilers/flutter/flutter.nix
parente1b7b95b82e3e9add7782537a0708b3669363f11 (diff)
flutter: Build flutter_tools with buildDartApplication
Diffstat (limited to 'pkgs/development/compilers/flutter/flutter.nix')
-rw-r--r--pkgs/development/compilers/flutter/flutter.nix48
1 files changed, 13 insertions, 35 deletions
diff --git a/pkgs/development/compilers/flutter/flutter.nix b/pkgs/development/compilers/flutter/flutter.nix
index da45fee420d00..3cc230b7b205c 100644
--- a/pkgs/development/compilers/flutter/flutter.nix
+++ b/pkgs/development/compilers/flutter/flutter.nix
@@ -3,21 +3,29 @@
 , patches
 , dart
 , src
+, pubspecLockFile
+, vendorHash
+, depsListFile
 , lib
 , stdenv
+, callPackage
 , darwin
 , git
 , which
 }:
 
 let
+  tools = callPackage ./flutter-tools.nix {
+    inherit dart version;
+    flutterSrc = src;
+    inherit pubspecLockFile vendorHash depsListFile;
+  };
+
   unwrapped =
     stdenv.mkDerivation {
       name = "flutter-${version}-unwrapped";
       inherit src patches version;
 
-      outputs = [ "out" "cache" ];
-
       buildInputs = [ git ];
       nativeBuildInputs = [ ]
         ++ lib.optionals stdenv.hostPlatform.isDarwin [ darwin.DarwinTools ];
@@ -35,45 +43,15 @@ let
 
       buildPhase = ''
         export FLUTTER_ROOT="$(pwd)"
-        export FLUTTER_TOOLS_DIR="$FLUTTER_ROOT/packages/flutter_tools"
-        export SCRIPT_PATH="$FLUTTER_TOOLS_DIR/bin/flutter_tools.dart"
 
+        mkdir -p "$FLUTTER_ROOT/bin/cache"
         export SNAPSHOT_PATH="$FLUTTER_ROOT/bin/cache/flutter_tools.snapshot"
         export STAMP_PATH="$FLUTTER_ROOT/bin/cache/flutter_tools.stamp"
 
-        export DART_SDK_PATH="${dart}"
-
-        # The Flutter tool compilation requires dependencies to be cached, as there is no Internet access.
-        # Dart expects package caches to be mutable, and does not support composing cache directories.
-        # The packages cached during the build therefore cannot be easily used. They are provided through
-        # the derivation's "cache" output, though, in case they are needed.
-        #
-        # Note that non-cached packages will normally be fetched from the Internet when they are needed, so Flutter
-        # will function without an existing package cache as long as it has an Internet connection.
-        export PUB_CACHE="$cache"
-
-        if [ -d .pub-preload-cache ]; then
-          ${dart}/bin/dart pub cache preload .pub-preload-cache/*
-        elif [ -d .pub-cache ]; then
-          mv .pub-cache "$PUB_CACHE"
-        else
-          echo 'ERROR: Failed to locate the Dart package cache required to build the Flutter tool.'
-          exit 1
-        fi
-
-        pushd "$FLUTTER_TOOLS_DIR"
-        ${dart}/bin/dart pub get --offline
-        popd
-
         local revision="$(cd "$FLUTTER_ROOT"; git rev-parse HEAD)"
-        ${dart}/bin/dart --snapshot="$SNAPSHOT_PATH" --packages="$FLUTTER_TOOLS_DIR/.dart_tool/package_config.json" "$SCRIPT_PATH"
         echo "$revision" > "$STAMP_PATH"
+        ln -s '${tools}/share/flutter_tools.snapshot' "$SNAPSHOT_PATH"
         echo -n "${version}" > version
-
-        # Certain prebuilts should be replaced with Nix-built (or at least Nix-patched) equivalents.
-        rm -r \
-          $FLUTTER_ROOT/bin/cache/dart-sdk \
-          $FLUTTER_ROOT/bin/cache/artifacts/engine
       '';
 
       installPhase = ''
@@ -101,7 +79,7 @@ let
       '';
 
       passthru = {
-        inherit dart engineVersion;
+        inherit dart engineVersion tools;
         # The derivation containing the original Flutter SDK files.
         # When other derivations wrap this one, any unmodified files
         # found here should be included as-is, for tooling compatibility.