Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build with nix flake #78

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,7 @@ jobs:
run: cargo test

- name: Tests (Liquid mode, REST)
run: cargo test --features liquid
run: cargo test --features liquid

- name: Tests (no default features)
run: cargo test --no-default-features
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
4 changes: 2 additions & 2 deletions Cargo.lock

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

8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ readme = "README.md"
edition = "2018"

[features]
default = [ "dev" ]
liquid = [ "elements" ]
electrum-discovery = [ "electrum-client"]
dev = [ "bitcoind/25_0", "electrumd/4_1_5", "elementsd/22_1_1" ]

[dependencies]
arraydeque = "0.5.1"
Expand Down Expand Up @@ -58,9 +60,9 @@ electrum-client = { version = "0.8", optional = true }


[dev-dependencies]
bitcoind = { version = "0.34", features = [ "25_0" ] }
elementsd = { version = "0.9", features = [ "22_1_1" ] }
electrumd = { version = "0.1.0", features = [ "4_1_5" ] }
bitcoind = { version = "0.34" }
elementsd = { version = "0.9" }
electrumd = { version = "0.1.0" }
ureq = { version = "2.9", default-features = false, features = [ "json" ] }
tempfile = "3.10"

Expand Down
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.

63 changes: 63 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
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;
cargoExtraArgs = "--no-default-features"; # avoid autodownload feature, which cannot happen in nix for deterministism
LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
bin = craneLib.buildPackage (commonArgs // {
inherit cargoArtifacts;
# doCheck = false;
});

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

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"
4 changes: 2 additions & 2 deletions tests/electrum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use bitcoin::address;

/// Test the Electrum RPC server using an headless Electrum wallet
/// This only runs on Bitcoin (non-Liquid) mode.
#[cfg_attr(not(feature = "liquid"), test)]
#[cfg_attr(feature = "liquid", allow(dead_code))]
#[cfg_attr(all(feature = "dev", not(feature = "liquid")), test)]
#[cfg_attr(any(feature = "liquid", not(feature = "dev")), allow(dead_code))]
fn test_electrum() -> Result<()> {
// Spawn an Electrs Electrum RPC server
let (electrum_server, electrum_addr, mut tester) = common::init_electrum_tester().unwrap();
Expand Down
3 changes: 2 additions & 1 deletion tests/rest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ pub mod common;

use common::Result;

#[test]
#[cfg_attr(feature = "dev", test)]
#[cfg_attr(not(feature = "dev"), allow(dead_code))]
fn test_rest() -> Result<()> {
let (rest_handle, rest_addr, mut tester) = common::init_rest_tester().unwrap();

Expand Down
Loading