flutter: Fetch artifacts with flutter prefetch

This commit is contained in:
hacker1024 2023-10-23 05:00:11 +11:00 committed by Maciej Krüger
parent de1d8091da
commit 44030b7f7d
No known key found for this signature in database
GPG key ID: 0D948CE19CF49C5F
9 changed files with 152 additions and 448 deletions

View file

@ -0,0 +1,43 @@
{ lib
, runCommand
, cacert
, unzip
, platform
, flutter
, hash
}:
let
platforms = [
"android"
"ios"
"web"
"linux"
"windows"
"macos"
"fuchsia"
"universal"
];
in
runCommand "flutter-artifacts-${platform}"
{
nativeBuildInputs = [ flutter unzip ];
NIX_FLUTTER_TOOLS_VM_OPTIONS = "--root-certs-file=${cacert}/etc/ssl/certs/ca-bundle.crt";
outputHash = hash;
outputHashMode = "recursive";
outputHashAlgo = "sha256";
passthru = {
inherit platform;
};
} ''
runHook preBuild
mkdir -p "$out"
HOME="$NIX_BUILD_TOP" FLUTTER_CACHE_DIR="$out" flutter precache -v '--${platform}' ${builtins.concatStringsSep " " (map (p: "'--no-${p}'") (lib.remove platform platforms))}
runHook postBuild
''

View file

@ -0,0 +1,38 @@
# NOTICE: When updating these hashes, make sure that no additional platforms
# have been added to the `flutter precache` CLI. If any have, they may be
# included in every derivation, unless they are also added to the platform list
# in fetch-artifacts.nix.
#
# The known arguments are as follows:
# $ flutter precache --help --verbose
# Usage: flutter precache [arguments]
# -h, --help Print this usage information.
# -a, --all-platforms Precache artifacts for all host platforms.
# -f, --force Force re-downloading of artifacts.
# --[no-]android Precache artifacts for Android development.
# --[no-]android_gen_snapshot Precache gen_snapshot for Android development.
# --[no-]android_maven Precache Gradle dependencies for Android development.
# --[no-]android_internal_build Precache dependencies for internal Android development.
# --[no-]ios Precache artifacts for iOS development.
# --[no-]web Precache artifacts for web development.
# --[no-]linux Precache artifacts for Linux desktop development.
# --[no-]windows Precache artifacts for Windows desktop development.
# --[no-]macos Precache artifacts for macOS desktop development.
# --[no-]fuchsia Precache artifacts for Fuchsia development.
# --[no-]universal Precache artifacts required for any development platform.
# (defaults to on)
# --[no-]flutter_runner Precache the flutter runner artifacts.
# --[no-]use-unsigned-mac-binaries Precache the unsigned macOS binaries when available.
{
"3.13.8" = {
android = "sha256-Uc36aBq8wQo2aEvjAPOoixZElWOE/GNRm2GUfhbwT3Y=";
fuchsia = "sha256-eu0BERdz53CkSexbpu3KA7O6Q4g0s9SGD3t1Snsk3Fk=";
ios = "sha256-QwkeGnutTVsm682CqxRtEd9rKUvN7zlAJcqkvAQYwao=";
linux = "sha256-0gIOwux3YBdmcXgwICr8dpftj1CauaBUX8Rt5GG0WSs=";
macos = "sha256-9WqCJQ37mcGc5tzfqQoY5CqHWHGTizjXf9p73bdnNWc=";
universal = "sha256-wATt1UPjo/fh7RFO1vvcUAdo0dMAaaOUIuzYodsM0v0=";
web = "sha256-DVXJOOFxv7tKt3d0NaYMexkphEcr7+gDFV67I6iAYa0=";
windows = "sha256-s8fJtwQkuZaGXr6vrPiKfpwP/NfewbETwyp9ERGqHYI=";
};
}

View file

@ -0,0 +1,10 @@
{ gtk3
}:
{ buildInputs ? [ ]
, ...
}:
{
buildInputs = buildInputs ++ [ gtk3 ];
}

