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