-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathflake.nix
189 lines (174 loc) · 5.51 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
{
description = "Chartistry is a charting library for Leptos";
inputs = {
nixpkgs.url = "nixpkgs";
utils.url = "flake-utils";
crane.url = "github:ipetkov/crane";
advisory-db = {
url = "github:rustsec/advisory-db";
flake = false;
};
cargo-leptos-src = {
url = "github:leptos-rs/cargo-leptos?tag=v0.2.24";
flake = false; # Only provides a devShell
};
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
trunk-src = {
url = "github:trunk-rs/trunk";
flake = false; # Avoid breakage if added
};
};
outputs =
{
self,
nixpkgs,
utils,
rust-overlay,
crane,
advisory-db,
...
}@inputs:
utils.lib.eachDefaultSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system}.appendOverlays [
rust-overlay.overlays.default
#self.overlays.tools
];
rustToolchain = pkgs.rust-bin.stable.latest.default.override {
targets = [ "wasm32-unknown-unknown" ];
};
craneLib = ((crane.mkLib pkgs).overrideToolchain rustToolchain).overrideScope (
final: prev: {
trunk = trunk-local;
wasm-bindgen-cli = wasm-bindgen-cli-local;
}
);
# Utilities
cargo-leptos-local = craneLib.buildPackage {
src = craneLib.cleanCargoSource inputs.cargo-leptos-src;
strictDeps = true;
buildInputs = with pkgs; [
openssl
pkg-config
wasm-bindgen-cli-local
];
cargoExtraArgs = "--no-default-features --features no_downloads";
doCheck = false;
};
trunk-local = craneLib.buildPackage {
src = inputs.trunk-src; # Don't clean source
strictDeps = true;
buildInputs = with pkgs; [
openssl
pkg-config
wasm-bindgen-cli-local
];
cargoExtraArgs = "--no-default-features --features rustls";
doCheck = false;
};
wasm-bindgen-cli-local = pkgs.wasm-bindgen-cli.override {
version = "0.2.99"; # Note: must be kept in sync with Cargo.lock
hash = "sha256-1AN2E9t/lZhbXdVznhTcniy+7ZzlaEp/gwLEAucs6EA=";
cargoHash = "sha256-DbwAh8RJtW38LJp+J9Ht8fAROK9OabaJ85D9C/Vkve4=";
};
# Build demo
src =
with pkgs;
lib.cleanSourceWith {
src = ./.;
filter =
path: type:
(lib.hasSuffix ".html" path)
|| (lib.hasInfix "/assets/" path)
|| (craneLib.filterCargoSources path type);
};
commonArgs = {
pname = "leptos-chartistry-workspace";
version = "0.0.1";
inherit src;
strictDeps = true;
CARGO_PROFILE = "release";
};
commonWasmArgs = commonArgs // {
wasm-bindgen-cli = wasm-bindgen-cli-local;
CARGO_BUILD_TARGET = "wasm32-unknown-unknown";
# Cannot run `cargo test` on wasm
doCheck = false;
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
wasmArtifacts = craneLib.buildDepsOnly commonWasmArgs;
demo = craneLib.buildTrunkPackage (
commonWasmArgs
// {
pname = "chartistry-demo";
cargoArtifacts = wasmArtifacts;
cargoExtraArgs = "--package=demo";
trunkExtraBuildArgs = "--config=./demo/Trunk.toml";
# Create symlinks for each of our pages. Enables a static site.
postInstall = ''
ln -s index.html $out/examples.html
mkdir -p $out/examples
for f in demo/src/examples/*.rs; do
f=''${f##*/} # Remove dir prefix
f=''${f%.rs} # Remove file suffix
f=''${f//_/-} # Replace underscores with dashes
ln -s ../index.html $out/examples/$f.html
done
'';
}
);
# Build SSR example
ssrExampleBin = craneLib.buildPackage (
commonArgs
// {
pname = "chartistry-ssr-example-bin";
inherit src cargoArtifacts;
cargoExtraArgs = "-p my_example_ssr --bin=my_example_ssr --no-default-features --features=ssr";
}
);
ssrExampleLib = craneLib.buildPackage (
commonWasmArgs
// {
pname = "chartistry-ssr-example-lib";
inherit src;
cargoArtifacts = wasmArtifacts;
cargoExtraArgs = "-p my_example_ssr --lib --no-default-features --features=hydrate";
}
);
in
{
devShells.default = pkgs.mkShell {
packages = [
cargo-leptos-local
trunk-local
wasm-bindgen-cli-local
];
};
checks = {
# Ensure we can build all code
inherit demo ssrExampleBin ssrExampleLib;
clippy = craneLib.cargoClippy (
commonArgs
// {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
}
);
doc = craneLib.cargoDoc (
commonArgs
// {
inherit cargoArtifacts;
cargoDocExtraArgs = "--workspace";
}
);
audit = craneLib.cargoAudit { inherit src advisory-db; };
fmt = craneLib.cargoFmt commonArgs;
};
packages.demo = demo;
}
);
}