View file

@ -0,0 +1,21 @@
{ stdenv
, lib
, autoPatchelfHook
, src
}:
stdenv.mkDerivation {
inherit (src) name;
inherit src;
nativeBuildInputs = lib.optional stdenv.hostPlatform.isLinux autoPatchelfHook;
installPhase = ''
runHook preInstall
mkdir -p "$out/bin"
cp -r . "$out/bin/cache"
runHook postInstall
'';
}

View file

@ -55,13 +55,7 @@ let
buildFlutterApplication = callPackage ../../../build-support/flutter { buildFlutterApplication = callPackage ../../../build-support/flutter {
# Package a minimal version of Flutter that only uses Linux desktop release artifacts. # Package a minimal version of Flutter that only uses Linux desktop release artifacts.
flutter = (wrapFlutter (mkCustomFlutter args)).override { flutter = (wrapFlutter (mkCustomFlutter args)).override {
supportsAndroid = false; supportedTargetPlatforms = [ "universal" "linux" ];
includedEngineArtifacts = {
common = [ "flutter_patched_sdk_product" ];
platform.linux = lib.optionals stdenv.hostPlatform.isLinux
(lib.genAttrs ((lib.optional stdenv.hostPlatform.isx86_64 "x64") ++ (lib.optional stdenv.hostPlatform.isAarch64 "arm64"))
(architecture: [ "release" ]));
};
}; };
}; };
}; };

View file

