1{ lib
2, stdenv
3, hostPlatform
4, engineVersion
5, fetchzip
6, autoPatchelfHook
7
8, gtk3
9}:
10
11let
12 hashes = (import ./hashes.nix).${engineVersion} or
13 (throw "There are no known artifact hashes for Flutter engine version ${engineVersion}.");
14
15 artifacts =
16 {
17 common = {
18 flutter_patched_sdk = { archive = "flutter_patched_sdk.zip"; };
19 flutter_patched_sdk_product = { archive = "flutter_patched_sdk_product.zip"; };
20 };
21 platform = {
22 android =
23 (lib.genAttrs
24 [ "arm" "arm64" "x64" ]
25 (arch:
26 {
27 base = [
28 { archive = "artifacts.zip"; }
29 ];
30 variants = lib.genAttrs [ "profile" "release" ]
31 (variant: [
32 { archive = "artifacts.zip"; }
33 { subdirectory = true; archive = "${lib.toLower hostPlatform.uname.system}-x64.zip"; }
34 ]);
35 })) //
36 {
37 "x86" = {
38 base = [
39 { archive = "artifacts.zip"; }
40 ];
41 variants.jit-release = [
42 { archive = "artifacts.zip"; }
43 ];
44 };
45 };
46
47 linux = lib.genAttrs
48 [ "arm64" "x64" ]
49 (arch:
50 let
51 linux-flutter-gtk = {
52 archive = "linux-${arch}-flutter-gtk.zip";
53 buildInputs = [ gtk3 ];
54 };
55 in
56 {
57 base = [
58 ({ archive = "artifacts.zip"; } // lib.optionalAttrs (arch == "arm64") {
59 # For some reason, the arm64 artifacts are missing shader code in Flutter < 3.10.0.
60 postPatch = ''
61 if [ ! -d shader_lib ]; then
62 ln -s ${lib.findSingle
63 (pkg: lib.getName pkg == "flutter-artifact-linux-x64-artifacts")
64 (throw "Could not find the x64 artifact archive.")
65 (throw "Could not find the correct x64 artifact archive.")
66 artifactDerivations.platform.linux.x64.base
67 }/shader_lib .
68 fi
69 '';
70 })
71 { archive = "font-subset.zip"; }
72 (linux-flutter-gtk // {
73 # https://github.com/flutter/flutter/commit/9d94a51b607600a39c14470c35c676eb3e30eed6
74 variant = "debug";
75 })
76 ];
77 variants = lib.genAttrs [ "debug" "profile" "release" ] (variant: [
78 linux-flutter-gtk
79 ]);
80 });
81 };
82 };
83
84 mkArtifactDerivation = { platform ? null, variant ? null, subdirectory ? null, archive, ... }@args:
85 let
86 artifactDirectory = if platform == null then null else "${platform}${lib.optionalString (variant != null) "-${variant}"}";
87 archiveBasename = lib.removeSuffix ".${(lib.last (lib.splitString "." archive))}" archive;
88 in
89 stdenv.mkDerivation ({
90 pname = "flutter-artifact${lib.optionalString (platform != null) "-${artifactDirectory}"}-${archiveBasename}";
91 version = engineVersion;
92
93 src = fetchzip {
94 url = "https://storage.googleapis.com/flutter_infra_release/flutter/${engineVersion}${lib.optionalString (platform != null) "/${artifactDirectory}"}/${archive}";
95 stripRoot = false;
96 hash = (if artifactDirectory == null then hashes else hashes.${artifactDirectory}).${archive};
97 };
98
99 nativeBuildInputs = [ autoPatchelfHook ];
100
101 installPhase =
102 let
103 destination = "$out/${if subdirectory == true then archiveBasename else if subdirectory != null then subdirectory else "."}";
104 in
105 ''
106 mkdir -p "${destination}"
107 cp -r . "${destination}"
108 '';
109 } // args);
110
111 artifactDerivations = {
112 common = builtins.mapAttrs (name: mkArtifactDerivation) artifacts.common;
113 platform =
114 builtins.mapAttrs
115 (os: architectures:
116 builtins.mapAttrs
117 (architecture: variants: {
118 base = map
119 (args: mkArtifactDerivation ({
120 platform = "${os}-${architecture}";
121 } // args))
122 variants.base;
123 variants = builtins.mapAttrs
124 (variant: variantArtifacts: map
125 (args: mkArtifactDerivation ({
126 platform = "${os}-${architecture}";
127 inherit variant;
128 } // args))
129 variantArtifacts)
130 variants.variants;
131 })
132 architectures)
133 artifacts.platform;
134 };
135in
136artifactDerivations