forked from payjoin/rust-payjoin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
363 lines (333 loc) · 10.9 KB
/
flake.nix
File metadata and controls
363 lines (333 loc) · 10.9 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
352
353
354
355
356
357
358
359
360
361
362
363
{
description = "rust-payjoin";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
crane.url = "github:ipetkov/crane";
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
nix2container = {
url = "github:nlewo/nix2container";
};
};
outputs =
{
self,
nixpkgs,
flake-utils,
rust-overlay,
crane,
treefmt-nix,
nix2container,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [
rust-overlay.overlays.default
(final: prev: {
rustToolchains = {
msrv = prev.rust-bin.stable.${msrv-version}.default;
stable = prev.rust-bin.stable.latest.default;
nightly = prev.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
};
})
];
};
msrv-version = "1.85.0";
nginxWithStream = pkgs.nginxMainline.overrideAttrs (oldAttrs: {
configureFlags = oldAttrs.configureFlags ++ [
"--with-stream"
"--with-stream_ssl_module"
"--error-log-path=/dev/null"
];
});
rustVersions =
with pkgs.rust-bin;
builtins.mapAttrs
(
_name: rust-bin:
rust-bin.override {
extensions = [
"rust-src"
"rustfmt"
"llvm-tools-preview"
];
}
)
{
msrv = stable.${msrv-version}.default;
stable = stable.latest.default;
nightly = fromRustupToolchainFile ./rust-toolchain.toml;
};
# Use crane to define nix packages for the workspace crate
# based on https://crane.dev/examples/quick-start-workspace.html
# default to nightly rust toolchain in crane, mainly due to rustfmt difference
craneLibVersions = builtins.mapAttrs (
name: rust-bin: (crane.mkLib pkgs).overrideToolchain (_: rust-bin)
) rustVersions;
src = nixpkgs.lib.cleanSourceWith {
src = ./.;
filter =
path: type:
(builtins.match ".*nginx.conf.template$" path != null)
|| (craneLibVersions.msrv.filterCargoSources path type);
name = "source";
};
cargoLock = rec {
default = recent; # see also #454
recent = ./Cargo-recent.lock;
minimal = ./Cargo-minimal.lock;
msrv = minimal;
stable = default;
nightly = recent;
};
commonArgs = {
inherit src;
strictDeps = true;
# avoid release builds throughout for faster feedback from checks
# note that this also affects the built packages
CARGO_PROFILE = "crane";
# provide fallback name & version for workspace related derivations
# this is mainly to silence warnings from crane about providing a stub
# value overridden in per-crate packages with info from Cargo.toml
pname = "workspace";
version = "no-version";
# tell bitcoind crate not to try to download during build
BITCOIND_SKIP_DOWNLOAD = 1;
};
cargoArtifacts = builtins.mapAttrs (
name: craneLib:
craneLib.buildDepsOnly (
commonArgs
// {
name = "workspace-deps-${name}";
cargoLock = cargoLock.${name};
}
)
) craneLibVersions;
treefmtEval = treefmt-nix.lib.evalModule pkgs ./treefmt.nix;
fileSetForCrate =
subdir:
pkgs.lib.fileset.toSource {
root = ./.;
fileset = pkgs.lib.fileset.unions [
./Cargo.toml
(craneLibVersions.msrv.fileset.commonCargoSources subdir)
];
};
packages =
builtins.mapAttrs
(
name: extraArgs:
# build packages with MSRV toolchain by default, since the builds are
# mostly for testing purposes
craneLibVersions.msrv.buildPackage (
commonArgs
// craneLibVersions.msrv.crateNameFromCargoToml {
cargoToml = builtins.toPath "${./.}/${name}/Cargo.toml";
}
// {
cargoLock = cargoLock.msrv;
cargoArtifacts = cargoArtifacts.msrv;
doCheck = false; # skip testing, since that's done in a separate flake check
cargoExtraArgs = "--locked -p ${name} ${extraArgs}";
inherit src;
}
)
)
{
"payjoin" = "--features v2";
"payjoin-cli" = "--features v1,v2";
"payjoin-directory" = "";
"ohttp-relay" = "";
"payjoin-service" = "";
};
# nix2container for building OCI/Docker images
nix2containerPkgs = nix2container.packages.${system};
# Helper to create a container image for a package
mkContainerImage =
name: pkg: tag:
let
releasePkg = pkg.overrideAttrs (final: prev: { CARGO_PROFILE = "release"; });
in
nix2containerPkgs.nix2container.buildImage {
inherit name tag;
copyToRoot = pkgs.buildEnv {
name = "root";
paths = [ releasePkg ];
pathsToLink = [ "/bin" ];
};
config = {
entrypoint = [ (pkgs.lib.getExe' releasePkg name) ];
};
maxLayers = 50;
};
containerImages =
let
tag = self.shortRev or "dirty";
in
{
"payjoin-service-image" = mkContainerImage "payjoin-service" packages.payjoin-service tag;
};
devShells = builtins.mapAttrs (
_name: craneLib:
craneLib.devShell {
packages =
with pkgs;
[
cargo-edit
cargo-nextest
cargo-watch
rust-analyzer
dart
]
++ pkgs.lib.optionals (!pkgs.stdenv.isDarwin) [
cargo-llvm-cov
];
}
) craneLibVersions;
simpleCheck =
args:
pkgs.stdenvNoCC.mkDerivation (
{
doCheck = true;
dontFixup = true;
installPhase = "mkdir $out";
}
// args
);
dummySrc = pkgs.runCommand "dummy src" { } "mkdir $out";
checkSuite =
name: buildInputs:
simpleCheck {
inherit name;
inherit buildInputs;
src = dummySrc;
};
in
{
packages =
packages
// containerImages
// {
nginx-with-stream = nginxWithStream;
};
devShells = devShells // {
default = devShells.nightly;
};
formatter = treefmtEval.config.build.wrapper;
checks =
packages
// (pkgs.lib.mapAttrs' (
name: craneLib:
(pkgs.lib.nameValuePair "payjoin-workspace-nextest-${name}" (
craneLib.cargoNextest (
commonArgs
// {
name = "payjoin-workspace-nextest-${name}";
cargoLock = cargoLock.${name};
cargoArtifacts = cargoArtifacts.${name};
partitions = 1;
partitionType = "count";
cargoExtraArgs = "--locked --all-features";
NEXTEST_SHOW_PROGRESS = "none";
BITCOIND_EXE = nixpkgs.lib.getExe' pkgs.bitcoind "bitcoind";
NGINX_EXE = nixpkgs.lib.getExe' nginxWithStream "nginx";
nativeBuildInputs = [ nginxWithStream ];
doInstallCargoArtifacts = false;
}
)
))
) craneLibVersions
)
// {
payjoin-workspace-machete = craneLibVersions.nightly.mkCargoDerivation (
commonArgs
// {
pname = "payjoin-workspace-machete";
cargoLock = cargoLock.nightly;
cargoArtifacts = cargoArtifacts.nightly;
nativeBuildInputs = [ pkgs.cargo-machete ];
buildPhaseCargoCommand = "";
checkPhaseCargoCommand = "cargo machete";
doCheck = true;
}
);
payjoin-workspace-clippy = craneLibVersions.nightly.cargoClippy (
commonArgs
// {
cargoLock = cargoLock.nightly;
cargoArtifacts = cargoArtifacts.nightly;
cargoClippyExtraArgs = "--all-targets --all-features --keep-going -- --deny warnings";
}
);
payjoin-workspace-doc = craneLibVersions.nightly.cargoDoc (
commonArgs
// {
cargoLock = cargoLock.nightly;
cargoArtifacts = cargoArtifacts.nightly;
}
);
payjoin-workspace-fmt = craneLibVersions.nightly.cargoFmt (
commonArgs
// {
inherit src;
# cargoLock = cargoLock.nightly;
}
);
formatting = treefmtEval.config.build.check self;
quick = checkSuite "quick" (
with self.outputs.checks.${system};
[
formatting
]
);
slow = checkSuite "slow" (
with self.outputs.checks.${system};
[
nightly
stable
msrv
]
);
nightly = checkSuite "nightly" (
with self.outputs.checks.${system};
[
payjoin-workspace-nextest-nightly
]
);
stable = checkSuite "stable" (
with self.outputs.checks.${system};
[
payjoin-workspace-nextest-stable
]
);
msrv = checkSuite "msrv" (
with self.outputs.checks.${system};
[
payjoin-workspace-nextest-msrv
]
++ pkgs.lib.attrValues packages
);
maintenance = checkSuite "maintenance" (
with self.outputs.checks.${system};
[
payjoin-workspace-machete
payjoin-workspace-clippy
payjoin-workspace-doc
formatting
]
);
};
}
);
}