-
Notifications
You must be signed in to change notification settings - Fork 21
/
flake.nix
127 lines (102 loc) · 3.06 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
{
description = "Simulation of evolution, powered by neural networks, genetic algorithms and high school math.";
inputs = {
naersk = {
url = "github:nix-community/naersk";
inputs = {
nixpkgs = {
follows = "nixpkgs";
};
};
};
napalm = {
url = "github:nix-community/napalm";
inputs = {
nixpkgs = {
follows = "nixpkgs";
};
};
};
nixpkgs = {
url = "github:nixos/nixpkgs/nixos-unstable";
};
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs = {
nixpkgs = {
follows = "nixpkgs";
};
};
};
utils = {
url = "github:numtide/flake-utils";
};
};
outputs = { self, naersk, napalm, nixpkgs, rust-overlay, utils }:
utils.lib.eachDefaultSystem (system:
let
pkgs = (import nixpkgs) {
inherit system;
overlays = [
rust-overlay.overlays.default
];
};
# nixpkgs has wasm-bindgen-cli v0.2.91, but we need the newer one
wasmBindgenCli = pkgs.wasm-bindgen-cli.override {
version = "0.2.92";
hash = "sha256-1VwY8vQy7soKEgbki4LD+v259751kKxSxmo/gqE6yV0=";
cargoHash = "sha256-aACJ+lYNEU8FFBs158G1/JG8sc6Rq080PeKCMnwdpH0=";
};
rust = (pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain).override {
targets = [ "wasm32-unknown-unknown" ];
};
naersk' = pkgs.callPackage naersk {
cargo = rust;
rustc = rust;
};
napalm' = pkgs.callPackage napalm {
#
};
# ---
shorelarkWasm' = naersk'.buildPackage {
src = ./.;
copyLibs = true;
CARGO_BUILD_TARGET = "wasm32-unknown-unknown";
};
shorelarkWasmManifest = pkgs.writeText "package.json" ''
{
"name": "lib-simulation-wasm",
"module": "lib_simulation_wasm.js",
"types": "lib_simulation_wasm.d.ts"
}
'';
shorelarkWasm = pkgs.runCommand "shorelark-wasm" { } ''
mkdir $out
cd $out
${pkgs.binaryen}/bin/wasm-opt \
--strip-debug \
-O4 \
${shorelarkWasm'}/lib/lib_simulation_wasm.wasm \
-o lib_simulation_wasm.wasm
cp ${shorelarkWasmManifest} package.json
${wasmBindgenCli}/bin/wasm-bindgen \
lib_simulation_wasm.wasm \
--out-dir .
'';
package = napalm'.buildPackage ./www {
installPhase = ''
# Inside `package.json`, our `lib-simulation-wasm` is included via
# `file:../libs` - this causes `napalm` to create a broken symlink
# (as `../libs` doesn't exist here anymore), which we have to fix:
rm node_modules/lib-simulation-wasm
ln -s ${shorelarkWasm} node_modules/lib-simulation-wasm
npm run build
mv dist $out
'';
};
in
{
defaultPackage = package;
}
);
}