-
Notifications
You must be signed in to change notification settings - Fork 1
/
flake.nix
190 lines (156 loc) · 7.35 KB
/
flake.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
{
inputs = {
naersk = {
url = "github:nix-community/naersk";
inputs.nixpkgs.follows = "nixpkgs";
};
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
nix-filter.url = "github:numtide/nix-filter";
};
outputs = { nixpkgs, flake-utils, rust-overlay, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
wasm-bindgen-cli-update = final: prev: {
wasm-bindgen-cli = prev.wasm-bindgen-cli.override {
version = "0.2.92";
hash = "sha256-1VwY8vQy7soKEgbki4LD+v259751kKxSxmo/gqE6yV0=";
cargoHash = "sha256-aACJ+lYNEU8FFBs158G1/JG8sc6Rq080PeKCMnwdpH0=";
};
};
overlays = [ (import rust-overlay) (wasm-bindgen-cli-update) ];
pkgs = import nixpkgs { inherit system overlays; };
toolchain = pkgs.rust-bin.nightly.latest.complete.override {
targets = [ "wasm32-unknown-unknown" ];
};
in rec {
packages = {
build-site = pkgs.writeShellScriptBin "site" ''
set -x
set -o nounset
set -o errexit
set -o pipefail
rm -rf site/*
cp -r assets/* site/
cp -r game/assets site/assets
cargo build --target wasm32-unknown-unknown --no-default-features --release -p app --lib --features app/hydrate,app/wasm
${pkgs.wasm-bindgen-cli}/bin/wasm-bindgen ./target/wasm32-unknown-unknown/release/app.wasm --no-typescript --remove-name-section --remove-producers-section --out-name index --target web --out-dir ./site/pkg
cargo build --target wasm32-unknown-unknown --no-default-features --release -p app --bin worker --features app/ssr,app/wasm
${pkgs.wasm-bindgen-cli}/bin/wasm-bindgen ./target/wasm32-unknown-unknown/release/worker.wasm --no-typescript --remove-name-section --remove-producers-section --out-name index --target bundler --out-dir ./site
cargo build --target wasm32-unknown-unknown --no-default-features --release -p game --bin game --features game/wasm
${pkgs.wasm-bindgen-cli}/bin/wasm-bindgen ./target/wasm32-unknown-unknown/release/game.wasm --no-typescript --remove-name-section --remove-producers-section --out-name game --target web --out-dir ./site/pkg
'';
deploy-site = pkgs.writeShellScriptBin "deploy-site" ''
set -x
set -o nounset
set -o errexit
set -o pipefail
${packages.build-site}/bin/build-site
wrangler deploy site/_worker.js
wrangler pages deploy --project-name deep-space-derby site
'';
dev-clean = pkgs.writeShellScriptBin "dev-clean" ''
set -x
set -o nounset
set -o errexit
set -o pipefail
rm -rf site/*
ln -s ../game/assets site/assets
'';
dev-copy-assets = pkgs.writeShellScriptBin "dev-copy-assets" ''
set -x
set -o nounset
set -o errexit
set -o pipefail
cp -r assets/* site/
'';
dev-build-client = pkgs.writeShellScriptBin "dev-build-client" ''
set -o nounset
set -o errexit
set -o pipefail
CLIENT_TARGET="./target/wasm32-unknown-unknown/debug/app.wasm"
cargo build --target wasm32-unknown-unknown --no-default-features -p app --lib --features app/hydrate,app/wasm
${pkgs.wasm-bindgen-cli}/bin/wasm-bindgen $CLIENT_TARGET --no-typescript --out-name index --target web --out-dir ./site/pkg
echo "############### FINISHED BUILDING CLIENT ###############"
'';
dev-build-game = pkgs.writeShellScriptBin "dev-build-game" ''
set -o nounset
set -o errexit
set -o pipefail
GAME_TARGET="./target/wasm32-unknown-unknown/debug/game.wasm"
cargo build --target wasm32-unknown-unknown --no-default-features -p game --bin game --features game/wasm
${pkgs.wasm-bindgen-cli}/bin/wasm-bindgen $GAME_TARGET --no-typescript --out-name game --target web --out-dir ./site/pkg
echo "############### FINISHED BUILDING GAME ###############"
'';
dev-run-native-server =
pkgs.writeShellScriptBin "dev-run-native-server" ''
set -o nounset
set -o errexit
set -o pipefail
RUST_LOG=info cargo run --package app --bin server
'';
dev-run-wrangler-server =
pkgs.writeShellScriptBin "dev-run-wrangler-server" ''
set -o nounset
set -o errexit
set -o pipefail
cargo build --target wasm32-unknown-unknown --no-default-features -p app --bin worker --features app/ssr,app/wasm
${pkgs.wasm-bindgen-cli}/bin/wasm-bindgen ./target/wasm32-unknown-unknown/debug/worker.wasm --keep-debug --no-typescript --out-name index --target bundler --out-dir ./site
wrangler pages dev site --ip 0.0.0.0 --local-protocol https --compatibility-date=2023-10-30
'';
dev-mprocs-config = pkgs.writeText "mprocs.dev.yaml" ''
procs:
clean: ${packages.dev-clean}/bin/dev-clean
assets: find assets | entr -r ${packages.dev-copy-assets}/bin/dev-copy-assets
client: find {app,shared} | entr -n ${packages.dev-build-client}/bin/dev-build-client
game: find {game,shared} | entr -n ${packages.dev-build-game}/bin/dev-build-game
server: find {app,shared} | entr -rn ${packages.dev-run-native-server}/bin/dev-run-native-server
'';
dev-wrangler-mprocs-config =
pkgs.writeText "mprocs.wrangler.dev.yaml" ''
procs:
clean: ${packages.dev-clean}/bin/dev-clean
assets: find assets | entr -r ${packages.dev-copy-assets}/bin/dev-copy-assets
client: find {app,shared} | entr -n ${packages.dev-build-client}/bin/dev-build-client
game: find {game,shared} | entr -n ${packages.dev-build-game}/bin/dev-build-game
server: find {app,shared} | entr -rn ${packages.dev-run-wrangler-server}/bin/dev-run-wrangler-server
'';
dev = pkgs.writeShellScriptBin "dev" ''
${pkgs.mprocs}/bin/mprocs --config ${packages.dev-mprocs-config}
'';
dev-wrangler = pkgs.writeShellScriptBin "dev-wrangler" ''
${pkgs.mprocs}/bin/mprocs --config ${packages.dev-wrangler-mprocs-config}
'';
};
devShell = with pkgs;
with packages;
mkShell {
buildInputs = [
toolchain
iconv
darwin.apple_sdk.frameworks.AppKit
nodejs
wasm-bindgen-cli
entr
cargo-watch
cargo-expand
cargo-leptos
leptosfmt
twiggy
mprocs
dev-clean
dev-copy-assets
dev-build-client
dev-build-game
dev-run-native-server
dev-run-wrangler-server
dev
dev-wrangler
binaryen
];
RUST_SRC_PATH = "${toolchain}/lib/rustlib/src/rust/library";
};
});
}