forked from concrete-utopia/utopia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshell.nix
414 lines (392 loc) · 14.9 KB
/
shell.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
{
compiler ? "ghc865",
includeServerBuildSupport ? true,
includeEditorBuildSupport ? true,
includeRunLocallySupport ? true,
includeReleaseSupport ? false
}:
let
release = (import ./release.nix {});
pkgs = release.pkgs;
lib = pkgs.lib;
node = pkgs.nodejs-14_x;
stdenv = pkgs.stdenv;
cabal = pkgs.haskellPackages.cabal-install;
# Slightly kludgy because the zlib Haskell package is a pain in the face.
ghc = pkgs.haskell.packages.${compiler}.ghcWithPackages (hpkgs: with hpkgs; [
zlib
]);
baseEditorScripts = [
(pkgs.writeScriptBin "install-editor" ''
#!/usr/bin/env bash
set -e
update-vscode-build-extension
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/editor
${node}/bin/npm --scripts-prepend-node-path=true install
'')
(pkgs.writeScriptBin "install-editor-ci" ''
#!/usr/bin/env bash
set -e
build-utopia-vscode-common
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/editor
${node}/bin/npm --scripts-prepend-node-path=true install
'')
(pkgs.writeScriptBin "install-website" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/website-next
${node}/bin/npm --scripts-prepend-node-path=true install
'')
(pkgs.writeScriptBin "test-editor" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/editor
${node}/bin/npm --scripts-prepend-node-path=true test
'')
(pkgs.writeScriptBin "test-editor-move-template-only-ci" ''
#!/usr/bin/env bash
set -e
install-editor-ci
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/editor
${node}/bin/npm --scripts-prepend-node-path=true run test-move-template-only-ci
'')
(pkgs.writeScriptBin "test-utopia-api" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/utopia-api
${node}/bin/npm --scripts-prepend-node-path=true test
'')
(pkgs.writeScriptBin "test-website" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/website-next
# ${node}/bin/npm --scripts-prepend-node-path=true test
'')
(pkgs.writeScriptBin "test-editor-all" ''
#!/usr/bin/env bash
set -e
test-editor
test-website
'')
(pkgs.writeScriptBin "check-editor" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/editor
${node}/bin/npm --scripts-prepend-node-path=true run check
'')
(pkgs.writeScriptBin "check-editor-ci" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/editor
${node}/bin/npm --scripts-prepend-node-path=true run check-ci
'')
(pkgs.writeScriptBin "check-editor-all-ci" ''
#!/usr/bin/env bash
set -e
install-editor-ci
install-website
check-editor-ci
test-website
'')
(pkgs.writeScriptBin "build-editor-staging-ci" ''
#!/usr/bin/env bash
set -e
install-editor-ci
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/editor
${node}/bin/npm --scripts-prepend-node-path=true run staging
'')
(pkgs.writeScriptBin "build-utopia-vscode-common" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/utopia-vscode-common
${node}/bin/npm --scripts-prepend-node-path=true install
${node}/bin/npm --scripts-prepend-node-path=true run build
'')
(pkgs.writeScriptBin "build-utopia-vscode-extension" ''
#!/usr/bin/env bash
set -e
build-utopia-vscode-common
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/utopia-vscode-extension
${node}/bin/npm --scripts-prepend-node-path=true install
${node}/bin/npm --scripts-prepend-node-path=true run build
'')
(pkgs.writeScriptBin "update-vscode-build-extension" ''
#!/usr/bin/env bash
set -e
build-utopia-vscode-extension
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/vscode-build
${pkgs.yarn}/bin/yarn run pull-utopia-extension
'')
(pkgs.writeScriptBin "build-vscode" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/vscode-build
${pkgs.yarn}/bin/yarn
${pkgs.yarn}/bin/yarn run build
'')
(pkgs.writeScriptBin "build-vscode-with-extension" ''
#!/usr/bin/env bash
set -e
build-utopia-vscode-extension
build-vscode
'')
];
withBaseEditorScripts = lib.optionals includeEditorBuildSupport baseEditorScripts;
serverBaseScripts = [
(pkgs.writeScriptBin "rebuild-cabal" ''
#!/usr/bin/env bash
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/server
${pkgs.haskellPackages.hpack}/bin/hpack
'')
(pkgs.writeScriptBin "cabal-update" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/server
${cabal}/bin/cabal new-update 'hackage.haskell.org,2021-06-09T12:43:34Z'
'')
(pkgs.writeScriptBin "test-server-inner" ''
#!/usr/bin/env bash
set -e
rebuild-cabal
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/server
${cabal}/bin/cabal new-test --disable-optimization --disable-profiling --disable-documentation --disable-library-coverage --disable-benchmarks utopia-web-test
'')
(pkgs.writeScriptBin "test-server" ''
#!/usr/bin/env bash
set -e
cabal-update
test-server-inner
'')
(pkgs.writeScriptBin "watch-tests" ''
#!/usr/bin/env bash
set -e
cabal-update
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/server
${pkgs.nodePackages.nodemon}/bin/nodemon -e hs,yaml --watch src --watch test --watch package.yaml --exec test-server-inner
'')
(pkgs.writeScriptBin "test-server-ci" ''
#!/usr/bin/env bash
set -e
cabal-update
test-server-inner
'')
];
withServerBaseScripts = withBaseEditorScripts ++ (lib.optionals includeServerBuildSupport serverBaseScripts);
editorRunScripts = [
(pkgs.writeScriptBin "watch-tsc" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/editor
${node}/bin/npx --scripts-prepend-node-path=true tsc --watch && NODE_OPTIONS=--max_old_space_size=4096
'')
(pkgs.writeScriptBin "watch-editor-cowboy" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/editor
RUN_COMPILER=true ${node}/bin/npm --scripts-prepend-node-path=true run move-fast-and-break-things
'')
(pkgs.writeScriptBin "watch-editor-no-compile" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/editor
RUN_COMPILER=false ${node}/bin/npm --scripts-prepend-node-path=true run move-fast-and-break-things
'')
(pkgs.writeScriptBin "watch-editor-performance" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/editor
RUN_COMPILER=true ${node}/bin/npm --scripts-prepend-node-path=true run performance-test
'')
(pkgs.writeScriptBin "watch-editor-cowboy-danger-hot" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/editor
RUN_COMPILER=true ${node}/bin/npm --scripts-prepend-node-path=true run move-fast-and-break-things-hot
'')
(pkgs.writeScriptBin "watch-website" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/website-next
${node}/bin/npm --scripts-prepend-node-path=true install
BROWSER=none ${node}/bin/npm --scripts-prepend-node-path=true run dev
'')
];
withEditorRunScripts = withServerBaseScripts ++ (lib.optionals includeRunLocallySupport editorRunScripts);
serverRunScripts = [
(pkgs.writeScriptBin "style-project" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/server/src
find . -name '*.hs' | xargs ${pkgs.haskellPackages.stylish-haskell}/bin/stylish-haskell -i
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/server/test
find . -name '*.hs' | xargs ${pkgs.haskellPackages.stylish-haskell}/bin/stylish-haskell -i
'')
(pkgs.writeScriptBin "run-server-inner" ''
#!/usr/bin/env bash
set -e
rebuild-cabal
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/server
${cabal}/bin/cabal new-run -j --disable-optimization --disable-profiling --disable-documentation --disable-library-coverage --disable-benchmarks utopia-web -- +RTS -N -c
'')
(pkgs.writeScriptBin "run-server" ''
#!/usr/bin/env bash
set -e
cabal-update
run-server-inner
'')
(pkgs.writeScriptBin "watch-server" ''
#!/usr/bin/env bash
set -e
cabal-update
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/server
${pkgs.nodePackages.nodemon}/bin/nodemon -e hs,yaml --watch src --watch package.yaml --exec run-server-inner
'')
];
withServerRunScripts = withEditorRunScripts ++ (lib.optionals includeRunLocallySupport serverRunScripts);
vscodeDevScripts = [
(pkgs.writeScriptBin "update-vscode-patch" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/vscode-build
${pkgs.yarn}/bin/yarn
${pkgs.yarn}/bin/yarn run make-patch
'')
(pkgs.writeScriptBin "watch-utopia-vscode-common" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/utopia-vscode-common
${node}/bin/npm --scripts-prepend-node-path=true install
${node}/bin/npm --scripts-prepend-node-path=true run watch-dev
'')
(pkgs.writeScriptBin "watch-utopia-vscode-extension" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/utopia-vscode-extension
${node}/bin/npm --scripts-prepend-node-path=true install
${node}/bin/npm --scripts-prepend-node-path=true run watch-dev
'')
(pkgs.writeScriptBin "pull-extension" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/vscode-build
${pkgs.yarn}/bin/yarn run pull-utopia-extension
'')
(pkgs.writeScriptBin "watch-vscode-build-extension-only" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/vscode-build
${pkgs.nodePackages.nodemon}/bin/nodemon --watch ../utopia-vscode-extension/dist/browser/extension.js --exec pull-extension
'')
];
# For the useful scripts in our dev environments
customDevScripts = [
(pkgs.writeScriptBin "stop-dev" ''
#!/usr/bin/env bash
# Kill nodemon because it just seems to keep running.
pkill nodemon
tmux kill-session -t utopia-dev
'')
(pkgs.writeScriptBin "start-minimal" ''
#!/usr/bin/env bash
stop-dev
tmux new-session -s utopia-dev \; \
set-option -g mouse on \; \
new-window -n "Scratchpad" \; \
new-window -n "Server" \; \
send-keys -t :2 watch-server C-m \; \
new-window -n "Editor TSC" \; \
send-keys -t :3 watch-tsc C-m \; \
new-window -n "Editor Webpack" \; \
send-keys -t :4 watch-editor-cowboy C-m \; \
new-window -n "Website" \; \
send-keys -t :5 watch-website C-m \; \
new-window -n "VSCode Common" \; \
send-keys -t :6 watch-utopia-vscode-common C-m \; \
new-window -n "VSCode Extension" \; \
send-keys -t :7 watch-utopia-vscode-extension C-m \; \
new-window -n "VSCode Pull Extension" \; \
send-keys -t :8 watch-vscode-build-extension-only C-m \; \
select-window -t :1 \;
'')
(pkgs.writeScriptBin "start-full" ''
#!/usr/bin/env bash
stop-dev
set -e
build-vscode-with-extension
install-editor
start-minimal
'')
] ++ vscodeDevScripts;
withCustomDevScripts = withServerRunScripts ++ (lib.optionals includeRunLocallySupport customDevScripts);
# TODO Come back to these when trying to use nix to build a docker container - https://stackoverflow.com/questions/58421505/how-do-i-apply-a-nix-shell-config-in-a-docker-image
releaseScripts = [
(pkgs.writeScriptBin "build-editor" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/editor
${node}/bin/npm --scripts-prepend-node-path=true install --unsafe-perm
${node}/bin/npm --scripts-prepend-node-path=true run production
'')
# CRA for whatever reason will automatically fail on CI for any warnings, so we need to prefix with `CI=false`. Urgh. https://github.com/facebook/create-react-app/issues/3657
(pkgs.writeScriptBin "build-website" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/website-next
${node}/bin/npm --scripts-prepend-node-path=true install
CI=false ${node}/bin/npm --scripts-prepend-node-path=true run export
'')
(pkgs.writeScriptBin "build-server" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/server
${cabal}/bin/cabal new-build utopia-web
cp --verbose $(${pkgs.haskellPackages.cabal-plan}/bin/cabal-plan list-bin exe:utopia-web) .
'')
(pkgs.writeScriptBin "build-all" ''
#!/usr/bin/env bash
set -e
build-editor
build-website
build-server
'')
];
scripts = withCustomDevScripts; # ++ (if needsRelease then releaseScripts else []);
linuxOnlyPackages = lib.optionals stdenv.isLinux [ pkgs.xvfb_run pkgs.x11 pkgs.xorg.libxkbfile ];
macOSOnlyPackages = lib.optionals stdenv.isDarwin (with pkgs.darwin.apple_sdk.frameworks; [
Cocoa
CoreServices
]);
baseServerPackages = [
cabal
ghc
pkgs.cabal2nix
pkgs.haskellPackages.stylish-haskell
pkgs.haskellPackages.hpack
pkgs.postgresql
];
serverRunPackages = [
];
releasePackages = [
pkgs.heroku
];
pythonAndPackages = pkgs.python37.withPackages(ps: with ps; [ pyusb tkinter pkgconfig ]);
basePackages = [ node pkgs.yarn pkgs.libsecret pythonAndPackages pkgs.pkg-config pkgs.tmux pkgs.git pkgs.wget ] ++ linuxOnlyPackages ++ macOSOnlyPackages;
withServerBasePackages = basePackages ++ (lib.optionals includeServerBuildSupport baseServerPackages);
withServerRunPackages = withServerBasePackages ++ (lib.optionals includeRunLocallySupport serverRunPackages);
withReleasePackages = withServerRunPackages ++ (lib.optionals includeReleaseSupport releasePackages);
packagesToUse = withReleasePackages;
in pkgs.mkShell {
buildInputs = [
(pkgs.stdenv.mkDerivation {
name = "scripts";
phases = "installPhase";
installPhase = ''
mkdir -p $out/bin
'' + (builtins.concatStringsSep "" (builtins.map (script: ''
for f in $(ls -d ${script}/bin/*); do ln -s $f $out/bin; done
'') scripts));
})
] ++ packagesToUse;
# Makes the electron runner use this executable instead.
ELECTRON_OVERRIDE_DIST_PATH = if stdenv.isLinux then "${pkgs.electron_6}/bin" else null;
}