-
Notifications
You must be signed in to change notification settings - Fork 2
/
shell.nix
184 lines (148 loc) · 4.75 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
{ pkgs ? import ./nix/pinned.nix {} }:
let
easy-ps = import ./nix/easy-ps.nix { inherit pkgs; };
purs-packages = import ./purs-packages.nix { inherit pkgs; };
purs-project = import ./nix/purs-project.nix { inherit pkgs; };
build-purs = pkgs.writeShellScriptBin "build-purs" ''
#!/usr/bin/env bash
purs compile ${toString purs-project.sourceGlobs} "src/**/*.purs" "test/**/*.purs"
'';
build = pkgs.writeShellScriptBin "build" ''
#!/usr/bin/env bash
set -e
echo "Installing JS Dependencies"
yarn
echo "Compiling"
#build-purs
#spago build
#echo "Bundling"
#pulp browserify --skip-compile -t dist/bundle.js --src-path output
#browserify
# 0.15
spago bundle-app --main Main --to dist/bundle.js
'';
build-suggestions = pkgs.writeShellScriptBin "build-suggestions" ''
#!/usr/bin/env bash
set -e
echo "Installing JS Dependencies"
yarn
rm -rf ./output
echo "Compiling"
#build-purs
#spago build
#echo "Bundling"
#pulp browserify --skip-compile -t dist/bundle.js --src-path output
#browserify
# 0.15
spago bundle-app --main Main --to dist/bundle.js --purs-args "--json-errors" | jq -r '.warnings | map(select(.errorCode | test("UnusedDctorExplicitImport|UnusedDctorImport|UnusedDeclaration|UnusedExplicitImport|UnusedImport|UnusedName|UnusedTypeVar"))) | map(select(.filename | test("^.spago") | not)) | map("[\(.filename)::\(.position.startLine)] \(.message)\n \(.suggestion)") | join("\n----------\n")'
'';
build-css = pkgs.writeShellScriptBin "build-css" ''
#!/usr/bin/env bash
set -e
yarn css
'';
serve = pkgs.writeShellScriptBin "serve" ''
#!/usr/bin/env bash
set -e
yarn server
'';
build-watch = pkgs.writeShellScriptBin "build-watch" ''
#!/usr/bin/env bash
set -e
echo "Build watch"
spago build -w --then browserify
'';
build-zephyr = pkgs.writeShellScriptBin "build-zephyr" ''
#!/usr/bin/env bash
set -e
spago build --purs-args '--codegen corefn,js'
zephyr -f Main.main
browserify-zephyr
'';
browserify = pkgs.writeShellScriptBin "browserify" ''
#!/usr/bin/env bash
set -e
pulp browserify --skip-compile -t dist/bundle.js --src-path output
'';
browserify-zephyr = pkgs.writeShellScriptBin "browserify-zephyr" ''
#!/usr/bin/env bash
set -e
pulp browserify --skip-compile -t dist/bundle.js -o dce-output
#purs bundle -o dist/bundle.js -m Main dce-output/**/*.js
'';
minify-bundle = pkgs.writeShellScriptBin "minify-bundle" ''
#!/usr/bin/env bash
set -e
minify dist/bundle.js > dist/bundle.min.js
'';
repl = pkgs.writeShellScriptBin "repl" ''
#!/usr/bin/env bash
spago repl
'';
test-ps = pkgs.writeShellScriptBin "test-ps" ''
#!/usr/bin/env bash
set -e
echo "Compiling"
yarn
#spago build
#build-purs
echo "Testing"
spago -v -x test.dhall test --main Test.Main
# spago -x test.dhall bundle-app --main Test.Main --to dist/test-bundle.js --platform node
# pulp browserify --skip-compile -t dist/bundle.js --src-path output
# pulp test --src-path output --test-path output
#NODE_PATH=output node -e "require('Test.Main').main();"
'';
# TODO: Remove this when nixpkgs is updated to newer version (23.05
# has nodejs 20.2.1 and we need >= 20.3.1 for crypto to work)
#nodejs_20_3_1 = pkgs.callPackage ./nix/nodejs-v20.nix {};
in
pkgs.mkShell {
buildInputs = [
easy-ps.purs-0_15_7
easy-ps.psc-package
easy-ps.dhall-json-simple
easy-ps.zephyr
browserify
browserify-zephyr
build-css
build-purs
build-suggestions
build-watch
build-zephyr
build
pkgs.ijq
pkgs.jq
minify-bundle
#pkgs.closurecompiler
pkgs.esbuild
pkgs.minify
pkgs.nodejs
#pkgs.nodePackages.purescript-language-server
#pkgs.python # needed for msgpack etc
#nodejs_20_3_1
repl
serve
pkgs.pulp
pkgs.spago
pkgs.yarn
test-ps
];
shellHook = ''
export PURS_IDE_SOURCES='${toString purs-project.unquotedSourceGlobs}'
'';
}
## how to build the project with nix dependencies:
#
# 1. start a nix shell (e.g. `nix-shell -j 20`, this uses 20 jobs to fetch deps)
# 2. run `yarn` to install npm deps
# 3a. run `build-purs` to build using nix store dependencies, and make sure to update your purescript ide tooling as necesssary
# 3b. or simply use `psc-package` as you might want to anyway
#
# note that the purescript compiler uses filepaths and timestamps, so using the above two commands
# interchangeably will lead to constant rebuilding of the entire project.
#
## how to update purs-packages.nix
#
# 1. run `nix/generate-packages-json.nix` to generate packages.json
# 2. run `nix/generate-purs-packages.nix` to generate purs-packages.nix