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