-
Notifications
You must be signed in to change notification settings - Fork 24
/
flake.nix
129 lines (113 loc) · 4.43 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
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs = {
nixpkgs.follows = "nixpkgs";
};
};
crane = {
url = "github:ipetkov/crane";
inputs = {
nixpkgs.follows = "nixpkgs";
};
};
electrs-flake = {
url = "github:blockstream/electrs";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
crane.follows = "crane";
rust-overlay.follows = "rust-overlay";
};
};
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";
};
};
};
outputs = { self, nixpkgs, flake-utils, rust-overlay, crane, electrs-flake, registry-flake }:
flake-utils.lib.eachDefaultSystem
(system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
inherit system overlays;
};
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;
registry = registry-flake.packages.${system};
# 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.8.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
'';
});
elementsd_ct = pkgs.elementsd.overrideAttrs (final: prev: rec {
version = "23.2.4";
src = pkgs.fetchFromGitHub {
owner = "ElementsProject";
repo = "elements";
rev = "elements-${version}";
sha256 = "sha256-UNjYkEZBjGuhkwBxSkNXjBBcLQqoan/afCLhoR2lOY4=";
};
});
in
{
packages =
{
# that way we can build `bin` specifically,
# but it's also the default.
inherit bin;
default = bin;
};
devShells.default = pkgs.mkShell {
inputsFrom = [ bin ];
buildInputs = [ registry.bin rustToolchain ];
ELEMENTSD_EXEC = "${elementsd_ct}/bin/elementsd";
BITCOIND_EXEC = "${pkgs.bitcoind}/bin/bitcoind";
ELECTRS_LIQUID_EXEC = electrs.program;
SKIP_VERIFY_DOMAIN_LINK = "1"; # the registry server skips validation
};
}
);
}