1{
2 useNixpkgsEngine ? false,
3 version,
4 engineVersion,
5 engineHashes ? { },
6 engineUrl ?
7 if lib.versionAtLeast version "3.29" then
8 "https://github.com/flutter/flutter.git@${engineVersion}"
9 else
10 "https://github.com/flutter/engine.git@${engineVersion}",
11 enginePatches ? [ ],
12 engineRuntimeModes ? [
13 "release"
14 "debug"
15 ],
16 engineSwiftShaderHash,
17 engineSwiftShaderRev,
18 patches,
19 channel,
20 dart,
21 src,
22 pubspecLock,
23 artifactHashes ? null,
24 lib,
25 stdenv,
26 callPackage,
27 makeWrapper,
28 darwin,
29 gitMinimal,
30 which,
31 jq,
32 flutterTools ? null,
33}@args:
34
35let
36 engine =
37 if args.useNixpkgsEngine or false then
38 callPackage ./engine/default.nix {
39 inherit (args) dart;
40 dartSdkVersion = args.dart.version;
41 flutterVersion = version;
42 swiftshaderRev = engineSwiftShaderRev;
43 swiftshaderHash = engineSwiftShaderHash;
44 version = engineVersion;
45 hashes = engineHashes;
46 url = engineUrl;
47 patches = enginePatches;
48 runtimeModes = engineRuntimeModes;
49 }
50 else
51 null;
52
53 dart = if args.useNixpkgsEngine or false then engine.dart else args.dart;
54
55 flutterTools =
56 args.flutterTools or (callPackage ./flutter-tools.nix {
57 inherit dart version;
58 flutterSrc = src;
59 inherit patches;
60 inherit pubspecLock;
61 systemPlatform = stdenv.hostPlatform.system;
62 });
63
64 unwrapped = stdenv.mkDerivation {
65 name = "flutter-${version}-unwrapped";
66 inherit src patches version;
67
68 nativeBuildInputs = [
69 makeWrapper
70 jq
71 gitMinimal
72 ]
73 ++ lib.optionals stdenv.hostPlatform.isDarwin [ darwin.DarwinTools ];
74 strictDeps = true;
75
76 preConfigure = ''
77 if [ "$(< bin/internal/engine.version)" != '${engineVersion}' ]; then
78 echo 1>&2 "The given engine version (${engineVersion}) does not match the version required by the Flutter SDK ($(< bin/internal/engine.version))."
79 exit 1
80 fi
81 '';
82
83 postPatch = ''
84 patchShebangs --build ./bin/
85 patchShebangs packages/flutter_tools/bin
86 '';
87
88 buildPhase = ''
89 # The flutter_tools package tries to run many Git commands. In most
90 # cases, unexpected output is handled gracefully, but commands are never
91 # expected to fail completely. A blank repository needs to be created.
92 rm -rf .git # Remove any existing Git directory
93 git init -b nixpkgs
94 GIT_AUTHOR_NAME=Nixpkgs GIT_COMMITTER_NAME=Nixpkgs \
95 GIT_AUTHOR_EMAIL= GIT_COMMITTER_EMAIL= \
96 GIT_AUTHOR_DATE='1/1/1970 00:00:00 +0000' GIT_COMMITTER_DATE='1/1/1970 00:00:00 +0000' \
97 git commit --allow-empty -m "Initial commit"
98 (. '${../../../build-support/fetchgit/deterministic-git}'; make_deterministic_repo .)
99
100 mkdir -p bin/cache
101
102 # Add a flutter_tools artifact stamp, and build a snapshot.
103 # This is the Flutter CLI application.
104 echo "$(git rev-parse HEAD)" > bin/cache/flutter_tools.stamp
105 ln -s '${flutterTools}/share/flutter_tools.snapshot' bin/cache/flutter_tools.snapshot
106
107 # Some of flutter_tools's dependencies contain static assets. The
108 # application attempts to read its own package_config.json to find these
109 # assets at runtime.
110 mkdir -p packages/flutter_tools/.dart_tool
111 ln -s '${flutterTools.pubcache}/package_config.json' packages/flutter_tools/.dart_tool/package_config.json
112
113 echo -n "${version}" > version
114 cat <<EOF > bin/cache/flutter.version.json
115 {
116 "devToolsVersion": "$(cat "${dart}/bin/resources/devtools/version.json" | jq -r .version)",
117 "flutterVersion": "${version}",
118 "frameworkVersion": "${version}",
119 "channel": "${channel}",
120 "repositoryUrl": "https://github.com/flutter/flutter.git",
121 "frameworkRevision": "nixpkgs000000000000000000000000000000000",
122 "frameworkCommitDate": "1970-01-01 00:00:00",
123 "engineRevision": "${engineVersion}",
124 "dartSdkVersion": "${dart.version}"
125 }
126 EOF
127
128 # Suppress a small error now that `.gradle`'s location changed.
129 # Location changed because of the patch "gradle-flutter-tools-wrapper.patch".
130 mkdir -p "$out/packages/flutter_tools/gradle/.gradle"
131 '';
132
133 installPhase = ''
134 runHook preInstall
135
136 mkdir -p $out
137 cp -r . $out
138 rm -rf $out/bin/cache/dart-sdk
139 ln -sf ${dart} $out/bin/cache/dart-sdk
140
141 # The regular launchers are designed to download/build/update SDK
142 # components, and are not very useful in Nix.
143 # Replace them with simple links and wrappers.
144 rm "$out/bin"/{dart,flutter}
145 ln -s "$out/bin/cache/dart-sdk/bin/dart" "$out/bin/dart"
146 makeShellWrapper "$out/bin/dart" "$out/bin/flutter" \
147 --set-default FLUTTER_ROOT "$out" \
148 --set FLUTTER_ALREADY_LOCKED true \
149 --add-flags "--disable-dart-dev --packages='${flutterTools.pubcache}/package_config.json' \$NIX_FLUTTER_TOOLS_VM_OPTIONS $out/bin/cache/flutter_tools.snapshot"
150
151 runHook postInstall
152 '';
153
154 doInstallCheck = true;
155 nativeInstallCheckInputs = [
156 which
157 ]
158 ++ lib.optionals stdenv.hostPlatform.isDarwin [ darwin.DarwinTools ];
159 installCheckPhase = ''
160 runHook preInstallCheck
161
162 export HOME="$(mktemp -d)"
163 $out/bin/flutter config --android-studio-dir $HOME
164 $out/bin/flutter config --android-sdk $HOME
165 $out/bin/flutter --version | fgrep -q '${builtins.substring 0 10 engineVersion}'
166
167 runHook postInstallCheck
168 '';
169
170 passthru = {
171 # TODO: rely on engine.version instead of engineVersion
172 inherit
173 dart
174 engineVersion
175 artifactHashes
176 channel
177 ;
178 tools = flutterTools;
179 # The derivation containing the original Flutter SDK files.
180 # When other derivations wrap this one, any unmodified files
181 # found here should be included as-is, for tooling compatibility.
182 sdk = unwrapped;
183 }
184 // lib.optionalAttrs (engine != null) {
185 inherit engine;
186 };
187
188 meta = with lib; {
189 description = "Flutter is Google's SDK for building mobile, web and desktop with Dart";
190 longDescription = ''
191 Flutter is Google’s UI toolkit for building beautiful,
192 natively compiled applications for mobile, web, and desktop from a single codebase.
193 '';
194 homepage = "https://flutter.dev";
195 license = licenses.bsd3;
196 platforms = [
197 "x86_64-linux"
198 "aarch64-linux"
199 "x86_64-darwin"
200 "aarch64-darwin"
201 ];
202 mainProgram = "flutter";
203 maintainers = with maintainers; [
204 ericdallo
205 ];
206 teams = [ teams.flutter ];
207 };
208 };
209in
210unwrapped