Skip to content

Commit

Permalink
enable build with nix flakes
Browse files Browse the repository at this point in the history
By default runs the bitcoin version

```shell
$ nix run .
Config { log: StdErrLog { verbosity: Error, quiet: false, show_level: true, timestamp: Off, modules: [], writer: "stderr", color_choice: Auto, show_module_names: false }, network_type: Bitcoin, db_path: "./db/mainnet", daemon_dir: "/home/casatta/.bitcoin", blocks_dir: "/home/casatta/.bitcoin/blocks", daemon_rpc_addr: 127.0.0.1:8332, cookie: None, electrum_rpc_addr: 127.0.0.1:50001, http_addr: 127.0.0.1:3000, http_socket_file: None, monitoring_addr: 127.0.0.1:4224, jsonrpc_import: false, light_mode: false, address_search: false, index_unspendables: false, cors: None, precache_scripts: None, utxos_limit: 500, electrum_txs_limit: 500, electrum_banner: "Welcome to electrs-esplora 0.4.1", electrum_rpc_logging: None }
```

But it contains also a package with the liquid variant:

```shell
$ nix run .#blockstream-electrs-liquid -- --network liquid
Config { log: StdErrLog { verbosity: Error, quiet: false, show_level: true, timestamp: Off, modules: [], writer: "stderr", color_choice: Auto, show_module_names: false }, network_type: Liquid, db_path: "./db/liquid", daemon_dir: "/home/casatta/.bitcoin/liquidv1", blocks_dir: "/home/casatta/.bitcoin/liquidv1/blocks", daemon_rpc_addr: 127.0.0.1:7041, cookie: None, electrum_rpc_addr: 127.0.0.1:51000, http_addr: 127.0.0.1:3000, http_socket_file: None, monitoring_addr: 127.0.0.1:34224, jsonrpc_import: false, light_mode: false, address_search: false, index_unspendables: false, cors: None, precache_scripts: None, utxos_limit: 500, electrum_txs_limit: 500, electrum_banner: "Welcome to electrs-esplora 0.4.1", electrum_rpc_logging: None, parent_network: Bitcoin, asset_db_path: None }
```
  • Loading branch information
RCasatta committed Apr 6, 2024
1 parent 65f7a57 commit 6fe0844
Show file tree
Hide file tree
Showing 4 changed files with 194 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ target
*.sublime*
*~
*.pyc
result
106 changes: 106 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

85 changes: 85 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
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";
flake-utils.follows = "flake-utils";
};
};
crane = {
url = "github:ipetkov/crane";
inputs = {
nixpkgs.follows = "nixpkgs";
};
};
};
outputs = { self, nixpkgs, flake-utils, rust-overlay, crane }:
flake-utils.lib.eachDefaultSystem
(system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
inherit system overlays;
};
rustToolchain = pkgs.pkgsBuildHost.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;

craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;

src = craneLib.cleanCargoSource ./.;

nativeBuildInputs = with pkgs; [ rustToolchain clang ]; # required only at build time
buildInputs = with pkgs; [ ]; # also required at runtime

commonArgs = {
inherit src buildInputs nativeBuildInputs;
LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
ELEMENTSD_SKIP_DOWNLOAD = true;
BITCOIND_SKIP_DOWNLOAD = true;
ELECTRUMD_SKIP_DOWNLOAD = true;
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
bin = craneLib.buildPackage (commonArgs // {
inherit cargoArtifacts;

# TODO: do testing by providing executables via *_EXE env var for {bitcoin,elements,electrum}d
doCheck = false;
});
binLiquid = craneLib.buildPackage (commonArgs // {
inherit cargoArtifacts;
cargoExtraArgs = "--features liquid";

# TODO: do testing by providing executables via *_EXE env var for {bitcoin,elements,electrum}d
doCheck = false;
});


in
with pkgs;
{
packages =
{
# that way we can build `bin` specifically,
# but it's also the default.
inherit bin;
default = bin;
};

apps."blockstream-electrs-liquid" = {
type = "app";
program = "${binLiquid}/bin/electrs";
};
apps."blockstream-electrs" = {
type = "app";
program = "${bin}/bin/electrs";
};


devShells.default = mkShell {
inputsFrom = [ bin ];
};
}
);
}
2 changes: 2 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[toolchain]
channel = "1.75.0"

0 comments on commit 6fe0844

Please sign in to comment.