-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
65 lines (62 loc) · 2.26 KB
/
flake.nix
File metadata and controls
65 lines (62 loc) · 2.26 KB
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
{
description = "Edein";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
rust-overlay.url = "github:oxalica/rust-overlay";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { nixpkgs, rust-overlay, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs { inherit system overlays; };
rustToolchain = pkgs.rust-bin.stable.latest.default.override {
targets = [ "wasm32-unknown-unknown" ];
};
rustPlatform = pkgs.makeRustPlatform {
cargo = rustToolchain;
rustc = rustToolchain;
};
devPort = 3000;
in {
packages.default = rustPlatform.buildRustPackage {
pname = "edein-web";
version = "0.1.0";
src = ./.;
cargoLock.lockFile = ./Cargo.lock;
cargoBuildFlags = [ "--package" "edein-wasm" ];
nativeBuildInputs = with pkgs; [ rustToolchain wasm-bindgen-cli ];
dontCargoBuild = true;
buildPhase = ''
runHook preBuild
export CARGO_NET_OFFLINE=true
cargo build --release --target wasm32-unknown-unknown --package edein-wasm
shopt -s nullglob
wasm=(target/wasm32-unknown-unknown/release/*.wasm)
if [[ ''${#wasm[@]} -eq 0 ]]; then
echo "no wasm artifact under target/wasm32-unknown-unknown/release" >&2
exit 1
fi
${pkgs.wasm-bindgen-cli}/bin/wasm-bindgen "''${wasm[0]}" --out-dir web/pkg --target web
runHook postBuild
'';
installPhase = ''
mkdir -p $out
cp -r web $out/
'';
doCheck = false;
};
apps.default = {
type = "app";
program = toString (pkgs.writeShellScript "edein-run" ''
set -e
export PATH="${rustToolchain}/bin:${pkgs.wasm-pack}/bin:${pkgs.nodejs}/bin:${pkgs.pnpm}/bin:$PATH"
wasm-pack build --target web --out-dir web/pkg
cd web
pnpm install --frozen-lockfile 2>/dev/null || pnpm install
exec pnpm exec vite --host 0.0.0.0 --port ${toString devPort}
'');
};
}
);
}