-
Notifications
You must be signed in to change notification settings - Fork 15
/
flake.nix
232 lines (200 loc) · 7.81 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
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
{
description = "homestar";
inputs = {
# we leverage unstable due to wasm-tools/wasm updates
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
};
};
outputs = {
self,
nixpkgs,
flake-compat,
flake-utils,
rust-overlay,
} @ inputs:
flake-utils.lib.eachDefaultSystem (
system: let
overlays = [(import rust-overlay)];
pkgs = import nixpkgs {inherit system overlays;};
rust-toolchain = (pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml).override {
extensions = ["cargo" "clippy" "rustfmt" "rust-src" "rust-std"];
targets = ["wasm32-unknown-unknown" "wasm32-wasi"];
};
nightly-rustfmt = pkgs.rust-bin.nightly.latest.rustfmt;
format-pkgs = with pkgs; [
nixpkgs-fmt
alejandra
];
cargo-installs = with pkgs; [
cargo-deny
cargo-expand
cargo-nextest
cargo-outdated
cargo-sort
cargo-udeps
cargo-watch
twiggy
wasm-tools
];
ci = pkgs.writeScriptBin "ci" ''
cargo fmt --check
cargo clippy
cargo build --release
nx-test
nx-test-0
'';
db = pkgs.writeScriptBin "db" ''
diesel setup
diesel migration run
'';
dbReset = pkgs.writeScriptBin "db-reset" ''
diesel database reset
diesel setup
diesel migration run
'';
doc = pkgs.writeScriptBin "doc" ''
cargo doc --no-deps --document-private-items --open
'';
compileWasm = pkgs.writeScriptBin "compile-wasm" ''
cargo build -p homestar-functions --target wasm32-unknown-unknown --release
'';
dockerBuild = arch:
pkgs.writeScriptBin "docker-${arch}" ''
docker buildx build --file docker/Dockerfile --platform=linux/${arch} -t homestar-runtime --progress=plain .
'';
xFunc = cmd:
pkgs.writeScriptBin "x-${cmd}" ''
cargo watch -c -x ${cmd}
'';
xFuncAll = cmd:
pkgs.writeScriptBin "x-${cmd}-all" ''
cargo watch -c -s "cargo ${cmd} --all-features"
'';
xFuncNoDefault = cmd:
pkgs.writeScriptBin "x-${cmd}-0" ''
cargo watch -c -s "cargo ${cmd} --no-default-features"
'';
xFuncPackage = cmd: crate:
pkgs.writeScriptBin "x-${cmd}-${crate}" ''
cargo watch -c -s "cargo ${cmd} -p homestar-${crate} --all-features"
'';
xFuncTest = pkgs.writeScriptBin "x-test" ''
cargo watch -c -s "cargo nextest run --nocapture && cargo test --doc"
'';
xFuncTestAll = pkgs.writeScriptBin "x-test-all" ''
cargo watch -c -s "cargo nextest run --all-features --nocapture \
&& cargo test --doc --all-features"
'';
xFuncTestNoDefault = pkgs.writeScriptBin "x-test-0" ''
cargo watch -c -s "cargo nextest run --no-default-features --nocapture \
&& cargo test --doc --no-default-features"
'';
xFuncTestPackage = crate:
pkgs.writeScriptBin "x-test-${crate}" ''
cargo watch -c -s "cargo nextest run -p homestar-${crate} --all-features \
&& cargo test --doc -p homestar-${crate} --all-features"
'';
nxTest = pkgs.writeScriptBin "nx-test" ''
cargo nextest run
cargo test --doc
'';
nxTestAll = pkgs.writeScriptBin "nx-test-all" ''
cargo nextest run --all-features --nocapture
cargo test --doc --all-features
'';
nxTestNoDefault = pkgs.writeScriptBin "nx-test-0" ''
cargo nextest run --no-default-features --nocapture
cargo test --doc --no-default-features
'';
wasmTest = pkgs.writeScriptBin "wasm-ex-test" ''
cargo build -p homestar-functions --features example-test --target wasm32-unknown-unknown --release
cp target/wasm32-unknown-unknown/release/homestar_functions.wasm homestar-wasm/fixtures/example_test.wasm
wasm-tools component new homestar-wasm/fixtures/example_test.wasm -o homestar-wasm/fixtures/example_test_component.wasm
'';
wasmAdd = pkgs.writeScriptBin "wasm-ex-add" ''
cargo build -p homestar-functions --features example-add --target wasm32-unknown-unknown --release
cp target/wasm32-unknown-unknown/release/homestar_functions.wasm homestar-wasm/fixtures/example_add.wasm
wasm-tools component new homestar-wasm/fixtures/example_add.wasm -o homestar-wasm/fixtures/example_add_component.wasm
wasm-tools print homestar-wasm/fixtures/example_add.wasm -o homestar-wasm/fixtures/example_add.wat
wasm-tools print homestar-wasm/fixtures/example_add_component.wasm -o homestar-wasm/fixtures/example_add_component.wat
'';
scripts = [
ci
db
dbReset
doc
compileWasm
(builtins.map (arch: dockerBuild arch) ["amd64" "arm64"])
(builtins.map (cmd: xFunc cmd) ["build" "check" "run" "clippy"])
(builtins.map (cmd: xFuncAll cmd) ["build" "check" "run" "clippy"])
(builtins.map (cmd: xFuncNoDefault cmd) ["build" "check" "run" "clippy"])
(builtins.map (cmd: xFuncPackage cmd "core") ["build" "check" "run" "clippy"])
(builtins.map (cmd: xFuncPackage cmd "wasm") ["build" "check" "run" "clippy"])
(builtins.map (cmd: xFuncPackage cmd "runtime") ["build" "check" "run" "clippy"])
xFuncTest
xFuncTestAll
xFuncTestNoDefault
(builtins.map (crate: xFuncTestPackage crate) ["core" "wasm" "guest-wasm" "runtime"])
nxTest
nxTestAll
nxTestNoDefault
wasmTest
wasmAdd
];
in rec
{
devShells.default = pkgs.mkShell {
name = "homestar";
nativeBuildInputs = with pkgs;
[
# The ordering of these two items is important. For nightly rustfmt to be used instead of
# the rustfmt provided by `rust-toolchain`, it must appear first in the list. This is
# because native build inputs are added to $PATH in the order they're listed here.
nightly-rustfmt
rust-toolchain
rust-analyzer
pkg-config
pre-commit
diesel-cli
direnv
self.packages.${system}.irust
]
++ format-pkgs
++ cargo-installs
++ scripts
++ lib.optionals stdenv.isDarwin [
darwin.apple_sdk.frameworks.Security
darwin.apple_sdk.frameworks.CoreFoundation
darwin.apple_sdk.frameworks.Foundation
];
NIX_PATH = "nixpkgs=" + pkgs.path;
RUST_BACKTRACE = 1;
shellHook = ''
[ -e .git/hooks/pre-commit ] || pre-commit install --install-hooks && pre-commit install --hook-type commit-msg
'';
};
packages.irust = pkgs.rustPlatform.buildRustPackage rec {
pname = "irust";
version = "1.70.0";
src = pkgs.fetchFromGitHub {
owner = "sigmaSd";
repo = "IRust";
rev = "v${version}";
sha256 = "sha256-chZKesbmvGHXwhnJRZbXyX7B8OwJL9dJh0O1Axz/n2E=";
};
doCheck = false;
cargoSha256 = "sha256-FmsD3ajMqpPrTkXCX2anC+cmm0a2xuP+3FHqzj56Ma4=";
};
formatter = pkgs.alejandra;
}
);
}