-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathflake.nix
More file actions
351 lines (308 loc) · 15 KB
/
Copy pathflake.nix
File metadata and controls
351 lines (308 loc) · 15 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
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
{
# flake format https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake.html#flake-format
description = "Holonix - Holochain Nix flake";
# specify all input dependencies needed to create the outputs of the flake
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-26.05";
# utility to iterate over multiple target platforms
flake-parts.url = "github:hercules-ci/flake-parts";
# lib to build a nix package from a rust crate
crane = {
url = "github:ipetkov/crane";
};
# Rust toolchain
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
kitsune2 = {
url = "github:holochain/kitsune2?ref=v0.5.0";
flake = false;
};
# Holochain sources
holochain = {
url = "github:holochain/holochain?ref=holochain-0.8.0-dev.1";
flake = false;
};
# Lair keystore sources
lair-keystore = {
url = "github:holochain/lair?ref=v0.7.1";
flake = false;
};
# Holochain scaffolding CLI
hc-scaffold = {
url = "github:holochain/scaffolding?ref=v0.700.0";
flake = false;
};
};
# outputs that this flake should produce
outputs = inputs @ { self, nixpkgs, flake-parts, rust-overlay, crane, ... }:
# refer to flake-parts docs https://flake.parts/
flake-parts.lib.mkFlake { inherit inputs; }
{
# systems that his flake can be used on
systems = [ "aarch64-darwin" "x86_64-linux" "x86_64-darwin" "aarch64-linux" ];
# for each system...
perSystem = { config, pkgs, system, ... }:
let
# include Rust overlay in nixpkgs
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
inherit system overlays;
};
rustVersion = "1.95.0";
# define Rust toolchain version and targets to be exported from this flake
rust = (pkgs.rust-bin.stable.${rustVersion}.minimal.override
{
extensions = [ "clippy" "rustfmt" ];
targets = [ "wasm32-unknown-unknown" ];
});
# instruct crane to use Rust toolchain specified above
craneLib = (crane.mkLib pkgs).overrideToolchain (p: p.rust-bin.stable.${rustVersion}.minimal);
bootstrap-srv =
craneLib.buildPackage {
pname = "kitsune2-bootstrap-srv";
# only build kitsune2-bootstrap-srv binary with SBD (default) disabled and the Iroh relay enabled
cargoExtraArgs = "-p kitsune2_bootstrap_srv --no-default-features --features=iroh-relay";
# Use Kitsune2 sources as defined in input dependencies.
src = craneLib.cleanCargoSource inputs.kitsune2;
# do not check built package as it either builds successfully or not
doCheck = false;
};
# Common Crane configuration to build binaries from the Holochain workspace.
holochainCommon =
let
# Crane filters out all non-cargo related files. Define include filter with files needed for build.
nonCargoBuildFiles = path: _type: builtins.match ".*(json|sql|wasm.gz)$" path != null;
includeFilesFilter = path: type:
(craneLib.filterCargoSources path type) || (nonCargoBuildFiles path type);
in
{
# Set a placeholder name for the dependencies derivation.
pname = "holochain";
# Crane wants a version when it builds dependencies but these arguments get re-used for different
# binaries. Set to 0.0.0 and expect packages to override it.
version = "0.0.0";
# Use Holochain sources as defined in input dependencies and include only those files defined in the
# filter previously.
src = pkgs.lib.cleanSourceWith {
src = inputs.holochain;
filter = includeFilesFilter;
};
# additional packages needed for build
buildInputs = [
pkgs.perl
pkgs.cmake
pkgs.clang
pkgs.go
pkgs.llvmPackages_18.libunwind
];
# Avoid Go trying to init modules in a directory that isn't writable while building tx5-go-pion-sys.
preBuild = ''
export HOME=$(mktemp -d)
'';
# do not check built package as it either builds successfully or not
doCheck = false;
# Make sure libdatachannel can find C++ standard libraries from clang.
LIBCLANG_PATH = "${pkgs.llvmPackages_18.libclang.lib}/lib";
};
# Define a derivation for just the Holochain dependencies.
holochainDeps = craneLib.buildDepsOnly holochainCommon;
# Define a function to build the Holochain binary. This allows consumers to customize the
# build by overriding function arguments.
holochainBuilder =
{
# Specify features to be built into Holochain. Can be overridden by the consumer.
# See the custom feature template for an example.
cargoExtraArgs ? ""
}:
let
# Crane doesn't know which version to select from a workspace, so we tell it where to look
crateInfo = craneLib.crateNameFromCargoToml { cargoToml = inputs.holochain + "/crates/holochain/Cargo.toml"; };
in
craneLib.buildPackage (holochainCommon // { cargoArtifacts = holochainDeps; } // {
pname = "holochain";
version = crateInfo.version;
cargoExtraArgs = "--manifest-path crates/holochain/Cargo.toml --bin holochain " + cargoExtraArgs;
});
# Default Holochain build, made overridable to allow consumers to extend cargo build arguments.
holochain = pkgs.lib.makeOverridable holochainBuilder { };
# Similar to the Holochain builder above, but for the hc binary.
hcBuilder =
{ cargoExtraArgs ? "" }:
let
# Crane doesn't know which version to select from a workspace, so we tell it where to look
crateInfo = craneLib.crateNameFromCargoToml { cargoToml = inputs.holochain + "/crates/hc/Cargo.toml"; };
in
craneLib.buildPackage (holochainCommon // { cargoArtifacts = holochainDeps; } // {
pname = "hc";
version = crateInfo.version;
# only build hc binary
cargoExtraArgs = "--manifest-path crates/hc/Cargo.toml --bin hc " + cargoExtraArgs;
});
# Default hc binary.
hc = pkgs.lib.makeOverridable hcBuilder { };
# The Holochain terminal, which has no feature flags and can just be defined as a normal package.
hcterm =
let
# Crane doesn't know which version to select from a workspace, so we tell it where to look
crateInfo = craneLib.crateNameFromCargoToml { cargoToml = inputs.holochain + "/crates/holochain_terminal/Cargo.toml"; };
in
craneLib.buildPackage (holochainCommon // { cargoArtifacts = holochainDeps; } // {
pname = "hcterm";
version = crateInfo.version;
# only build hcterm binary
cargoExtraArgs = "--manifest-path crates/holochain_terminal/Cargo.toml --bin hcterm";
});
# define how to build Lair keystore binary
lair-keystore =
let
# Crane filters out all non-cargo related files. Define include filter with files needed for build.
nonCargoBuildFiles = path: _type: builtins.match ".*(sql|md)$" path != null;
includeFilesFilter = path: type:
(craneLib.filterCargoSources path type) || (nonCargoBuildFiles path type);
# Crane doesn't know which version to select from a workspace, so we tell it where to look
crateInfo = craneLib.crateNameFromCargoToml { cargoToml = inputs.lair-keystore + "/Cargo.toml"; };
in
craneLib.buildPackage {
pname = "lair-keystore";
version = crateInfo.version;
# only build lair-keystore binary
cargoExtraArgs = "--bin lair-keystore";
# Use Lair keystore sources as defined in input dependencies and include only those files defined in the
# filter previously.
src = pkgs.lib.cleanSourceWith {
src = inputs.lair-keystore;
filter = includeFilesFilter;
};
# additional packages needed for build
# perl needed for openssl on all platforms
buildInputs = [ pkgs.perl ];
# do not check built package as it either builds successfully or not
doCheck = false;
};
hc-scaffold =
let
# Crane filters out all non-cargo related files. Define include filter with files needed for build.
nonCargoBuildFiles = path: _type: builtins.match ".*(gitignore|md|hbs|nix|sh)$" path != null;
includeFilesFilter = path: type:
(craneLib.filterCargoSources path type) || (nonCargoBuildFiles path type);
in
craneLib.buildPackage {
pname = "hc-scaffold";
src = pkgs.lib.cleanSourceWith {
src = inputs.hc-scaffold;
filter = includeFilesFilter;
};
doCheck = false;
buildInputs = [
pkgs.perl
];
};
# Shell script to show what versions of the Holochain tools are installed.
# It can be included as a package into the dev shell and is then available by its name - `hn-introspect`.
hn-introspect = pkgs.writeShellScriptBin "hn-introspect" ''
#!/usr/bin/env bash
if command -v "hc-scaffold" > /dev/null; then
echo "hc-scaffold : $(hc-scaffold --version) (${builtins.substring 0 7 inputs.hc-scaffold.rev})"
else
echo "hc-scaffold : not installed"
fi
if command -v "lair-keystore" > /dev/null; then
echo "Lair keystore : $(lair-keystore --version) (${builtins.substring 0 7 inputs.lair-keystore.rev})"
else
echo "Lair keystore : not installed"
fi
if command -v "kitsune2-bootstrap-srv" > /dev/null; then
echo "Kitsune2 bootstrap srv : $(kitsune2-bootstrap-srv --version) (${builtins.substring 0 7 inputs.kitsune2.rev})"
else
echo "Kitsune2 bootstrap srv : not installed"
fi
if command -v "hc" > /dev/null; then
echo "Holochain CLI : $(hc --version) (${builtins.substring 0 7 inputs.holochain.rev})"
else
echo "Holochain CLI : not installed"
fi
if command -v "hcterm" > /dev/null; then
echo "Holochain terminal : $(hcterm --version) (${builtins.substring 0 7 inputs.holochain.rev})"
else
echo "Holochain terminal : not installed"
fi
if command -v "holochain" > /dev/null; then
echo "Holochain : $(holochain --version) (${builtins.substring 0 7 inputs.holochain.rev})"
printf "\nHolochain build info: "
holochain --build-info | ${pkgs.jq}/bin/jq
else
echo "Holochain : not installed"
fi
'';
in
{
# Configure a formatter so that `nix fmt` can be used to format this file.
formatter = pkgs.nixpkgs-fmt;
packages = {
inherit holochain;
inherit hc;
inherit hcterm;
inherit bootstrap-srv;
inherit lair-keystore;
inherit hc-scaffold;
inherit rust;
inherit hn-introspect;
};
# Define runnable applications for use with `nix run`.
# These can be used like `nix run "github:holochain/holonix#hc-scaffold" -- --version`.
# https://flake.parts/options/flake-parts.html?highlight=perSystem.apps#opt-perSystem.apps
apps = {
holochain.program = "${holochain}/bin/holochain";
holochain.meta.description = "Holochain conductor";
hc.program = "${hc}/bin/hc";
hc.meta.description = "Holochain CLI";
hcterm.program = "${hcterm}/bin/hcterm";
hcterm.meta.description = "Holochain terminal";
kitsune2-bootstrap-srv.program = "${bootstrap-srv}/bin/kitsune2-bootstrap-srv";
kitsune2-bootstrap-srv.meta.description = "Kitsune2 bootstrap server";
lair-keystore.program = "${lair-keystore}/bin/lair-keystore";
lair-keystore.meta.description = "Lair keystore";
hc-scaffold.program = "${hc-scaffold}/bin/hc-scaffold";
hc-scaffold.meta.description = "Holochain scaffolding CLI";
};
devShells = {
default = pkgs.mkShell {
packages = [
holochain
hc
hcterm
bootstrap-srv
lair-keystore
hc-scaffold
hn-introspect
rust
];
};
};
};
} // {
# Add content which is not platform specific after using flake-parts to generate platform specific content.
templates = {
# A template that can be used to create a flake that depends on this flake, with recommended defaults.
default = {
path = ./templates/default;
description = "Holonix default template";
};
custom-holochain = {
path = ./templates/custom-holochain;
description = "Holonix template for custom Holochain build";
};
custom-rust = {
path = ./templates/custom-rust;
description = "Flake for Holochain app development with Rust stable";
};
};
};
nixConfig = {
# https://nixos.wiki/wiki/Maintainers:Fastly#BETA:_Try_cache_v2.21
substituters = [ "https://aseipp-nix-cache.freetls.fastly.net" "https://cache.nixos.org" "https://holochain-ci.cachix.org" ];
trusted-public-keys = [ "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=" "holochain-ci.cachix.org-1:5IUSkZc0aoRS53rfkvH9Kid40NpyjwCMCzwRTXy+QN8=" ];
};
}