1{ pname
2, version
3, patches
4, dart
5, src
6}:
7
8{ bash
9, buildFHSUserEnv
10, cacert
11, coreutils
12, git
13, runCommand
14, stdenv
15, lib
16, fetchurl
17, alsaLib
18, dbus
19, expat
20, libpulseaudio
21, libuuid
22, libX11
23, libxcb
24, libXcomposite
25, libXcursor
26, libXdamage
27, libXfixes
28, libXrender
29, libXtst
30, libXi
31, libXext
32, libGL
33, nspr
34, nss
35, systemd
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/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/.packages" "$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 mkdir -p $out
78 cp -r . $out
79 mkdir -p $out/bin/cache/
80 ln -sf ${dart} $out/bin/cache/dart-sdk
81 '';
82 };
83
84 # Wrap flutter inside an fhs user env to allow execution of binary,
85 # like adb from $ANDROID_HOME or java from android-studio.
86 fhsEnv = buildFHSUserEnv {
87 name = "${drvName}-fhs-env";
88 multiPkgs = pkgs: [
89 # Flutter only use these certificates
90 (runCommand "fedoracert" { } ''
91 mkdir -p $out/etc/pki/tls/
92 ln -s ${cacert}/etc/ssl/certs $out/etc/pki/tls/certs
93 '')
94 pkgs.zlib
95 ];
96 targetPkgs = pkgs:
97 with pkgs; [
98 bash
99 curl
100 dart
101 git
102 unzip
103 which
104 xz
105
106 # flutter test requires this lib
107 libGLU
108
109 # for android emulator
110 alsaLib
111 dbus
112 expat
113 libpulseaudio
114 libuuid
115 libX11
116 libxcb
117 libXcomposite
118 libXcursor
119 libXdamage
120 libXext
121 libXfixes
122 libXi
123 libXrender
124 libXtst
125 libGL
126 nspr
127 nss
128 systemd
129 ];
130 };
131
132in
133runCommand drvName
134{
135 startScript = ''
136 #!${bash}/bin/bash
137 export PUB_CACHE=''${PUB_CACHE:-"$HOME/.pub-cache"}
138 export ANDROID_EMULATOR_USE_SYSTEM_LIBS=1
139 ${fhsEnv}/bin/${drvName}-fhs-env ${flutter}/bin/flutter --no-version-check "$@"
140 '';
141 preferLocalBuild = true;
142 allowSubstitutes = false;
143 passthru = { unwrapped = flutter; };
144 meta = with lib; {
145 description = "Flutter is Google's SDK for building mobile, web and desktop with Dart";
146 longDescription = ''
147 Flutter is Google’s UI toolkit for building beautiful,
148 natively compiled applications for mobile, web, and desktop from a single codebase.
149 '';
150 homepage = "https://flutter.dev";
151 license = licenses.bsd3;
152 platforms = [ "x86_64-linux" ];
153 maintainers = with maintainers; [ babariviere ericdallo thiagokokada ];
154 };
155} ''
156 mkdir -p $out/bin
157
158 echo -n "$startScript" > $out/bin/${pname}
159 chmod +x $out/bin/${pname}
160''