@ -1,243 +0,0 @@
{ lib
, stdenv
, hostPlatform
, engineVersion
, fetchurl
, fetchzip
, autoPatchelfHook
, gtk3
, flutterVersion
, unzip
, stdenvNoCC
}:
let
hashes = (import ./hashes.nix).${engineVersion} or
(throw "There are no known artifact hashes for Flutter engine version ${engineVersion}.");
noticeText = stdenvNoCC.mkDerivation (finalAttrs: {
pname = "flutter-notice";
version = engineVersion;
dontUnpack = true;
src = fetchurl {
pname = "flutter-sky_engine-LICENSE";
version = engineVersion;
url = "https://raw.githubusercontent.com/flutter/engine/${engineVersion}/sky/packages/sky_engine/LICENSE";
sha256 = hashes.skyNotice;
};
flutterNotice = fetchurl {
pname = "flutter-LICENSE";
version = engineVersion;
url = "https://raw.githubusercontent.com/flutter/flutter/${flutterVersion}/LICENSE";
sha256 = hashes.flutterNotice;
};
installPhase =
''
SRC_TEXT="$(cat $src)"
FLUTTER_NOTICE_TEXT="$(cat $flutterNotice)"
cat << EOF > $out
This artifact is from the Flutter SDK's engine.
This file carries third-party notices for its dependencies.
See also other files, that have LICENSE in the name, in the artifact directory.
Appendix 1/2: merged sky_engine LICENSE file (also found at ${finalAttrs.src.url})
$SRC_TEXT
Appendix 2/2: Flutter license (also found at ${finalAttrs.flutterNotice.url})
$FLUTTER_NOTICE_TEXT
EOF
'';
});
artifacts =
{
common = {
flutter_patched_sdk = { archive = "flutter_patched_sdk.zip"; };
flutter_patched_sdk_product = { archive = "flutter_patched_sdk_product.zip"; };
};
platform = {
android =
(lib.genAttrs
[ "arm" "arm64" "x64" ]
(arch:
{
base = [
{ archive = "artifacts.zip"; }
];
variants = lib.genAttrs [ "profile" "release" ]
(variant: [
{ archive = "artifacts.zip"; }
{ subdirectory = true; archive = "${lib.toLower hostPlatform.uname.system}-x64.zip"; }
]);
})) //
{
"x86" = {
base = [
{ archive = "artifacts.zip"; }
];
variants.jit-release = [
{ archive = "artifacts.zip"; }
];
};
};
darwin = {
"arm64" = {
base = [
{ archive = "artifacts.zip"; }
{ archive = "font-subset.zip"; }
];
variants = lib.genAttrs [ "profile" "release" ]
(variant: [
{ archive = "artifacts.zip"; }
]);
};
"x64" = {
base = [
{ archive = "FlutterEmbedder.framework.zip"; }
{ archive = "FlutterMacOS.framework.zip"; }
{ archive = "artifacts.zip"; }
{ archive = "font-subset.zip"; }
{ archive = "gen_snapshot.zip"; }
];
variants.profile = [
{ archive = "FlutterMacOS.framework.zip"; }
{ archive = "artifacts.zip"; }
{ archive = "gen_snapshot.zip"; }
];
variants.release = [
{ archive = "FlutterMacOS.dSYM.zip"; }
{ archive = "FlutterMacOS.framework.zip"; }
{ archive = "artifacts.zip"; }
{ archive = "gen_snapshot.zip"; }
];
};
};
ios =
(lib.genAttrs
[ "" ]
(arch:
{
base = [
{ archive = "artifacts.zip"; }
];
variants.profile = [
{ archive = "artifacts.zip"; }
];
variants.release = [
{ archive = "artifacts.zip"; }
{ archive = "Flutter.dSYM.zip"; }
];
}));
linux = lib.genAttrs
[ "arm64" "x64" ]
(arch:
let
linux-flutter-gtk = {
archive = "linux-${arch}-flutter-gtk.zip";
buildInputs = [ gtk3 ];
};
in
{
base = [
({ archive = "artifacts.zip"; } // lib.optionalAttrs (arch == "arm64") {
# For some reason, the arm64 artifacts are missing shader code in Flutter < 3.10.0.
postPatch = ''
if [ ! -d shader_lib ]; then
ln -s ${lib.findSingle
(pkg: lib.getName pkg == "flutter-artifact-linux-x64-artifacts")
(throw "Could not find the x64 artifact archive.")
(throw "Could not find the correct x64 artifact archive.")
artifactDerivations.platform.linux.x64.base
}/shader_lib .
fi
'';
})
{ archive = "font-subset.zip"; }
(linux-flutter-gtk // {
# https://github.com/flutter/flutter/commit/9d94a51b607600a39c14470c35c676eb3e30eed6
variant = "debug";
})
];
variants = lib.genAttrs [ "debug" "profile" "release" ] (variant: [
linux-flutter-gtk
]);
});
};
};
mkArtifactDerivation = { platform ? null, variant ? null, subdirectory ? null, archive, ... }@args:
let
artifactDirectory = if platform == null then null else "${platform}${lib.optionalString (variant != null) "-${variant}"}";
archiveBasename = lib.removeSuffix ".${(lib.last (lib.splitString "." archive))}" archive;
overrideUnpackCmd = builtins.elem archive [ "FlutterEmbedder.framework.zip" "FlutterMacOS.framework.zip" ];
in
stdenv.mkDerivation ({
pname = "flutter-artifact${lib.optionalString (platform != null) "-${artifactDirectory}"}-${archiveBasename}";
version = engineVersion;
nativeBuildInputs = [ unzip ]
++ lib.optionals stdenv.hostPlatform.isLinux [ autoPatchelfHook ];
src =
if overrideUnpackCmd then
(fetchurl {
url = "https://storage.googleapis.com/flutter_infra_release/flutter/${engineVersion}${lib.optionalString (platform != null) "/${artifactDirectory}"}/${archive}";
hash = (if artifactDirectory == null then hashes else hashes.${artifactDirectory}).${archive};
}) else
(fetchzip {
url = "https://storage.googleapis.com/flutter_infra_release/flutter/${engineVersion}${lib.optionalString (platform != null) "/${artifactDirectory}"}/${archive}";
stripRoot = false;
hash = (if artifactDirectory == null then hashes else hashes.${artifactDirectory}).${archive};
});
sourceRoot = if overrideUnpackCmd then "." else null;
unpackCmd = if overrideUnpackCmd then "unzip -o $src -d $out" else null;
installPhase =
let
destination = "$out/${if subdirectory == true then archiveBasename else if subdirectory != null then subdirectory else "."}";
in
''
# ship the notice near all artifacts. if the artifact directory is / multiple directories are nested in $src, link it there. If there isn't a directory, link it in root
# this *isn't the same as the subdirectory variable above*
DIR_CNT="$(echo */ | wc -w)"
if [[ "$DIR_CNT" == 0 ]]; then
ln -s ${noticeText} LICENSE.README
else
for dir in */
do
ln -s ${noticeText} "$dir/LICENSE.README"
done
fi
mkdir -p "${destination}"
cp -r . "${destination}"
'';
} // args);
artifactDerivations = {
common = builtins.mapAttrs (name: mkArtifactDerivation) artifacts.common;
platform =
builtins.mapAttrs
(os: architectures:
builtins.mapAttrs
(architecture: variants: {
base = map
(args: mkArtifactDerivation ({
platform = "${os}${lib.optionalString (architecture != "") "-${architecture}"}";
} // args))
variants.base;
variants = builtins.mapAttrs
(variant: variantArtifacts: map
(args: mkArtifactDerivation ({
platform = "${os}${lib.optionalString (architecture != "") "-${architecture}"}";
inherit variant;
} // args))
variantArtifacts)
variants.variants;
})
architectures)
artifacts.platform;
};
in
artifactDerivations

View file

@ -1,118 +0,0 @@
{
"767d8c75e898091b925519803830fc2721658d07" = {
skyNotice = "sha256-bJMktK26wC9fVzdhLNcTHqOg5sHRZ535LB5u5dgwjlY=";
flutterNotice = "sha256-pZjblLYpD/vhC17PkRBXtqlDNRxyf92p5fKJHWhwCiA=";
android-arm = {
"artifacts.zip" = "sha256-pnUDY2sUN2r/LrivyNkfTUpQC90GKOI6Ya+0lgIz+c0=";
};
android-arm-profile = {
"artifacts.zip" = "sha256-/kDNI+no4u2Ri/FqqsQEp2iEqifULYGqzz8w0G4pzCM=";
"linux-x64.zip" = "sha256-fUfaDJIo1VcdJHcd0jO98Az3OdNQ+JtA5Mp6nQVVU4E=";
"darwin-x64.zip" = "sha256-J7vDD5VEsgnWmbI8acM3vQwrnrqcfMaCijiItDfniLY=";
};
android-arm-release = {
"artifacts.zip" = "sha256-tVAFHHG8A8vlgQu6l6ybdfm6OmBf2vrYf3PZByWvs08=";
"linux-x64.zip" = "sha256-lrejG7zpUBox9kPvs1uPM/lyR1d/SAc1w+c6kcqghHI=";
"darwin-x64.zip" = "sha256-8lKOsqLgbnuoCR87v84dn8V3PRzl1+maWFIHopiGvbc=";
};
android-arm64 = {
"artifacts.zip" = "sha256-rcU2mX0nP1ot+6DU+uxvILUOAuwTPGH23UQ6riBs0d4=";
};
android-arm64-profile = {
"artifacts.zip" = "sha256-x4TEJWi3c6mEPGh+3l4PtRqsg4Tq7mxHtGz+4MqwzPw=";
"linux-x64.zip" = "sha256-PsDKOq3DXaNeNtaFtDQJ9JIEESXBHm8XHHpOw2u1cGg=";
"darwin-x64.zip" = "sha256-K4W1CEBOlZVsHjuhvKCUZWv45VSohRd23vviaLqMNjQ=";
};
android-arm64-release = {
"artifacts.zip" = "sha256-w+J4sNhYoj44IiHpZ0BkemCYlE9wOTvWL57Y8RCstkI=";
"linux-x64.zip" = "sha256-MJsmck27V14/f0IAT6b/R47p8/eCMX9Nn//PEAbEeOY=";
"darwin-x64.zip" = "sha256-xXa5GFatJPiwBANqeWUpAdM9gibD4xH85aI6YpJrcpI=";
};
android-x64 = {
"artifacts.zip" = "sha256-doNUwEJkwncHPIf2c8xOZByUU8dmogtWlc6q7n7ElDY=";
};
android-x64-profile = {
"artifacts.zip" = "sha256-N3AjdHdzj4s6v3f3Gf6n/1Xk0W7xFQP70SneCNlj2sk=";
"linux-x64.zip" = "sha256-pNn75iZqLwOGO3ZmymmrSasDPMmDWwp9ZWBv9Xti4cU=";
"darwin-x64.zip" = "sha256-6O4lA/4wZ91ODUUYHe4HpjvraAEbhHiehBmf3sT37Dc=";
};
android-x64-release = {
"artifacts.zip" = "sha256-odDS/m8fgSA24EYt+W2sEDmOlPO17FZxxomWuYUHmns=";
"linux-x64.zip" = "sha256-sVQYmu0KaPADlL59XZc26Ks+TbmaJxRGPiJKlWxUhRA=";
"darwin-x64.zip" = "sha256-dep/CmBIDkvqYKQPWMCDTDbFhVvOk6N7JAF8v3dr/P8=";
};
android-x86 = {
"artifacts.zip" = "sha256-MzTFQ0XPtd9OXvKfM98bwpxN/xfEcXox24gn/4aS/Do=";
};
android-x86-jit-release = {
"artifacts.zip" = "sha256-cUsBqJxOOluwnYEFzdtZof8c4Vp1D81HkEEH8aRGLyY=";
};
darwin-arm64 = {
"artifacts.zip" = "sha256-df+rmN0RqLM7MgEKjTcybMY0bFYCB1jsTvaVE1J0BzY=";
"font-subset.zip" = "sha256-hJ5fECxN4oZX6E9ivzSDGejNSj56t2SKccbyfozXxps=";
};
darwin-arm64-profile = {
"artifacts.zip" = "sha256-EaXOr998zE4cG5G5FRtsDGt3jjg1GjkRGE/ZDD3Coto=";
};
darwin-arm64-release = {
"artifacts.zip" = "sha256-1XMoM8jDRoUSPMauKD5lsgC25B7Htod8wYouDKSEGJY=";
};
darwin-x64 = {
"FlutterEmbedder.framework.zip" = "sha256-vzvt0pwo1HbIxxym/jn2Y+1+Iqm/Gw2TfymEcuUHIXQ=";
"FlutterMacOS.framework.zip" = "sha256-cMTCULaVOKDq8VrqCmZLo0IPBve0GSh0K2yvtdCvX8c=";
"artifacts.zip" = "sha256-8BViZUz4b0XurQJM+FCU2toONKmhajabCc66gBUVGgY=";
"font-subset.zip" = "sha256-VgqNdUmvTbSedQtJNT+Eq90GWS4hXCDCBDBjno6s1dk=";
"gen_snapshot.zip" = "sha256-4O0ZfKt96x8/Jwh8DgBoPFiv84Tqf9tR/f0PVRJlJiQ=";
};
darwin-x64-profile = {
"FlutterMacOS.framework.zip" = "sha256-IrXK0Mjllic3OKaYKKpAE9gPIceTO32hGqgxGR66QmY=";
"artifacts.zip" = "sha256-IHllbxwRMrEWA1MI0DRCYYRzYAdQIL8B9b5rZHsOvjc=";
"gen_snapshot.zip" = "sha256-bPI6pHrWQR1X7CzytbJA90TYe3cg1yN+9v7JtsCCrbQ=";
};
darwin-x64-release = {
"FlutterMacOS.dSYM.zip" = "sha256-HjU8sLPwvOwO3LP7krpZZW6/t3sN3rX2frFnBp1Kk0I=";
"FlutterMacOS.framework.zip" = "sha256-GuTWojZFdSEeOiSYxH8XGSWsxcrkUpnXA61B0NpDa5A=";
"artifacts.zip" = "sha256-tQCm1HHrhffNz9a0lNIHXLBqFMbT4QiaibKvRKuuhJ4=";
"gen_snapshot.zip" = "sha256-0na+yx0Nxe/FuHVZqhgbRniZLInShoKE3USaJg0829o=";
};
"flutter_patched_sdk.zip" = "sha256-AVjXLND3nJAaGyBAhytBRUvbkJtwZEcndQSrq+D2c08=";
"flutter_patched_sdk_product.zip" = "sha256-31qgieDI897sXtEf8ok2SdFgrlN57bwhT3FUfdofZi0=";
ios = {
"artifacts.zip" = "sha256-RicBTTBX5aIQwfcolDrKe0MVG9uTp56RYMWgR75AVEw=";
};
ios-profile = {
"artifacts.zip" = "sha256-6EXHvy36K+rRGpjt0GL/DyuOhpAGeaOrZAZvPZuLyys=";
};
ios-release = {
"Flutter.dSYM.zip" = "sha256-zYqlX4QhxnDb9LasMcBcPO/+30LCfVbwC+z+wZiiEqk=";
"artifacts.zip" = "sha256-DVpynf2LxU6CPC1BPQbi8OStcIwJKX55rDSWNiJ4KNk=";
};
linux-arm64 = {
"artifacts.zip" = "sha256-djesma+IqQZgGlxQj4Gv6hAkQhQKQp7Gsa1I4hksqNc=";
"font-subset.zip" = "sha256-Wo11dks0uhLI2nu+9QJ7aLmvfsPcuqvcmquak4qv5XM=";
};
linux-arm64-debug = {
"linux-arm64-flutter-gtk.zip" = "sha256-6T2Ycxe3GTVnFGfBFfXLZwPklIndQ6hojnCSnMeXJso=";
};
linux-arm64-profile = {
"linux-arm64-flutter-gtk.zip" = "sha256-ycInFHuRu7r+50GsoFR4v/rIRiAQaQ9zFemd2d9AnpQ=";
};
linux-arm64-release = {
"linux-arm64-flutter-gtk.zip" = "sha256-J60MU8pHDVL9DyX5A3YdCRkKXnTgvALhHiEzYiPSSuA=";
};
linux-x64 = {
"artifacts.zip" = "sha256-ZUMRJ0dzaeRQUYy5S7gDLWa3w9CVhNPORN9l+lwxAMs=";
"font-subset.zip" = "sha256-pmtHAgIj5tXzUsDrrxB5JwfLDNzMCqouUCOyYN5BOEQ=";
};
linux-x64-debug = {
"linux-x64-flutter-gtk.zip" = "sha256-otmghZAiUlpLYfFaWd18UWlfctKcYsMRBMP78ZyBj/E=";
};
linux-x64-profile = {
"linux-x64-flutter-gtk.zip" = "sha256-bT6xMYlwTB9JOV1790cJqTSEXYstdI4sZCQzFzcpa5s=";
};
linux-x64-release = {
"linux-x64-flutter-gtk.zip" = "sha256-E8Eogr0nD7yaxjuoNhpvF4tTx9N53y3iOkI71Eqx5Ko=";
};
};
}

View file

@ -6,7 +6,7 @@ let
self = self =
symlinkJoin { symlinkJoin {
name = "${flutter.name}-sdk-links"; name = "${flutter.name}-sdk-links";
paths = [ flutter flutter.sdk ]; paths = [ flutter flutter.cacheDir flutter.sdk ];
nativeBuildInputs = [ makeWrapper ]; nativeBuildInputs = [ makeWrapper ];
postBuild = '' postBuild = ''

View file

@ -3,27 +3,14 @@
, darwin , darwin
, callPackage , callPackage
, flutter , flutter
, supportsLinuxDesktop ? stdenv.hostPlatform.isLinux , supportedTargetPlatforms ? [
, supportsAndroid ? (stdenv.hostPlatform.isx86_64 || stdenv.hostPlatform.isDarwin) "universal"
, supportsDarwin ? stdenv.hostPlatform.isDarwin "web"
, supportsIOS ? stdenv.hostPlatform.isDarwin ]
, includedEngineArtifacts ? { ++ lib.optional stdenv.hostPlatform.isLinux "linux"
common = [ ++ lib.optional (stdenv.hostPlatform.isx86_64 || stdenv.hostPlatform.isDarwin) "android"
"flutter_patched_sdk" ++ lib.optionals stdenv.hostPlatform.isDarwin [ "macos" "ios" ]
"flutter_patched_sdk_product" , artifactHashes ? (import ./artifacts/hashes.nix).${flutter.version}
];
platform = {
android = lib.optionalAttrs supportsAndroid
((lib.genAttrs [ "arm" "arm64" "x64" ] (architecture: [ "profile" "release" ])) // { x86 = [ "jit-release" ]; });
darwin = lib.optionalAttrs supportsDarwin
((lib.genAttrs [ "arm64" "x64" ] (architecture: [ "profile" "release" ])));
ios = lib.optionalAttrs supportsIOS
((lib.genAttrs [ "" ] (architecture: [ "profile" "release" ])));
linux = lib.optionalAttrs supportsLinuxDesktop
(lib.genAttrs ((lib.optional stdenv.hostPlatform.isx86_64 "x64") ++ (lib.optional stdenv.hostPlatform.isAarch64 "arm64"))
(architecture: [ "debug" "profile" "release" ]));
};
}
, extraPkgConfigPackages ? [ ] , extraPkgConfigPackages ? [ ]
, extraLibraries ? [ ] , extraLibraries ? [ ]
, extraIncludes ? [ ] , extraIncludes ? [ ]
@ -57,61 +44,33 @@
}: }:
let let
engineArtifacts = callPackage ./engine-artifacts { supportsLinuxDesktopTarget = builtins.elem "linux" supportedTargetPlatforms;
inherit (flutter) engineVersion;
flutterVersion = flutter.version; mkPlatformArtifacts = platform:
}; (callPackage ./artifacts/prepare-artifacts.nix {
mkCommonArtifactLinkCommand = { artifact }: src = callPackage ./artifacts/fetch-artifacts.nix {
'' inherit platform;
mkdir -p $out/artifacts/engine/common # Use a version of Flutter with just enough capabilities to download
lndir -silent ${artifact} $out/artifacts/engine/common # artifacts.
''; flutter = callPackage ./wrapper.nix {
mkPlatformArtifactLinkCommand = { artifact, os, architecture, variant ? null }: inherit flutter;
let supportedTargetPlatforms = [ ];
artifactDirectory = "${os}-${architecture}${lib.optionalString (variant != null) "-${variant}"}"; };
in hash = artifactHashes.${platform} or "";
'' };
mkdir -p $out/artifacts/engine/${artifactDirectory} }).overrideAttrs (
lndir -silent ${artifact} $out/artifacts/engine/${artifactDirectory} if builtins.pathExists ./artifacts/overrides/${platform}.nix
''; then callPackage ./artifacts/overrides/${platform}.nix { }
engineArtifactDirectory = else ({ ... }: { })
runCommandLocal "flutter-engine-artifacts-${flutter.version}" { nativeBuildInputs = [ lndir ]; } );
(
builtins.concatStringsSep "\n"
((map
(name: mkCommonArtifactLinkCommand {
artifact = engineArtifacts.common.${name};
})
(includedEngineArtifacts.common or [ ])) ++
(builtins.foldl'
(commands: os: commands ++
(builtins.foldl'
(commands: architecture: commands ++
(builtins.foldl'
(commands: variant: commands ++
(map
(artifact: mkPlatformArtifactLinkCommand {
inherit artifact os architecture variant;
})
engineArtifacts.platform.${os}.${architecture}.variants.${variant}))
(map
(artifact: mkPlatformArtifactLinkCommand {
inherit artifact os architecture;
})
engineArtifacts.platform.${os}.${architecture}.base)
includedEngineArtifacts.platform.${os}.${architecture}))
[ ]
(builtins.attrNames includedEngineArtifacts.platform.${os})))
[ ]
(builtins.attrNames (includedEngineArtifacts.platform or { }))))
);
cacheDir = symlinkJoin { cacheDir = symlinkJoin {
name = "flutter-cache-dir"; name = "flutter-cache-dir";
paths = [ paths = map mkPlatformArtifacts supportedTargetPlatforms;
engineArtifactDirectory postBuild = ''
"${flutter}/bin/cache" mkdir -p "$out/bin/cache"
]; ln -s '${flutter}/bin/cache/dart-sdk' "$out/bin/cache"
'';
}; };
# By default, Flutter stores downloaded files (such as the Pub cache) in the SDK directory. # By default, Flutter stores downloaded files (such as the Pub cache) in the SDK directory.
@ -120,7 +79,7 @@ let
# We do not patch it since the script doesn't require engine artifacts(which are the only thing not added by the unwrapped derivation), so it shouldn't fail, and patching it will just be harder to maintain. # We do not patch it since the script doesn't require engine artifacts(which are the only thing not added by the unwrapped derivation), so it shouldn't fail, and patching it will just be harder to maintain.
immutableFlutter = writeShellScript "flutter_immutable" '' immutableFlutter = writeShellScript "flutter_immutable" ''
export PUB_CACHE=''${PUB_CACHE:-"$HOME/.pub-cache"} export PUB_CACHE=''${PUB_CACHE:-"$HOME/.pub-cache"}
export FLUTTER_CACHE_DIR=''${FLUTTER_CACHE_DIR:-'${cacheDir}'} export FLUTTER_CACHE_DIR=''${FLUTTER_CACHE_DIR:-'${cacheDir}/bin/cache'}
${flutter}/bin/flutter "$@" ${flutter}/bin/flutter "$@"
''; '';
@ -128,7 +87,7 @@ let
tools = [ git which ]; tools = [ git which ];
# Libraries that Flutter apps depend on at runtime. # Libraries that Flutter apps depend on at runtime.
appRuntimeDeps = lib.optionals supportsLinuxDesktop [ appRuntimeDeps = lib.optionals supportsLinuxDesktopTarget [
atk atk
cairo cairo
gdk-pixbuf gdk-pixbuf
@ -152,10 +111,10 @@ let
# Some header files and libraries are not properly located by the Flutter SDK. # Some header files and libraries are not properly located by the Flutter SDK.
# They must be manually included. # They must be manually included.
appStaticBuildDeps = (lib.optionals supportsLinuxDesktop [ libX11 xorgproto zlib ]) ++ extraLibraries; appStaticBuildDeps = (lib.optionals supportsLinuxDesktopTarget [ libX11 xorgproto zlib ]) ++ extraLibraries;
# Tools used by the Flutter SDK to compile applications. # Tools used by the Flutter SDK to compile applications.
buildTools = lib.optionals supportsLinuxDesktop [ buildTools = lib.optionals supportsLinuxDesktopTarget [
pkg-config pkg-config
cmake cmake
ninja ninja
@ -174,12 +133,12 @@ in
nativeBuildInputs = [ makeWrapper ] nativeBuildInputs = [ makeWrapper ]
++ lib.optionals stdenv.hostPlatform.isDarwin [ darwin.DarwinTools ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ darwin.DarwinTools ]
++ lib.optionals supportsLinuxDesktop [ glib wrapGAppsHook ]; ++ lib.optionals supportsLinuxDesktopTarget [ glib wrapGAppsHook ];
passthru = flutter.passthru // { passthru = flutter.passthru // {
inherit (flutter) version; inherit (flutter) version;
unwrapped = flutter; unwrapped = flutter;
inherit engineArtifacts; inherit cacheDir;
}; };
dontUnpack = true; dontUnpack = true;