Repository navigation
Expand file tree
/
Copy pathflake.nix
More file actions
222 lines (204 loc) · 7.19 KB
/
Copy pathflake.nix
File metadata and controls
222 lines (204 loc) · 7.19 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
{
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";
};
waterfalls-nixpkgs.url = "github:NixOS/nixpkgs/c5296fdd05cfa2c187990dd909864da9658df755";
waterfalls-crane.url = "github:ipetkov/crane/0314e365877a85c9e5758f9ea77a9972afbb4c21";
waterfalls-rust-overlay = {
url = "github:oxalica/rust-overlay/e9bcd12156a577ac4e47d131c14dc0293cc9c8c2";
inputs.nixpkgs.follows = "waterfalls-nixpkgs";
};
electrs-flake = {
url = "github:blockstream/electrs";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
crane.follows = "crane";
rust-overlay.follows = "rust-overlay";
};
};
waterfalls-flake = {
url = "github:blockstream/waterfalls";
inputs.nixpkgs.follows = "waterfalls-nixpkgs";
inputs.crane.follows = "waterfalls-crane";
inputs.rust-overlay.follows = "waterfalls-rust-overlay";
inputs.flake-utils.follows = "flake-utils";
};
registry-flake = {
url = "github:blockstream/asset_registry/flake";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
crane.follows = "crane";
rust-overlay.follows = "rust-overlay";
};
};
# TODO: Remove nixpkgs-mdbook once MSRV reach 1.88+ and we can upgrade mdbook dependency in docs/snippets/processor
nixpkgs-mdbook.url = "github:NixOS/nixpkgs/566e53c2ad750c84f6d31f9ccb9d00f823165550";
};
outputs =
{
self,
nixpkgs,
flake-utils,
rust-overlay,
crane,
electrs-flake,
waterfalls-flake,
registry-flake,
nixpkgs-mdbook,
...
}:
flake-utils.lib.eachDefaultSystem (
system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
inherit system overlays;
};
pkgs-mdbook = import nixpkgs-mdbook {
inherit system;
};
inherit (pkgs) lib;
rustToolchain = pkgs.pkgsBuildHost.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
electrs = electrs-flake.apps.${system}.blockstream-electrs-liquid;
# upstream test_electrum fails for the bitcoin build, skip the checks
electrs-bitcoin = electrs-flake.packages.${system}.bin.overrideAttrs (_: {
doCheck = false;
});
registry = registry-flake.packages.${system};
waterfalls = waterfalls-flake.packages.${system}.default;
# When filtering sources, we want to allow assets other than .rs files
src = lib.cleanSourceWith {
src = ./.; # The original, unfiltered source
filter =
path: type:
(lib.hasSuffix "\.elf" path)
|| (lib.hasSuffix "\.json" path)
|| (lib.hasSuffix "\.md" path)
|| (lib.hasInfix "/test_data/" path)
|| (lib.hasInfix "/test/data/" path)
|| (lib.hasInfix "/tests/data/" path)
# TODO unify these dir names
||
# Default filter from crane (allow .rs files)
(craneLib.filterCargoSources path type);
};
nativeBuildInputs = with pkgs; [
rustToolchain
pkg-config
]; # required only at build time
buildInputs = [
pkgs.openssl
pkgs.udev
]; # also required at runtime
commonArgs = {
inherit src buildInputs nativeBuildInputs;
# the following must be kept in sync with the ones in ./lwk_cli/Cargo.toml
# note there should be a way to read those from there with
# craneLib.crateNameFromCargoToml { cargoToml = ./path/to/Cargo.toml; }
# but I can't make it work
pname = "lwk_cli";
version = "0.19.0";
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
# remember, `set1 // set2` does a shallow merge:
bin = craneLib.buildPackage (
commonArgs
// {
inherit cargoArtifacts;
cargoTestExtraArgs = "--lib"; # only unit testing, integration testing has more requirements (docker and other executables)
# Without the following also libs are included in the package, and we need to produce only the executable.
# There should probably a way to avoid creating it in the first place, but for now this works.
postInstall = ''
rm -r $out/lib
'';
}
);
amp2MockArgs = commonArgs // {
pname = "amp2_mock";
cargoExtraArgs = "-p amp2_mock";
};
amp2MockCargoArtifacts = craneLib.buildDepsOnly amp2MockArgs;
amp2Mock = craneLib.buildPackage (
amp2MockArgs
// {
cargoArtifacts = amp2MockCargoArtifacts;
postInstall = ''
rm -rf $out/lib
'';
}
);
# Build mdbook-snippets from local source
mdbook-snippets = craneLib.buildPackage {
src = lib.cleanSource ./docs/snippets/processor;
inherit nativeBuildInputs;
buildInputs = [ ];
pname = "mdbook-snippets";
version = "0.1.0";
};
mcp-language-server = pkgs.mcp-language-server;
in
{
packages = {
# that way we can build `bin` specifically,
# but it's also the default.
inherit bin;
default = bin;
amp2-mock = amp2Mock;
inherit mdbook-snippets;
inherit mcp-language-server;
};
devShells.default = pkgs.mkShell {
inputsFrom = [ bin ];
buildInputs = [
mcp-language-server
registry.bin
rustToolchain
pkgs.websocat
pkgs.heaptrack
pkgs-mdbook.mdbook
pkgs-mdbook.mdbook-mermaid
mdbook-snippets
pkgs.cargo-depgraph
pkgs.cargo-bloat
pkgs.cargo-nextest
pkgs.cargo-audit
pkgs.cargo-fuzz
amp2Mock
pkgs.grcov
pkgs.go
pkgs.just
pkgs.lsof
pkgs.nixfmt
pkgs.psmisc
pkgs.sqlite
pkgs.libxml2
pkgs.yq # to validate yml
pkgs.jq
];
ELEMENTSD_EXEC = "${pkgs.elementsd}/bin/elementsd";
BITCOIND_EXEC = "${pkgs.bitcoind}/bin/bitcoind";
BITCOINCLI_EXEC = "${pkgs.bitcoind}/bin/bitcoin-cli";
LIGHTNINGD_EXEC = "${pkgs.clightning}/bin/lightningd";
ELECTRS_LIQUID_EXEC = electrs.program;
ELECTRS_BITCOIN_EXEC = "${electrs-bitcoin}/bin/electrs";
WATERFALLS_EXEC = "${waterfalls}/bin/waterfalls";
ASSET_REGISTRY_EXEC = "${registry.default}/bin/server";
AMP2_MOCK_EXEC = "${amp2Mock}/bin/amp2_mock";
WEBSOCAT_EXEC = "${pkgs.websocat}/bin/websocat";
SKIP_VERIFY_DOMAIN_LINK = "1"; # the registry server skips validation
};
}
);
}