Skip to content

Commit

Permalink
flutter: Make fetch-artifects.nix independent from the host's platform
Browse files Browse the repository at this point in the history
This is useful for an update script
  • Loading branch information
FlafyDev committed Jan 10, 2024
1 parent 579e013 commit da6757f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
, unzip

, flutterPlatform
, systemPlatform
, flutter
, hash
}:
Expand All @@ -25,9 +26,16 @@ let
# Use a version of Flutter with just enough capabilities to download
# artifacts.
supportedTargetFlutterPlatforms = [ ];

# Modify flutter-tool's system platform in order to get the desired platform's hashes.
flutter = flutter.unwrapped.override {
flutterTools = flutter.unwrapped.tools.override {
inherit systemPlatform;
};
};
};
in
runCommand "flutter-artifacts-${flutterPlatform}"
runCommand "flutter-artifacts-${flutterPlatform}-${systemPlatform}"
{
nativeBuildInputs = [ xorg.lndir flutter' unzip ];

Expand Down
4 changes: 2 additions & 2 deletions pkgs/development/compilers/flutter/flutter-tools.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ hostPlatform
{ systemPlatform
, buildDartApplication
, git
, which
Expand Down Expand Up @@ -35,7 +35,7 @@ buildDartApplication.override { inherit dart; } rec {
'';

dartEntryPoints."flutter_tools.snapshot" = "bin/flutter_tools.dart";
dartCompileFlags = [ "--define=NIX_FLUTTER_HOST_PLATFORM=${hostPlatform.system}" ];
dartCompileFlags = [ "--define=NIX_FLUTTER_HOST_PLATFORM=${systemPlatform}" ];

# The Dart wrapper launchers are useless for the Flutter tool - it is designed
# to be launched from a snapshot by the SDK.
Expand Down
17 changes: 9 additions & 8 deletions pkgs/development/compilers/flutter/flutter.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
, git
, which
, jq
}:

let
tools = callPackage ./flutter-tools.nix {
, flutterTools ? callPackage ./flutter-tools.nix {
inherit dart version;
flutterSrc = src;
inherit patches;
inherit pubspecLock;
};
systemPlatform = stdenv.hostPlatform.system;
}
}:

let
unwrapped =
stdenv.mkDerivation {
name = "flutter-${version}-unwrapped";
Expand Down Expand Up @@ -59,13 +59,13 @@ let
# Add a flutter_tools artifact stamp, and build a snapshot.
# This is the Flutter CLI application.
echo "$(git rev-parse HEAD)" > bin/cache/flutter_tools.stamp
ln -s '${tools}/share/flutter_tools.snapshot' bin/cache/flutter_tools.snapshot
ln -s '${flutterTools}/share/flutter_tools.snapshot' bin/cache/flutter_tools.snapshot
# Some of flutter_tools's dependencies contain static assets. The
# application attempts to read its own package_config.json to find these
# assets at runtime.
mkdir -p packages/flutter_tools/.dart_tool
ln -s '${tools.pubcache}/package_config.json' packages/flutter_tools/.dart_tool/package_config.json
ln -s '${flutterTools.pubcache}/package_config.json' packages/flutter_tools/.dart_tool/package_config.json
echo -n "${version}" > version
cat <<EOF > bin/cache/flutter.version.json
Expand Down Expand Up @@ -119,7 +119,8 @@ let
'';

passthru = {
inherit dart engineVersion tools;
inherit dart engineVersion;
tools = flutterTools;
# 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.
Expand Down
1 change: 1 addition & 0 deletions pkgs/development/compilers/flutter/wrapper.nix
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ let
(callPackage ./artifacts/prepare-artifacts.nix {
src = callPackage ./artifacts/fetch-artifacts.nix {
inherit flutterPlatform;
systemPlatform = stdenv.hostPlatform.system;
flutter = callPackage ./wrapper.nix { inherit flutter; };
hash = artifactHashes.${flutterPlatform}.${stdenv.hostPlatform.system} or "";
};
Expand Down

0 comments on commit da6757f

Please sign in to comment.