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