From 6fe0844db864a04c411a8636446d3bb8a6ce6a29 Mon Sep 17 00:00:00 2001 From: Riccardo Casatta Date: Thu, 28 Mar 2024 15:29:10 +0100 Subject: [PATCH] enable build with nix flakes 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 } ``` --- .gitignore | 1 + flake.lock | 106 ++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 85 +++++++++++++++++++++++++++++++++++ rust-toolchain.toml | 2 + 4 files changed, 194 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 rust-toolchain.toml diff --git a/.gitignore b/.gitignore index 8dbb109c5..8ed8a0203 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ target *.sublime* *~ *.pyc +result diff --git a/flake.lock b/flake.lock new file mode 100644 index 000000000..6d1fa8e96 --- /dev/null +++ b/flake.lock @@ -0,0 +1,106 @@ +{ + "nodes": { + "crane": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1711586303, + "narHash": "sha256-iZDHWTqQj6z6ccqTSEOPOxQ8KMFAemInUObN2R9vHSs=", + "owner": "ipetkov", + "repo": "crane", + "rev": "a329cd00398379c62e76fc3b8d4ec2934260d636", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1711523803, + "narHash": "sha256-UKcYiHWHQynzj6CN/vTcix4yd1eCu1uFdsuarupdCQQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "2726f127c15a4cc9810843b96cad73c7eb39e443", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "crane": "crane", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": [ + "flake-utils" + ], + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1711592024, + "narHash": "sha256-oD4OJ3TRmVrbAuKZWxElRCyCagNCDuhfw2exBmNOy48=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "aa858717377db2ed8ffd2d44147d907baee656e5", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 000000000..f98272581 --- /dev/null +++ b/flake.nix @@ -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 ]; + }; + } + ); +} diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 000000000..7897a24d1 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "1.75.0"