-
Notifications
You must be signed in to change notification settings - Fork 41
/
flake.nix
186 lines (167 loc) · 6.11 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
{
description = "rust-payjoin";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
crane.url = "github:ipetkov/crane";
};
outputs = {
self,
nixpkgs,
flake-utils,
rust-overlay,
crane,
}:
flake-utils.lib.eachDefaultSystem (
system: let
pkgs = import nixpkgs {
inherit system;
overlays = [rust-overlay.overlays.default];
};
msrv = "1.63.0";
rustVersions = with pkgs.rust-bin;
builtins.mapAttrs (_name: rust-bin:
rust-bin.override {
extensions = ["rust-src" "rustfmt"];
})
{
msrv = stable.${msrv}.default;
stable = stable.latest.default;
nightly = nightly.latest.default;
};
# 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;
craneLib = craneLibVersions.nightly;
src = craneLib.cleanCargoSource ./.;
commonArgs = {
inherit src;
strictDeps = true;
# 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";
# default to recent dependency versions
# TODO add overrides for minimal lockfile, once #454 is resolved
cargoLock = ./Cargo-recent.lock;
# tell bitcoind crate not to try to download during build
BITCOIND_SKIP_DOWNLOAD = 1;
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
individualCrateArgs =
commonArgs
// {
inherit cargoArtifacts;
doCheck = false; # skip testing, since that's done in flake check
};
fileSetForCrate = subdir:
pkgs.lib.fileset.toSource {
root = ./.;
fileset = pkgs.lib.fileset.unions [
./Cargo.toml
(craneLib.fileset.commonCargoSources subdir)
];
};
packages =
builtins.mapAttrs (
name: extraArgs:
craneLib.buildPackage (individualCrateArgs
// craneLib.crateNameFromCargoToml {cargoToml = builtins.toPath "${./.}/${name}/Cargo.toml";}
// {
cargoExtraArgs = "--locked -p ${name} ${extraArgs}";
inherit src;
})
) {
"payjoin" = "--features v2,send,receive";
"payjoin-cli" = "--features v1,v2";
"payjoin-directory" = "";
};
devShells = builtins.mapAttrs (_name: craneLib:
craneLib.devShell {
packages = with pkgs; [
cargo-edit
cargo-nextest
cargo-watch
rust-analyzer
];
})
craneLibVersions;
simpleCheck = args:
pkgs.stdenvNoCC.mkDerivation ({
doCheck = true;
dontFixup = true;
installPhase = "mkdir $out";
}
// args);
in {
packages = packages;
devShells = devShells // {default = devShells.nightly;};
formatter = pkgs.alejandra;
checks =
packages
// {
payjoin-workspace-nextest = craneLib.cargoNextest (commonArgs
// {
inherit cargoArtifacts;
partitions = 1;
partitionType = "count";
# TODO also run integration tests
# this needs --all-features to enable io,_danger_local_https features
# unfortunately this can't yet work because running docker inside the nix sandbox is not possible,
# which precludes use of the redis test container
# cargoExtraArgs = "--locked --all-features";
# buildInputs = [ pkgs.bitcoind ]; # not verified to work
});
payjoin-workspace-nextest-msrv = craneLibVersions.msrv.cargoNextest (commonArgs
// {
cargoArtifacts = craneLibVersions.msrv.buildDepsOnly commonArgs;
partitions = 1;
partitionType = "count";
});
payjoin-workspace-clippy = craneLib.cargoClippy (commonArgs
// {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets --all-features --keep-going -- --deny warnings";
});
payjoin-workspace-doc = craneLib.cargoDoc (commonArgs
// {
inherit cargoArtifacts;
});
payjoin-workspace-fmt = craneLib.cargoFmt (commonArgs
// {
inherit src;
});
nix-fmt-check = simpleCheck {
name = "nix-fmt-check";
src = pkgs.lib.sources.sourceFilesBySuffices ./. [".nix"];
nativeBuildInputs = [pkgs.alejandra];
checkPhase = ''
alejandra -c .
'';
};
shfmt = simpleCheck rec {
name = "shell-checks";
src = pkgs.lib.sources.sourceFilesBySuffices ./. [".sh"];
nativeBuildInputs = [pkgs.shfmt];
checkPhase = ''
shfmt -d -s -i 4 -ci ${src}
'';
};
shellcheck = simpleCheck rec {
name = "shell-checks";
src = pkgs.lib.sources.sourceFilesBySuffices ./. [".sh"];
nativeBuildInputs = [pkgs.shellcheck];
checkPhase = ''
shellcheck -x ${src}
'';
};
};
}
);
}