-
Notifications
You must be signed in to change notification settings - Fork 2
/
flake.nix
112 lines (112 loc) · 5.37 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
{
description = "kitchen";
# Pin nixpkgs
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
gitignore = { url = "github:hercules-ci/gitignore.nix"; flake = false; };
flake-utils.url = "github:numtide/flake-utils";
rust-overlay = {
url = "github:oxalica/rust-overlay?ref=stable";
inputs.nixpkgs.follows = "nixpkgs";
};
naersk.url = "github:nix-community/naersk";
flake-compat = { url = "github:edolstra/flake-compat"; flake = false; };
cargo-wasm2map-src = { url = "github:mtolmacs/wasm2map"; flake = false; };
};
outputs = {nixpkgs, flake-utils, rust-overlay, naersk, cargo-wasm2map-src, ...}:
let
kitchenGen = (import ./nix/kitchen/default.nix);
kitchenWasmGen = (import ./nix/kitchenWasm/default.nix);
moduleGen = (import ./nix/kitchen/module.nix);
wasm-packGen = (import ./nix/wasm-pack/default.nix);
wasm-bindgenGen = (import ./nix/wasm-bindgen/default.nix);
version = "0.2.25";
in
flake-utils.lib.eachDefaultSystem (system:
let
overlays = [ rust-overlay.overlays.default ];
pkgs = import nixpkgs { inherit system overlays; };
rust-wasm = pkgs.rust-bin.stable."1.77.0".default.override {
extensions = [ "rust-src" ];
# Add wasm32 as an extra target besides the native target.
targets = [ "wasm32-unknown-unknown" ];
};
# make sure to use our rust-wasm build target as the rust toolchain
# in naersk.
naersk-lib = pkgs.callPackage naersk {
rustc = rust-wasm;
cargo = rust-wasm;
};
# TODO(jwall): Do the same thing for wasm-bindgen as well?
# We've run into a few problems with the bundled wasm-pack in nixpkgs.
# Better to just control this part of our toolchain directly.
wasm-pack = wasm-packGen {
inherit rust-wasm naersk-lib pkgs;
};
cargo-wasm2map = naersk-lib.buildPackage {
pname = "cargo-wasm2map";
version = "v0.1.0";
build-inputs = [ rust-wasm ];
src = cargo-wasm2map-src;
cargoBuildOptions = opts: opts ++ ["-p" "cargo-wasm2map" ];
};
wasm-bindgen = pkgs.callPackage wasm-bindgenGen { inherit pkgs; };
kitchenWasm = kitchenWasmGen {
inherit pkgs rust-wasm wasm-bindgen version cargo-wasm2map;
lockFile = ./Cargo.lock;
outputHashes = {
# I'm maintaining some patches for these so the lockfile hashes are a little
# incorrect. We override those here.
"wasm-web-component-0.2.0" = "sha256-quuPgzGb2F96blHmD3BAUjsWQYbSyJGZl27PVrwL92k=";
"sycamore-0.8.2" = "sha256-D968+8C5EelGGmot9/LkAlULZOf/Cr+1WYXRCMwb1nQ=";
};
};
kitchen = (kitchenGen {
inherit pkgs version naersk-lib kitchenWasm rust-wasm;
# Because it's a workspace we need the other crates available as source
# TODO(jwall): gitignoreSource is broken right now due to being impure.
#root = (pkgs.callPackage gitignore { }).gitignoreSource ./.;
root = ./.;
});
kitchenWasmDebug = kitchenWasmGen {
inherit pkgs rust-wasm wasm-bindgen version cargo-wasm2map;
lockFile = ./Cargo.lock;
outputHashes = {
# I'm maintaining some patches for these so the lockfile hashes are a little
# incorrect. We override those here.
"wasm-web-component-0.2.0" = "sha256-quuPgzGb2F96blHmD3BAUjsWQYbSyJGZl27PVrwL92k=";
"sycamore-0.8.2" = "sha256-D968+8C5EelGGmot9/LkAlULZOf/Cr+1WYXRCMwb1nQ=";
};
#features = "--features debug_logs";
};
kitchenDebug = (kitchenGen {
inherit pkgs version naersk-lib rust-wasm;
kitchenWasm = kitchenWasmDebug;
# Because it's a workspace we need the other crates available as source
# TODO(jwall): gitignoreSource is broken right now due to being impure.
#root = (pkgs.callPackage gitignore { }).gitignoreSource ./.;
root = ./.;
});
module = moduleGen {inherit kitchen;};
in
{
packages = {
inherit kitchenWasm
kitchen
kitchenWasmDebug
kitchenDebug
;
};
defaultPackage = kitchen;
nixosModules.kitchen = module;
defaultApp = {
type = "app";
program = "${kitchen}/bin/kitchen";
};
devShell = pkgs.callPackage ./nix/devShell/default.nix {
inherit rust-wasm wasm-bindgen cargo-wasm2map;
wasm-pack-hermetic = wasm-pack;
};
}
);
}