forked from FlafyDev/dart-flutter-nix
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-flutter-app.nix
186 lines (159 loc) · 3.89 KB
/
build-flutter-app.nix
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
{
flutter,
lib,
cmake,
ninja,
pkg-config,
wrapGAppsHook,
autoPatchelfHook,
util-linux,
libselinux,
libsepol,
libthai,
libdatrie,
libxkbcommon,
at-spi2-core,
xorg,
dbus,
gtk3,
glib,
pcre,
pcre2,
libepoxy,
git,
dart,
bash,
curl,
unzip,
which,
xz,
stdenv,
fetchzip,
runCommand,
clang,
tree,
callPackage,
}: args: let
inherit
(lib)
importJSON
mapAttrsToList
makeLibraryPath
;
shared = callPackage ./shared {};
deps = importJSON (args.depsFile or (args.src + "/deps2nix.lock"));
pubCache = shared.generatePubCache {inherit deps args;};
# ~/.cache/flutter/<cache files>
cache = runCommand "${args.pname}-cache" {} ((mapAttrsToList
(_name: sdk: let
derv = fetchzip (removeAttrs sdk ["cachePath"]);
in ''
mkdir -p $out/${sdk.cachePath}
ln -s ${derv}/* $out/${sdk.cachePath}
'')
deps.sdk.artifacts)
++ (mapAttrsToList
(name: version: ''
echo ${version} > $out/${name}.stamp
'')
deps.sdk.stamps));
in
stdenv.mkDerivation (args
// rec {
nativeBuildInputs =
[
cmake
ninja
pkg-config
wrapGAppsHook
autoPatchelfHook
bash
curl
flutter.dart
git
unzip
which
xz
# Testing
tree
]
++ (args.nativeBuildInputs or []);
buildInputs =
[
at-spi2-core.dev
clang
cmake
dart
dbus.dev
flutter
gtk3
libdatrie
libepoxy.dev
libselinux
libsepol
libthai
libxkbcommon
ninja
pcre
pkg-config
util-linux.dev
xorg.libXdmcp
xorg.libXtst
gtk3
glib
pcre
pcre2
util-linux
]
++ (args.buildInputs or []);
PUB_CACHE = toString pubCache;
LD_LIBRARY_PATH = makeLibraryPath [libepoxy];
NIX_LDFLAGS = "-rpath ${lib.makeLibraryPath buildInputs}";
configurePhase = ''
runHook preConfigure
HOME=$(mktemp -d)
mkdir -p $HOME/.cache/flutter
cp -r ${cache}/* $HOME/.cache/flutter
chmod +wr -R $HOME/.cache/flutter
# Test directories
# tree $HOME/.cache/flutter
# tree $PUB_CACHE -L 3
flutter config --no-analytics &>/dev/null # mute first-run
flutter config --enable-linux-desktop
flutter pub get --offline
runHook postConfigure
'';
buildPhase = ''
runHook preBuild
flutter build linux -v
runHook postBuild
'';
installPhase = ''
runHook preInstall
built=build/linux/*/release/bundle
mkdir -p $out/bin
mv $built $out/app
for f in $(find $out/app -iname "*.desktop" -type f); do
install -D $f $out/share/applications/$(basename $f)
done
for f in $(find $out/app -maxdepth 1 -type f); do
ln -s $f $out/bin/$(basename $f)
done
# this confuses autopatchelf hook otherwise
rm -rf "$HOME"
# make *.so executable
find $out/app -iname "*.so" -type f -exec chmod +x {} +
# remove stuff like /build/source/packages/ubuntu_desktop_installer/linux/flutter/ephemeral
for f in $(find $out/app -executable -type f); do
if patchelf --print-rpath "$f" | grep /build; then # this ignores static libs (e,g. libapp.so) also
echo "strip RPath of $f"
newrp=$(patchelf --print-rpath $f | sed -r "s|/build.*ephemeral:||g" | sed -r "s|/build.*profile:||g")
patchelf --set-rpath "$newrp" "$f"
fi
done
runHook postInstall
'';
# outputHash = lib.fakeSha256;
# outputHashAlgo = "sha256";
# dontUseCmakeConfigure = true;
})