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