-
Notifications
You must be signed in to change notification settings - Fork 7
/
flake.nix
342 lines (294 loc) · 10.2 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
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
rec {
description = "nemo, a datalog-based rule engine for fast and scalable analytic data processing in memory";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
rust-overlay.url = "github:oxalica/rust-overlay";
rust-overlay.inputs = {
nixpkgs.follows = "nixpkgs";
};
utils.url = "github:gytis-ivaskevicius/flake-utils-plus";
};
outputs =
inputs@{
self,
utils,
rust-overlay,
...
}:
utils.lib.mkFlake {
inherit self inputs;
channels.nixpkgs.overlaysBuilder = channels: [
rust-overlay.overlays.default
];
overlays.default =
final: prev:
let
pkgs = self.packages."${final.system}";
lib = self.channels.nixpkgs."${final.system}";
in
{
inherit (pkgs) nemo nemo-python nemo-wasm;
nodePackages = lib.makeExtensible (lib.extends pkgs.nodePackages prev.nodePackages);
};
outputsBuilder =
channels:
let
pkgs = channels.nixpkgs;
toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
platform = pkgs.makeRustPlatform {
cargo = toolchain;
rustc = toolchain;
};
defaultBuildInputs =
[
pkgs.openssl
pkgs.openssl.dev
]
++ pkgs.lib.optionals pkgs.stdenv.isDarwin [
pkgs.darwin.apple_sdk.frameworks.Security
pkgs.darwin.apple_sdk.frameworks.SystemConfiguration
];
defaultNativeBuildInputs = [
toolchain
pkgs.pkg-config
];
in
rec {
packages =
let
cargoMeta = (builtins.fromTOML (builtins.readFile ./Cargo.toml)).workspace.package;
inherit (cargoMeta) version;
meta = {
inherit description;
inherit (cargoMeta) homepage;
license = [
pkgs.lib.licenses.asl20
pkgs.lib.licenses.mit
];
};
buildWasm =
target:
{
pname,
src,
version,
meta,
...
}@args:
pkgs.stdenv.mkDerivation rec {
inherit (args)
version
meta
pname
src
;
cargoDeps = platform.importCargoLock { lockFile = ./Cargo.lock; };
nativeBuildInputs =
defaultNativeBuildInputs
++ (with platform; [
cargoSetupHook
pkgs.wasm-pack
pkgs.nodejs
pkgs.wasm-bindgen-cli
]);
buildInputs = defaultBuildInputs ++ [ pkgs.nodejs ];
buildPhase = ''
runHook preBuild
mkdir -p $out/lib/node_modules/nemo-wasm
mkdir .cache
mkdir target
export CARGO_HOME=$TMPDIR/.cargo
export CARGO_TARGET_DIR=$TMPDIR/target
export XDG_CACHE_HOME=$TMPDIR/.cache
cd $src
HOME=$TMPDIR wasm-pack build --target ${target} --weak-refs --mode=no-install --out-dir=$out/lib/node_modules/${pname} nemo-wasm
runHook postBuild
'';
};
in
rec {
nemo = platform.buildRustPackage {
pname = "nemo";
src = ./.;
meta = meta // {
mainProgram = "nmo";
};
inherit version;
cargoLock.lockFile = ./Cargo.lock;
buildInputs = defaultBuildInputs;
nativeBuildInputs =
defaultNativeBuildInputs
++ (with platform; [
cargoBuildHook
cargoCheckHook
]);
buildAndTestSubdir = "nemo-cli";
};
nemo-python = pkgs.python3Packages.buildPythonPackage {
pname = "nemo-python";
src = ./.;
inherit version meta;
cargoDeps = platform.importCargoLock { lockFile = ./Cargo.lock; };
buildInputs = defaultBuildInputs;
nativeBuildInputs =
defaultNativeBuildInputs
++ (with platform; [
cargoSetupHook
maturinBuildHook
]);
buildAndTestSubdir = "nemo-python";
checkPhase = ''
PYTHONPATH=''${PYTHONPATH:+''${PYTHONPATH}:}out python3 -m unittest discover -s nemo-python/tests -v
'';
};
nemo-wasm-node = buildWasm "nodejs" {
pname = "nemo-wasm";
src = ./.;
inherit version meta;
};
nemo-wasm-bundler = buildWasm "bundler" {
pname = "nemo-wasm";
src = ./.;
inherit version meta;
};
nemo-wasm = nemo-wasm-bundler;
python3 = pkgs.python3.withPackages (ps: [ nemo-python ]);
python = python3;
nodejs = pkgs.writeShellScriptBin "node" ''
NODE_PATH=${nemo-wasm-node}/lib/node_modules''${NODE_PATH:+":$NODE_PATH"} ${pkgs.nodejs}/bin/node $@
'';
default = nemo;
};
apps.ci-checks = utils.lib.mkApp {
drv = pkgs.writeShellApplication {
name = "nemo-run-ci-checks";
runtimeInputs = pkgs.lib.concatLists [
defaultBuildInputs
defaultNativeBuildInputs
[
pkgs.python3
pkgs.python3Packages.pycodestyle
pkgs.maturin
pkgs.wasm-pack
pkgs.wasm-bindgen-cli
]
];
text = ''
export RUSTFLAGS"=-Dwarnings"
export RUSTDOCFLAGS="-Dwarnings"
if [[ ! -f "flake.nix" || ! -f "Cargo.toml" || ! -f "rust-toolchain.toml" ]]; then
echo "This should be run from the top-level of the nemo source tree."
exit 1
fi
cargo test
cargo clippy --all-targets
cargo fmt --all -- --check
cargo doc --workspace
pushd nemo-python
pycodestyle .
VENV="$(mktemp -d)"
python3 -m venv "''${VENV}"
# shellcheck disable=SC1091
. "''${VENV}"/bin/activate
maturin develop
python3 -m unittest discover tests -v
deactivate
rm -rf "''${VENV}"
popd
HOME=$TMPDIR wasm-pack build --weak-refs --mode=no-install nemo-wasm
cargo miri test
'';
};
};
checks =
let
runCargo' =
name: env: buildCommand:
pkgs.stdenv.mkDerivation (
{
preferLocalBuild = true;
allowSubstitutes = false;
RUSTFLAGS = "-Dwarnings";
RUSTDOCFLAGS = "-Dwarnings";
src = ./.;
cargoDeps = platform.importCargoLock { lockFile = ./Cargo.lock; };
buildInputs = defaultBuildInputs;
nativeBuildInputs =
defaultNativeBuildInputs
++ (with platform; [
cargoSetupHook
pkgs.python3
]);
inherit name;
buildPhase = ''
runHook preBuild
mkdir $out
${buildCommand}
runHook postBuild
'';
}
// env
);
runCargo = name: runCargo' name { };
in
rec {
inherit (packages)
nemo
nemo-python
nemo-wasm
nemo-wasm-node
;
devShell = devShells.default;
clippy = runCargo "nemo-check-clippy" ''
cargo clippy --all-targets
'';
doc = runCargo "nemo-check-docs" ''
cargo doc --workspace
'';
fmt = runCargo "nemo-check-formatting" ''
cargo fmt --all -- --check
'';
test = runCargo "nemo-check-tests" ''
cargo test
'';
python-codestyle =
pkgs.runCommandLocal "nemo-check-python-codestyle"
{
nativeBuildInputs = [ pkgs.python3Packages.pycodestyle ];
}
''
mkdir $out
pycodestyle ${./nemo-python}
'';
};
devShells.default = pkgs.mkShell {
NMO_LOG = "debug";
RUST_LOG = "debug";
RUST_BACKTRACE = 1;
RUST_SRC_PATH = "${toolchain}/lib/rustlib/src/rust/library";
shellHook = ''
export PATH=''${HOME}/.cargo/bin''${PATH+:''${PATH}}
'';
buildInputs = pkgs.lib.concatLists [
defaultBuildInputs
defaultNativeBuildInputs
[
pkgs.cargo-audit
pkgs.cargo-license
pkgs.cargo-tarpaulin
pkgs.gnuplot
pkgs.maturin
pkgs.python3
pkgs.wasm-pack
pkgs.wasm-bindgen-cli
pkgs.nodejs
]
];
};
formatter = channels.nixpkgs.alejandra;
};
};
}
# Local Variables:
# apheleia-formatter: alejandra
# End: