-
Notifications
You must be signed in to change notification settings - Fork 172
/
Copy pathshell.nix
826 lines (793 loc) · 28.8 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
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
{
compiler ? "ghc902",
includeServerBuildSupport ? true,
includeEditorBuildSupport ? true,
includeRunLocallySupport ? true,
includeReleaseSupport ? false,
includeDatabaseSupport ? true
}:
let
release = (import ./release.nix {});
pkgs = release.pkgs;
recentPkgs = release.recentPkgs;
lib = pkgs.lib;
node = pkgs.nodejs-18_x;
postgres = pkgs.postgresql_13;
stdenv = pkgs.stdenv;
pnpm = node.pkgs.pnpm;
yarn = pkgs.yarn.override { nodejs = node; };
nodePackages = [
node
pnpm
yarn
];
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
magic
]);
baseEditorScripts = [
(pkgs.writeScriptBin "install-utopia-api" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/utopia-api
${pnpm}/bin/pnpm install
${pnpm}/bin/pnpm run build
'')
(pkgs.writeScriptBin "install-eslint-config-utopia" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/eslint-config-utopia
${pnpm}/bin/pnpm install
'')
(pkgs.writeScriptBin "build-vscode-common" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)
${pnpm}/bin/pnpm install
update-vscode-build-extension
'')
(pkgs.writeScriptBin "install-editor" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)
${pnpm}/bin/pnpm install
install-utopia-api
install-eslint-config-utopia
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/editor
${pnpm}/bin/pnpm install
'')
(pkgs.writeScriptBin "install-editor-ci" ''
#!/usr/bin/env bash
set -e
install-utopia-api
install-eslint-config-utopia
build-utopia-vscode-common
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/editor
${pnpm}/bin/pnpm install
'')
(pkgs.writeScriptBin "install-website" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/website-next
${pnpm}/bin/pnpm install
'')
(pkgs.writeScriptBin "install-website-editor-ci" ''
#!/usr/bin/env bash
set -e
install-editor-ci
install-website
'')
(pkgs.writeScriptBin "test-editor" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/editor
${pnpm}/bin/pnpm test
'')
(pkgs.writeScriptBin "test-editor-watch" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/editor
${pnpm}/bin/pnpm test-watch
'')
(pkgs.writeScriptBin "test-utopia-api" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/utopia-api
${pnpm}/bin/pnpm test
'')
(pkgs.writeScriptBin "test-website" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/website-next
# ${pnpm}/bin/pnpm 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
${pnpm}/bin/pnpm run check
'')
(pkgs.writeScriptBin "check-editor-ci" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/editor
${pnpm}/bin/pnpm run check-ci
'')
(pkgs.writeScriptBin "check-editor-code" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/editor
${pnpm}/bin/pnpm run check-code
'')
(pkgs.writeScriptBin "check-editor-jest" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/editor
${pnpm}/bin/pnpm run test-ci
'')
(pkgs.writeScriptBin "check-editor-karma" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/editor
${pnpm}/bin/pnpm run test-browser
'')
(pkgs.writeScriptBin "check-editor-karma-hydrogen" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/editor
${pnpm}/bin/pnpm run test-browser-hydrogen
'')
(pkgs.writeScriptBin "check-editor-karma-shard-1" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/editor
${pnpm}/bin/pnpm run test-browser-shard-1
'')
(pkgs.writeScriptBin "check-editor-karma-shard-2" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/editor
${pnpm}/bin/pnpm run test-browser-shard-2
'')
(pkgs.writeScriptBin "test-editor-browser" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/editor
${pnpm}/bin/pnpm run test-browser
'')
(pkgs.writeScriptBin "test-editor-browser-debug" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/editor
${pnpm}/bin/pnpm run test-browser-debug
'')
(pkgs.writeScriptBin "check-editor-all-ci" ''
#!/usr/bin/env bash
set -e
install-editor-ci
install-website
check-editor-ci
test-website
'')
(pkgs.writeScriptBin "check-editor-code-ci" ''
#!/usr/bin/env bash
set -e
install-editor-ci
install-website
check-editor-code
test-website
'')
(pkgs.writeScriptBin "check-editor-jest-ci" ''
#!/usr/bin/env bash
set -e
install-editor-ci
install-website
check-editor-jest
'')
(pkgs.writeScriptBin "check-editor-karma-ci-hydrogen" ''
#!/usr/bin/env bash
set -e
install-editor-ci
install-website
check-editor-karma-hydrogen
'')
(pkgs.writeScriptBin "check-editor-karma-ci-shard-1" ''
#!/usr/bin/env bash
set -e
install-editor-ci
install-website
check-editor-karma-shard-1
'')
(pkgs.writeScriptBin "check-editor-karma-ci-shard-2" ''
#!/usr/bin/env bash
set -e
install-editor-ci
install-website
check-editor-karma-shard-2
'')
(pkgs.writeScriptBin "build-editor-staging-ci" ''
#!/usr/bin/env bash
set -e
install-editor-ci
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/website-next
${pnpm}/bin/pnpm install
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/editor
${pnpm}/bin/pnpm run staging-print-json
'')
(pkgs.writeScriptBin "build-editor-branches-ci" ''
#!/usr/bin/env bash
set -e
install-editor-ci
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/website-next
${pnpm}/bin/pnpm install
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/editor
${pnpm}/bin/pnpm run branches-print-json
'')
(pkgs.writeScriptBin "build-utopia-vscode-common" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/utopia-vscode-common
${pnpm}/bin/pnpm install
${pnpm}/bin/pnpm run build
'')
(pkgs.writeScriptBin "build-utopia-vscode-common-production" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/utopia-vscode-common
${pnpm}/bin/pnpm install
${pnpm}/bin/pnpm run production
'')
(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
${pnpm}/bin/pnpm install
${pnpm}/bin/pnpm run build
'')
(pkgs.writeScriptBin "build-utopia-vscode-extension-production" ''
#!/usr/bin/env bash
set -e
build-utopia-vscode-common-production
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/utopia-vscode-extension
${pnpm}/bin/pnpm install
${pnpm}/bin/pnpm run production
'')
(pkgs.writeScriptBin "update-vscode-build-extension" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/vscode-build
nix-shell --run update-vscode-build-extension-inner
'')
(pkgs.writeScriptBin "build-vscode" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/vscode-build
nix-shell --run build-vscode-inner
'')
(pkgs.writeScriptBin "build-vscode-with-extension" ''
#!/usr/bin/env bash
set -e
build-utopia-vscode-extension
build-vscode
'')
(pkgs.writeScriptBin "pull-extension" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/vscode-build
nix-shell --run pull-extension-inner
'')
(pkgs.writeScriptBin "check-github-token" ''
#!/usr/bin/env bash
set -e
GITHUB_TOKEN_STATUS=$(curl -s -o /dev/null -w "%{http_code}" --request GET --url "https://api.github.com/octocat" --header "Authorization: Bearer $GITHUB_TOKEN" --header "X-GitHub-Api-Version: 2022-11-28")
if [ "$GITHUB_TOKEN_STATUS" = "200" ]
then
echo "A valid GITHUB_TOKEN was found"
else
printf "A valid GITHUB_TOKEN is required when running the full Utopia build.\nYou may be missing one, or it may have expired.\nPlease see the readme for instructions.\n"
exit 1
fi
'')
(pkgs.writeScriptBin "check-tool-versions" ''
#! /usr/bin/env nix-shell
#! nix-shell -p "haskellPackages.ghcWithPackages (pkgs: with pkgs; [async process])" -i runhaskell
import Control.Concurrent.Async
import Control.Monad
import Data.Foldable
import Data.List
import Data.Monoid
import System.Exit
import System.Process
expectedToolVersions :: [(String, [String], [String])]
expectedToolVersions =
[ ("node", ["--version"], ["v18.12.1"])
, ("pnpm", ["--version"], ["7.14.2"])
, ("yarn", ["--version"], ["1.22.19"])
, ("ghc", ["--version"], ["The Glorious Glasgow Haskell Compilation System, version 9.0.2"])
, ("cabal", ["--version"], ["cabal-install version 3.8.1.0", "compiled using version 3.8.1.0 of the Cabal library "])
]
checkVersion :: (String, [String], [String]) -> IO All
checkVersion (executable, arguments, expectedOutput) = do
let commandToRun = unwords (executable : arguments)
output <- readProcess "nix-shell" ["--run", commandToRun] ""
let actualOutput = lines output
let correctVersion = actualOutput == expectedOutput
unless correctVersion $ do
putStrLn ("Error when checking the version of " <> executable)
putStrLn "Expected:"
traverse_ putStrLn expectedOutput
putStrLn "Received:"
traverse_ putStrLn actualOutput
pure $ All correctVersion
main :: IO ()
main = do
results <- mapConcurrently checkVersion expectedToolVersions
let result = getAll $ mconcat results
when result $ putStrLn "All tools are the correct version."
if result then exitSuccess else exitFailure
'')
(pkgs.writeScriptBin "test-remix-bff" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/utopia-remix
${pnpm}/bin/pnpm run test
'')
(pkgs.writeScriptBin "test-remix-bff-ci" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/utopia-remix
${pnpm}/bin/pnpm run test-ci
'')
];
withBaseEditorScripts = lib.optionals includeEditorBuildSupport baseEditorScripts;
puppeteerScripts = [
(pkgs.writeScriptBin "build-puppeteer-tests" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/puppeteer-tests
${pnpm}/bin/pnpm install --unsafe-perm
${pnpm}/bin/pnpm run build
'')
(pkgs.writeScriptBin "run-puppeteer-test" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/puppeteer-tests
${pnpm}/bin/pnpm install --unsafe-perm
${pnpm}/bin/pnpm run performance-test
'')
(pkgs.writeScriptBin "run-comments-test" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/puppeteer-tests
${pnpm}/bin/pnpm install --unsafe-perm
${pnpm}/bin/pnpm run comments-test
'')
(pkgs.writeScriptBin "run-collaboration-test" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/puppeteer-tests
${pnpm}/bin/pnpm install --unsafe-perm
${pnpm}/bin/pnpm run collaboration-test
'')
];
withPuppeteerScripts = withBaseEditorScripts ++ (lib.optionals stdenv.isLinux puppeteerScripts);
serverBaseScripts = [
(pkgs.writeScriptBin "rebuild-cabal" ''
#!/usr/bin/env bash
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/clientmodel/lib
${pkgs.haskellPackages.hpack}/bin/hpack
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,2024-01-16T13:02:28Z'
'')
(pkgs.writeScriptBin "test-server-inner" ''
#!/usr/bin/env bash
set -e
rebuild-cabal
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/server
nix-shell --run "${cabal}/bin/cabal build --disable-optimization --disable-profiling --disable-documentation --disable-library-coverage --disable-benchmarks utopia-web-test"
cp --verbose $(${pkgs.haskellPackages.cabal-plan}/bin/cabal-plan list-bin test:utopia-web-test) .
./utopia-web-test +RTS -N -RTS "$@"
'')
(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 = withPuppeteerScripts ++ (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
${pnpm}/bin/pnpm run watch-tsc
'')
(pkgs.writeScriptBin "watch-editor-cowboy" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/editor
RUN_COMPILER=true ${pnpm}/bin/pnpm run move-fast-and-break-things
'')
(pkgs.writeScriptBin "watch-editor-hmr" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/editor
RUN_COMPILER=true ${pnpm}/bin/pnpm run dev-fast
'')
(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 ${pnpm}/bin/pnpm 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 ${pnpm}/bin/pnpm 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 ${pnpm}/bin/pnpm 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
${pnpm}/bin/pnpm install
BROWSER=none ${pnpm}/bin/pnpm run dev
'')
];
withEditorRunScripts = withServerBaseScripts ++ (lib.optionals includeRunLocallySupport editorRunScripts);
databaseRunScripts = [
(pkgs.writeScriptBin "create-db" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)
PGLOCK_DIR="`pwd`/.pglock/"
echo "Ignore previous line about database not existing." > pglog.txt
${postgres}/bin/createdb -e -h "$PGLOCK_DIR" utopia
'')
(pkgs.writeScriptBin "start-postgres-background" ''
#!/usr/bin/env bash
stop-postgres
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)
PGLOCK_DIR="`pwd`/.pglock/"
[ ! -d "utopia-db" ] && ${postgres}/bin/initdb -D utopia-db
mkdir -p $PGLOCK_DIR
${postgres}/bin/pg_ctl -D utopia-db -l pglog.txt -o "--unix_socket_directories='$PGLOCK_DIR' -c log_statement=none" start
${postgres}/bin/psql -o /dev/null -h "$PGLOCK_DIR" -d utopia -tc "SELECT 1 FROM pg_database WHERE datname = 'utopia'" || create-db
'')
(pkgs.writeScriptBin "start-postgres" ''
#!/usr/bin/env bash
stop-postgres
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)
start-postgres-background
tail -f pglog.txt
'')
(pkgs.writeScriptBin "stop-postgres" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)
PGLOCK_DIR="`pwd`/.pglock/"
mkdir -p $PGLOCK_DIR
${postgres}/bin/pg_ctl -D utopia-db stop
'')
(pkgs.writeScriptBin "run-psql" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)
PGLOCK_DIR="`pwd`/.pglock/"
mkdir -p $PGLOCK_DIR
${postgres}/bin/psql -h "$PGLOCK_DIR" -d utopia "$@"
'')
];
withDatabaseRunScripts = withEditorRunScripts ++ (lib.optionals (includeDatabaseSupport || includeRunLocallySupport) databaseRunScripts);
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
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/clientmodel/lib/src
find . -name '*.hs' | xargs ${pkgs.haskellPackages.stylish-haskell}/bin/stylish-haskell -i
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/clientmodel/lib/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
pkill utopia-web || true
nix-shell --run "${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)/
${pkgs.nodePackages.nodemon}/bin/nodemon --delay 200ms -e hs,yaml --watch server/src --watch server/package.yaml --watch clientmodel/lib/src --watch clientmodel/lib/package.yaml --exec run-server-inner
'')
(pkgs.writeScriptBin "watch-remix" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/utopia-remix
${pnpm}/bin/pnpm install
${pnpm}/bin/pnpm exec prisma generate > /dev/null
PNPM=${pnpm}/bin/pnpm PORT=8000 DATABASE_URL="postgres://$(whoami):postgres@localhost:5432/utopia" LOCAL=true ./run-remix.sh
'')
(pkgs.writeScriptBin "watch-fga" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/utopia-remix
./fga-run.sh
'')
(pkgs.writeScriptBin "fga-create-store" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/utopia-remix
./fga-create-store.sh
'')
];
withServerRunScripts = withDatabaseRunScripts ++ (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
nix-shell --run update-vscode-patch-inner
'')
(pkgs.writeScriptBin "watch-utopia-vscode-common" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/utopia-vscode-common
${pnpm}/bin/pnpm install
${pnpm}/bin/pnpm 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
${pnpm}/bin/pnpm install
${pnpm}/bin/pnpm run watch-dev
'')
(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
pkill utopia-web
stop-postgres
tmux kill-session -t utopia-dev
'')
(pkgs.writeScriptBin "start" ''
#!/usr/bin/env bash
start-minimal
'')
(pkgs.writeScriptBin "start-minimal" ''
#!/usr/bin/env bash
stop-dev
set -e
check-tool-versions
install-editor
tmux new-session -s utopia-dev \; \
set -g default-terminal "xterm-256color" \; \
set-option -g mouse on \; \
new-window -n "Scratchpad" \; \
new-window -n "Server" \; \
send-keys -t :2 watch-server C-m \; \
new-window -n "Remix" \; \
send-keys -t :3 watch-remix C-m \; \
new-window -n "Editor TSC" \; \
send-keys -t :4 watch-tsc C-m \; \
new-window -n "Editor Vite" \; \
send-keys -t :5 watch-editor-hmr C-m \; \
new-window -n "Website" \; \
send-keys -t :6 watch-website C-m \; \
new-window -n "VSCode Common" \; \
send-keys -t :7 watch-utopia-vscode-common C-m \; \
new-window -n "VSCode Extension" \; \
send-keys -t :8 watch-utopia-vscode-extension C-m \; \
new-window -n "VSCode Pull Extension" \; \
send-keys -t :9 watch-vscode-build-extension-only C-m \; \
new-window -n "PostgreSQL" \; \
send-keys -t :10 start-postgres C-m \; \
new-window -n "FGA" \; \
send-keys -t :11 watch-fga C-m \; \
select-window -t :1 \;
'')
(pkgs.writeScriptBin "start-full" ''
#!/usr/bin/env bash
stop-dev
set -e
check-github-token
check-tool-versions
build-vscode-with-extension
build-vscode-common
start-minimal
'')
(pkgs.writeScriptBin "start-minimal-webpack" ''
#!/usr/bin/env bash
stop-dev
set -e
check-tool-versions
install-editor
tmux new-session -s utopia-dev \; \
set -g default-terminal "xterm-256color" \; \
set-option -g mouse on \; \
new-window -n "Scratchpad" \; \
new-window -n "Server" \; \
send-keys -t :2 watch-server C-m \; \
new-window -n "Remix" \; \
send-keys -t :3 watch-remix C-m \; \
new-window -n "Editor TSC" \; \
send-keys -t :4 watch-tsc C-m \; \
new-window -n "Editor Webpack" \; \
send-keys -t :5 watch-editor-cowboy C-m \; \
new-window -n "Website" \; \
send-keys -t :6 watch-website C-m \; \
new-window -n "VSCode Common" \; \
send-keys -t :7 watch-utopia-vscode-common C-m \; \
new-window -n "VSCode Extension" \; \
send-keys -t :8 watch-utopia-vscode-extension C-m \; \
new-window -n "VSCode Pull Extension" \; \
send-keys -t :9 watch-vscode-build-extension-only C-m \; \
new-window -n "PostgreSQL" \; \
send-keys -t :10 start-postgres C-m \; \
new-window -n "FGA" \; \
send-keys -t :11 watch-fga C-m \; \
select-window -t :1 \;
'')
(pkgs.writeScriptBin "start-full-webpack" ''
#!/usr/bin/env bash
stop-dev
set -e
check-tool-versions
build-vscode-with-extension
build-vscode-common
start-minimal-webpack
'')
] ++ vscodeDevScripts;
withCustomDevScripts = withServerRunScripts ++ (lib.optionals includeRunLocallySupport customDevScripts);
releaseScripts = [
(pkgs.writeScriptBin "prepare-build-editor" ''
#!/usr/bin/env bash
set -e
install-utopia-api
build-utopia-vscode-common
install-website
'')
(pkgs.writeScriptBin "build-editor-production" ''
#!/usr/bin/env bash
set -e
prepare-build-editor
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/editor
${pnpm}/bin/pnpm install --unsafe-perm
${pnpm}/bin/pnpm run production
'')
(pkgs.writeScriptBin "build-editor-staging" ''
#!/usr/bin/env bash
set -e
prepare-build-editor
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/editor
${pnpm}/bin/pnpm install --unsafe-perm
${pnpm}/bin/pnpm run staging
'')
# 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
${pnpm}/bin/pnpm install
CI=false ${pnpm}/bin/pnpm run export
'')
(pkgs.writeScriptBin "build-server" ''
#!/usr/bin/env bash
set -e
cabal-update
rebuild-cabal
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) .
'')
];
withReleaseScripts = withCustomDevScripts ++ (lib.optionals includeReleaseSupport releaseScripts);
scripts = withReleaseScripts;
linuxOnlyPackages = lib.optionals stdenv.isLinux [ pkgs.xvfb_run pkgs.xlibsWrapper 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
postgres
];
serverRunPackages = [
];
releasePackages = [
pkgs.heroku
];
pythonAndPackages = pkgs.python3.withPackages(ps: with ps; [ pyusb tkinter pkgconfig ]);
basePackages = [ node pkgs.libsecret pkgs.libkrb5 pythonAndPackages pkgs.pkg-config pkgs.tmux pkgs.git pkgs.wget ] ++ nodePackages ++ 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}/bin" else null;
# Required for webpack builds
NODE_OPENSSL_OPTION = "--openssl-legacy-provider";
# Required for node-gyp, apparently
npm_config_force_process_config = true;
# Make Prisma work.
PRISMA_SCHEMA_ENGINE_BINARY = if stdenv.isLinux then "${recentPkgs.prisma-engines}/bin/schema-engine" else null;
PRISMA_QUERY_ENGINE_BINARY = if stdenv.isLinux then "${recentPkgs.prisma-engines}/bin/query-engine" else null;
PRISMA_FMT_BINARY = if stdenv.isLinux then "${recentPkgs.prisma-engines}/bin/prisma-fmt" else null;
PRISMA_QUERY_ENGINE_LIBRARY = if stdenv.isLinux then "${recentPkgs.prisma-engines}/lib/libquery_engine.node" else null;
}