forked from wasmCloud/wasmCloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
390 lines (350 loc) · 13 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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
{
nixConfig.extra-substituters = [
"https://wasmcloud.cachix.org"
"https://crane.cachix.org"
"https://bytecodealliance.cachix.org"
"https://nix-community.cachix.org"
"https://cache.garnix.io"
];
nixConfig.extra-trusted-public-keys = [
"wasmcloud.cachix.org-1:9gRBzsKh+x2HbVVspreFg/6iFRiD4aOcUQfXVDl3hiM="
"crane.cachix.org-1:8Scfpmn9w+hGdXH/Q9tTLiYAE/2dnJYRJP7kl80GuRk="
"bytecodealliance.cachix.org-1:0SBgh//n2n0heh0sDFhTm+ZKBRy2sInakzFGfzN531Y="
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
"cache.garnix.io:CTFPyKSLcx5RMJKfLo5EEPUObbA78b0YQ2DTCJXqr9g="
];
inputs.nixify.inputs.nixlib.follows = "nixlib";
inputs.nixify.url = "github:rvolosatovs/nixify";
inputs.nixlib.url = "github:nix-community/nixpkgs.lib";
inputs.wasmcloud-component-adapters.inputs.nixify.follows = "nixify";
inputs.wasmcloud-component-adapters.url = "github:wasmCloud/wasmcloud-component-adapters/v0.3.0";
inputs.wit-deps.inputs.nixify.follows = "nixify";
inputs.wit-deps.inputs.nixlib.follows = "nixlib";
inputs.wit-deps.url = "github:bytecodealliance/wit-deps/v0.3.5-rc1";
outputs = {
nixify,
nixlib,
wasmcloud-component-adapters,
wit-deps,
...
}:
with builtins;
with nixlib.lib;
with nixify.lib;
rust.mkFlake {
src = ./.;
overlays = [
wit-deps.overlays.default
];
excludePaths = let
washboardExclude = map (name: "washboard-ui/${name}") (remove "dist" (attrNames (readDir ./washboard-ui)));
in
[
".devcontainer"
".envrc"
".github"
".gitignore"
"ADOPTERS.md"
"adr"
"awesome-wasmcloud"
"chart"
"CODE_OF_CONDUCT.md"
"CODEOWNERS"
"CONTRIBUTING.md"
"CONTRIBUTION_LADDER.md"
"crates/wash-cli/.devcontainer"
"crates/wash-cli/build"
"crates/wash-cli/Completions.md"
"crates/wash-cli/CONTRIBUTING.md"
"crates/wash-cli/Dockerfile"
"crates/wash-cli/docs"
"crates/wash-cli/Makefile"
"crates/wash-cli/snap"
"crates/wash-cli/tools"
"Dockerfile"
"flake.nix"
"garnix.yaml"
"GOVERNANCE.md"
"LICENSE"
"OWNERS"
"README.md"
"ROADMAP.md"
"rust-toolchain.toml"
"sample-manifest.yaml"
"SECURITY.md"
]
++ washboardExclude;
doCheck = false; # testing is performed in checks via `nextest`
targets.arm-unknown-linux-gnueabihf = false;
targets.arm-unknown-linux-musleabihf = false;
targets.armv7-unknown-linux-gnueabihf = false;
targets.armv7-unknown-linux-musleabihf = false;
targets.powerpc64le-unknown-linux-gnu = false;
targets.riscv64gc-unknown-linux-gnu = false; # TODO: Enable once Ring updated https://github.com/wasmCloud/wasmCloud/issues/724
targets.s390x-unknown-linux-gnu = false;
targets.wasm32-unknown-unknown = false;
targets.wasm32-wasi = false;
build.packages = [
"wash-cli"
"wasmcloud"
];
clippy.allTargets = true;
clippy.deny = ["warnings"];
clippy.workspace = true;
test.allTargets = true;
test.excludes = [
"wash-cli"
"wash-lib"
];
test.workspace = true;
buildOverrides = {
pkgs,
pkgsCross ? pkgs,
...
}: {
buildInputs ? [],
depsBuildBuild ? [],
nativeBuildInputs ? [],
nativeCheckInputs ? [],
...
} @ args:
with pkgs.lib; let
cargoLock.root = readTOML ./Cargo.lock;
cargoLock.actors-rust = readTOML ./tests/actors/rust/Cargo.lock;
cargoLock.providers-rust = readTOML ./crates/providers/Cargo.lock;
lockPackages =
cargoLock.root.package
++ cargoLock.actors-rust.package
++ cargoLock.providers-rust.package;
# deduplicate lockPackages by $name:$version:$checksum
lockPackages' = listToAttrs (
map (
{
name,
version,
checksum ? "no-hash",
...
} @ pkg:
nameValuePair "${name}:${version}:${checksum}" pkg
)
lockPackages
);
cargoLockParsed =
cargoLock.root
// {
package = attrValues lockPackages';
};
darwin2darwin = pkgs.stdenv.hostPlatform.isDarwin && pkgsCross.stdenv.hostPlatform.isDarwin;
depsBuildBuild' =
depsBuildBuild
++ optionals darwin2darwin [
pkgs.darwin.apple_sdk.frameworks.SystemConfiguration
pkgs.xcbuild.xcrun
];
in
{
inherit
cargoLockParsed
;
WASI_PREVIEW1_COMMAND_COMPONENT_ADAPTER = wasmcloud-component-adapters.packages.${pkgs.stdenv.system}.wasi-preview1-command-component-adapter;
WASI_PREVIEW1_REACTOR_COMPONENT_ADAPTER = wasmcloud-component-adapters.packages.${pkgs.stdenv.system}.wasi-preview1-reactor-component-adapter;
cargoExtraArgs = ""; # disable `--locked` passed by default by crane
buildInputs =
buildInputs
++ optional pkgs.stdenv.hostPlatform.isDarwin pkgs.libiconv;
depsBuildBuild = depsBuildBuild';
nativeBuildInputs =
nativeBuildInputs
++ [
pkgs.protobuf # prost build dependency
];
}
// optionalAttrs (args ? cargoArtifacts) {
depsBuildBuild =
depsBuildBuild'
++ optionals darwin2darwin [
pkgs.darwin.apple_sdk.frameworks.CoreFoundation
pkgs.darwin.apple_sdk.frameworks.CoreServices
];
nativeCheckInputs =
nativeCheckInputs
++ [
pkgs.nats-server
pkgs.redis
];
};
withPackages = {
hostRustToolchain,
packages,
pkgs,
...
}: let
pullDebian = {
imageDigest,
sha256,
}:
pkgs.dockerTools.pullImage {
inherit
imageDigest
sha256
;
imageName = "debian";
finalImageTag = "12.2-slim";
finalImageName = "debian";
};
debian.aarch64 = pullDebian {
imageDigest = "sha256:9ccb91746bf0b2e3e82b2dd37069ef9b358cb7d813217ea3fa430b940fc5dac3";
sha256 = "sha256-cb2lPuBXaQGMrVmvp/Gq0/PtNuTtlZzUmF3S+4jHVtQ=";
};
debian.x86_64 = pullDebian {
imageDigest = "sha256:ea5ad531efe1ac11ff69395d032909baf423b8b88e9aade07e11b40b2e5a1338";
sha256 = "sha256-k+x4aUW10YAQ7X20xxJxqW57y2k20sc4e7unh/kqQZQ=";
};
buildImage = {
fromImage ? null,
pkg,
name,
architecture,
description,
}: let
# ensure that only the binary corresponding to `$name` is copied to the image
bin = pkgs.runCommandLocal name {} ''
mkdir -p $out/bin
cp ${pkg}/bin/${name} $out/bin/${name}
'';
copyToRoot = pkgs.buildEnv {
inherit name;
extraPrefix = "/usr"; # /bin is a symlink to /usr/bin on Debian, add a prefix to avoid replacing original `/bin`
paths = [
bin
pkgs.dockerTools.caCertificates
];
postBuild = ''
mv $out/usr/etc $out/etc
'';
};
version =
if name == "wasmcloud"
then (readTOML ./Cargo.toml).package.version
else if name == "wash"
then (readTOML ./crates/wash-cli/Cargo.toml).package.version
else throw "unsupported binary `${name}`";
in
pkgs.dockerTools.buildImage {
inherit
architecture
copyToRoot
fromImage
name
;
tag = architecture;
config.Cmd = [name];
config.Labels."org.opencontainers.image.description" = description;
config.Labels."org.opencontainers.image.source" = "https://github.com/wasmCloud/wasmCloud";
config.Labels."org.opencontainers.image.title" = name;
config.Labels."org.opencontainers.image.vendor" = "wasmCloud";
config.Labels."org.opencontainers.image.version" = version;
};
buildWashImage = {
pkg,
fromImage,
architecture,
}:
buildImage {
inherit
architecture
fromImage
pkg
;
name = "wash";
description = "WAsmcloud SHell";
};
wash-aarch64-unknown-linux-musl-oci-debian = buildWashImage {
pkg = packages.wasmcloud-aarch64-unknown-linux-musl;
fromImage = debian.aarch64;
architecture = "arm64";
};
wash-x86_64-unknown-linux-musl-oci-debian = buildWashImage {
pkg = packages.wasmcloud-x86_64-unknown-linux-musl;
fromImage = debian.x86_64;
architecture = "amd64";
};
buildWasmcloudImage = {
pkg,
fromImage,
architecture,
}:
buildImage {
inherit
architecture
fromImage
pkg
;
name = "wasmcloud";
description = "wasmCloud host";
};
wasmcloud-aarch64-unknown-linux-musl-oci-debian = buildWasmcloudImage {
pkg = packages.wasmcloud-aarch64-unknown-linux-musl;
fromImage = debian.aarch64;
architecture = "arm64";
};
wasmcloud-x86_64-unknown-linux-musl-oci-debian = buildWasmcloudImage {
pkg = packages.wasmcloud-x86_64-unknown-linux-musl;
fromImage = debian.x86_64;
architecture = "amd64";
};
build-wash-oci-debian = pkgs.writeShellScriptBin "build-wash-oci-debian" ''
set -xe
build() {
${pkgs.buildah}/bin/buildah manifest create "''${1}"
${pkgs.buildah}/bin/buildah manifest add "''${1}" docker-archive:${wash-aarch64-unknown-linux-musl-oci-debian}
${pkgs.buildah}/bin/buildah pull docker-archive:${wash-aarch64-unknown-linux-musl-oci-debian}
${pkgs.buildah}/bin/buildah manifest add "''${1}" docker-archive:${wash-x86_64-unknown-linux-musl-oci-debian}
${pkgs.buildah}/bin/buildah pull docker-archive:${wash-x86_64-unknown-linux-musl-oci-debian}
}
build "''${1:-wash:debian}"
'';
build-wasmcloud-oci-debian = pkgs.writeShellScriptBin "build-wasmcloud-oci-debian" ''
set -xe
build() {
${pkgs.buildah}/bin/buildah manifest create "''${1}"
${pkgs.buildah}/bin/buildah manifest add "''${1}" docker-archive:${wasmcloud-aarch64-unknown-linux-musl-oci-debian}
${pkgs.buildah}/bin/buildah pull docker-archive:${wasmcloud-aarch64-unknown-linux-musl-oci-debian}
${pkgs.buildah}/bin/buildah manifest add "''${1}" docker-archive:${wasmcloud-x86_64-unknown-linux-musl-oci-debian}
${pkgs.buildah}/bin/buildah pull docker-archive:${wasmcloud-x86_64-unknown-linux-musl-oci-debian}
}
build "''${1:-wasmcloud:debian}"
'';
in
packages
// {
inherit
build-wash-oci-debian
build-wasmcloud-oci-debian
wash-aarch64-unknown-linux-musl-oci-debian
wash-x86_64-unknown-linux-musl-oci-debian
wasmcloud-aarch64-unknown-linux-musl-oci-debian
wasmcloud-x86_64-unknown-linux-musl-oci-debian
;
rust = hostRustToolchain;
};
withDevShells = {
devShells,
pkgs,
...
}:
extendDerivations {
buildInputs =
[
pkgs.buildah
pkgs.cargo-audit
pkgs.nats-server
pkgs.protobuf # prost build dependency
pkgs.redis
pkgs.wit-deps
]
++ optional (!(pkgs.stdenv.hostPlatform.isDarwin && pkgs.stdenv.hostPlatform.isAarch64)) pkgs.tinygo; # TinyGo currently fails to buid due to GDB not being supported on aarch64-darwin
}
devShells;
};
}