1{ pname
2, version
3, patches
4, dart
5, src
6}:
7
8{ bash
9, buildFHSUserEnv
10, cacert
11, git
12, runCommand
13, stdenv
14, lib
15, alsa-lib
16, dbus
17, expat
18, libpulseaudio
19, libuuid
20, libX11
21, libxcb
22, libXcomposite
23, libXcursor
24, libXdamage
25, libXfixes
26, libXrender
27, libXtst
28, libXi
29, libXext
30, libGL
31, nspr
32, nss
33, systemd
34, which
35, callPackage
36}:
37let
38 drvName = "flutter-${version}";
39 flutter = stdenv.mkDerivation {
40 name = "${drvName}-unwrapped";
41
42 buildInputs = [ git ];
43
44 inherit src patches version;
45
46 postPatch = ''
47 patchShebangs --build ./bin/
48 '';
49
50 buildPhase = ''
51 export FLUTTER_ROOT="$(pwd)"
52 export FLUTTER_TOOLS_DIR="$FLUTTER_ROOT/packages/flutter_tools"
53 export SCRIPT_PATH="$FLUTTER_TOOLS_DIR/bin/flutter_tools.dart"
54
55 export SNAPSHOT_PATH="$FLUTTER_ROOT/bin/cache/flutter_tools.snapshot"
56 export STAMP_PATH="$FLUTTER_ROOT/bin/cache/flutter_tools.stamp"
57
58 export DART_SDK_PATH="${dart}"
59
60 HOME=../.. # required for pub upgrade --offline, ~/.pub-cache
61 # path is relative otherwise it's replaced by /build/flutter
62
63 pushd "$FLUTTER_TOOLS_DIR"
64 ${dart}/bin/dart pub get --offline
65 popd
66
67 local revision="$(cd "$FLUTTER_ROOT"; git rev-parse HEAD)"
68 ${dart}/bin/dart --snapshot="$SNAPSHOT_PATH" --packages="$FLUTTER_TOOLS_DIR/.dart_tool/package_config.json" "$SCRIPT_PATH"
69 echo "$revision" > "$STAMP_PATH"
70 echo -n "${version}" > version
71
72 rm -r bin/cache/{artifacts,dart-sdk,downloads}
73 rm bin/cache/*.stamp
74 '';
75
76 installPhase = ''
77 runHook preInstall
78
79 mkdir -p $out
80 cp -r . $out
81 mkdir -p $out/bin/cache/
82 ln -sf ${dart} $out/bin/cache/dart-sdk
83
84 runHook postInstall
85 '';
86
87 doInstallCheck = true;
88 installCheckInputs = [ which ];
89 installCheckPhase = ''
90 runHook preInstallCheck
91
92 export HOME="$(mktemp -d)"
93 $out/bin/flutter config --android-studio-dir $HOME
94 $out/bin/flutter config --android-sdk $HOME
95 $out/bin/flutter --version | fgrep -q '${version}'
96
97 runHook postInstallCheck
98 '';
99 };
100
101 # Wrap flutter inside an fhs user env to allow execution of binary,
102 # like adb from $ANDROID_HOME or java from android-studio.
103 fhsEnv = buildFHSUserEnv {
104 name = "${drvName}-fhs-env";
105 multiPkgs = pkgs: [
106 # Flutter only use these certificates
107 (runCommand "fedoracert" { } ''
108 mkdir -p $out/etc/pki/tls/
109 ln -s ${cacert}/etc/ssl/certs $out/etc/pki/tls/certs
110 '')
111 pkgs.zlib
112 ];
113 targetPkgs = pkgs:
114 with pkgs; [
115 bash
116 curl
117 dart
118 git
119 unzip
120 which
121 xz
122
123 # flutter test requires this lib
124 libGLU
125
126 # for android emulator
127 alsa-lib
128 dbus
129 expat
130 libpulseaudio
131 libuuid
132 libX11
133 libxcb
134 libXcomposite
135 libXcursor
136 libXdamage
137 libXext
138 libXfixes
139 libXi
140 libXrender
141 libXtst
142 libGL
143 nspr
144 nss
145 systemd
146 ];
147 };
148
149in
150let
151self = (self:
152runCommand drvName
153{
154 startScript = ''
155 #!${bash}/bin/bash
156 export PUB_CACHE=''${PUB_CACHE:-"$HOME/.pub-cache"}
157 export ANDROID_EMULATOR_USE_SYSTEM_LIBS=1
158 ${fhsEnv}/bin/${drvName}-fhs-env ${flutter}/bin/flutter --no-version-check "$@"
159 '';
160 preferLocalBuild = true;
161 allowSubstitutes = false;
162 passthru = {
163 unwrapped = flutter;
164 inherit dart;
165 mkFlutterApp = callPackage ../../../build-support/flutter {
166 flutter = self;
167 };
168 };
169 meta = with lib; {
170 description = "Flutter is Google's SDK for building mobile, web and desktop with Dart";
171 longDescription = ''
172 Flutter is Google’s UI toolkit for building beautiful,
173 natively compiled applications for mobile, web, and desktop from a single codebase.
174 '';
175 homepage = "https://flutter.dev";
176 license = licenses.bsd3;
177 platforms = [ "x86_64-linux" "aarch64-linux" ];
178 maintainers = with maintainers; [ babariviere ericdallo ];
179 };
180} ''
181 mkdir -p $out/bin
182
183 mkdir -p $out/bin/cache/
184 ln -sf ${dart} $out/bin/cache/dart-sdk
185
186 echo -n "$startScript" > $out/bin/${pname}
187 chmod +x $out/bin/${pname}
188'') self;
189in
190self