Files
cdk/flake.nix
thesimplekid f4c857c3e7 Nutshell wallet (#695)
* chore: Add nutshell wallet integration test script

feat: Add MINT_URL configuration for docker container in nutshell wallet integration test script

chore: Make nutshell_wallet_itest.sh executable

fix: Update MINT_URL to use host.docker.internal for Docker container access

feat: Add Docker container startup for Cashu daemon in wallet integration test script

chore: Update Docker image to use Docker Hub repository

feat: Add cleanup trap to stop Docker container and unset variables

feat: Add initial test stub for nutshell wallet mint functionality

test: Add Cashu wallet mint integration test

feat: Add just command for nutshell wallet integration test

refactor: Organize imports and improve code formatting in nutshell wallet test

fix: Update Cashu Docker image and test URL for correct container access

fix: Update Docker container name and image for Cashu wallet test script

fix: Handle Docker container name conflict in nutshell wallet integration test

fix: Update Docker image to cashubtc/nutshell:latest in wallet integration test script

feat: Add support for running separate Nutshell mint and wallet containers

feat: Update Nutshell mint and wallet container configurations for integration testing

fix: Update wallet port and container configuration in integration test script

chore: Export MINT_URL and WALLET_URL as environment variables

fix: Update invoice creation and state checking in nutshell wallet test

fix: Update MINT_URL to use host.docker.internal for container access

fix: Update nutshell wallet mint test to handle invoice payment state

refactor: Improve Nutshell wallet test with better error handling and robustness

refactor: Improve code formatting and logging in nutshell wallet test

refactor: Replace anyhow with expect for error handling in Nutshell wallet test

refactor: Simplify error handling in Nutshell wallet mint test

refactor: Replace `?` with `expect()` in Nutshell wallet test

refactor: Simplify nutshell wallet test by removing unused code and improving error handling

refactor: Extract minting and balance helper functions in nutshell wallet test

feat: Add test for Nutshell wallet token swap functionality

fix: Trim quotes from token in nutshell wallet swap test

refactor: Remove debug print statements and improve code readability

refactor: Improve test_nutshell_wallet_melt with payment state checking and balance verification

refactor: Update Nutshell wallet integration test script configuration

feat: Extract common mint startup function into shared script

refactor: Simplify nutshell wallet integration test script and improve startup process

feat: Add mintd process termination and test status capture in integration test script

refactor: Capitalize env vars and ensure comprehensive cleanup in trap

feat: nutshell wallet test

* ci: Add test step for Nutshell wallet integration tests

* ci: Split Nutshell integration tests into separate jobs

* feat: nutshell wallet test

* ci: Add Docker setup and increase timeout for Nutshell wallet integration tests

* chore: Improve Nutshell wallet integration test script robustness

* fix: Remove -i flag from Nix develop and improve Docker accessibility check

* fix: payment processor

* fix: wallet tests

* feat: Add integration shell with Docker and Rust stable for testing

* ci: Simplify Nutshell wallet integration test workflow and script

* fix: Improve mintd endpoint detection and error handling in integration test script

* fix: wallet tests
2025-03-30 13:08:00 +01:00

296 lines
9.2 KiB
Nix

{
description = "CDK Flake";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs = {
nixpkgs.follows = "nixpkgs";
};
};
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.rust-analyzer-src.follows = "";
};
flake-utils.url = "github:numtide/flake-utils";
crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};
pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
};
outputs = { self, nixpkgs, rust-overlay, flake-utils, pre-commit-hooks, crane, fenix, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
overlays = [ (import rust-overlay) ];
lib = pkgs.lib;
stdenv = pkgs.stdenv;
isDarwin = stdenv.isDarwin;
libsDarwin = with pkgs; lib.optionals isDarwin [
# Additional darwin specific inputs can be set here
darwin.apple_sdk.frameworks.Security
darwin.apple_sdk.frameworks.SystemConfiguration
];
# Dependencies
pkgs = import nixpkgs {
inherit system overlays;
};
# Toolchains
# latest stable
stable_toolchain = pkgs.rust-bin.stable."1.83.0".default.override {
targets = [ "wasm32-unknown-unknown" ]; # wasm
extensions = [ "rustfmt" "clippy" "rust-analyzer" ];
};
# MSRV stable
msrv_toolchain = pkgs.rust-bin.stable."1.75.0".default.override {
targets = [ "wasm32-unknown-unknown" ]; # wasm
};
# Nightly used for formatting
nightly_toolchain = pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.default.override {
extensions = [ "rustfmt" "clippy" "rust-analyzer" "rust-src" ];
targets = [ "wasm32-unknown-unknown" ]; # wasm
});
# Common inputs
envVars = { };
buildInputs = with pkgs; [
# Add additional build inputs here
git
pkg-config
curl
just
protobuf
nixpkgs-fmt
typos
lnd
clightning
bitcoind
sqlx-cli
cargo-outdated
# Needed for github ci
libz
] ++ libsDarwin;
# WASM deps
WASMInputs = with pkgs; [
];
craneLib = crane.mkLib pkgs;
src = craneLib.cleanCargoSource ./.;
# Common arguments can be set here to avoid repeating them later
commonArgs = {
inherit src;
strictDeps = true;
buildInputs = [
# Add additional build inputs here
pkgs.protobuf
pkgs.pkg-config
] ++ lib.optionals pkgs.stdenv.isDarwin [
# Additional darwin specific inputs can be set here
pkgs.libiconv
];
# Additional environment variables can be set directly
# MY_CUSTOM_VAR = "some value";
PROTOC = "${pkgs.protobuf}/bin/protoc";
PROTOC_INCLUDE = "${pkgs.protobuf}/include";
};
craneLibLLvmTools = craneLib.overrideToolchain
(fenix.packages.${system}.complete.withComponents [
"cargo"
"llvm-tools"
"rustc"
]);
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
individualCrateArgs = commonArgs // {
inherit cargoArtifacts;
inherit (craneLib.crateNameFromCargoToml { inherit src; }) version;
# NB: we disable tests since we'll run them all via cargo-nextest
doCheck = false;
};
fileSetForCrate = crate: lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions [
./Cargo.toml
./Cargo.lock
(craneLib.fileset.commonCargoSources ./crates/cdk)
(craneLib.fileset.commonCargoSources ./crates/cdk-axum)
(craneLib.fileset.commonCargoSources ./crates/cdk-cln)
(craneLib.fileset.commonCargoSources ./crates/cdk-lnd)
(craneLib.fileset.commonCargoSources ./crates/cdk-fake-wallet)
(craneLib.fileset.commonCargoSources ./crates/cdk-lnbits)
(craneLib.fileset.commonCargoSources ./crates/cdk-redb)
(craneLib.fileset.commonCargoSources ./crates/cdk-sqlite)
./crates/cdk-sqlite/src/mint/migrations
./crates/cdk-sqlite/src/wallet/migrations
(craneLib.fileset.commonCargoSources crate)
];
};
cdk-mintd = craneLib.buildPackage (individualCrateArgs // {
pname = "cdk-mintd";
name = "cdk-mintd-${individualCrateArgs.version}";
cargoExtraArgs = "-p cdk-mintd";
src = fileSetForCrate ./crates/cdk-mintd;
});
nativeBuildInputs = with pkgs; [
#Add additional build inputs here
] ++ lib.optionals isDarwin [
# Additional darwin specific native inputs can be set here
];
in
{
checks = {
# Pre-commit checks
pre-commit-check =
let
# this is a hack based on https://github.com/cachix/pre-commit-hooks.nix/issues/126
# we want to use our own rust stuff from oxalica's overlay
_rust = pkgs.rust-bin.stable.latest.default;
rust = pkgs.buildEnv {
name = _rust.name;
inherit (_rust) meta;
buildInputs = [ pkgs.makeWrapper ];
paths = [ _rust ];
pathsToLink = [ "/" "/bin" ];
postBuild = ''
for i in $out/bin/*; do
wrapProgram "$i" --prefix PATH : "$out/bin"
done
'';
};
in
pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks = {
rustfmt = {
enable = true;
entry = lib.mkForce "${rust}/bin/cargo-fmt fmt --all -- --config format_code_in_doc_comments=true --check --color always";
};
nixpkgs-fmt.enable = true;
typos.enable = true;
commitizen.enable = true; # conventional commits
};
};
};
packages = {
inherit cdk-mintd;
default = cdk-mintd;
} // lib.optionalAttrs (!pkgs.stdenv.isDarwin) {
my-workspace-llvm-coverage = craneLibLLvmTools.cargoLlvmCov (commonArgs // {
inherit cargoArtifacts;
});
};
apps = {
cdk-mintd = flake-utils.lib.mkApp {
drv = cdk-mintd;
};
};
devShells =
let
# pre-commit-checks
_shellHook = (self.checks.${system}.pre-commit-check.shellHook or "");
# devShells
msrv = pkgs.mkShell ({
shellHook = "
${_shellHook}
cargo update
cargo update -p async-compression --precise 0.4.3
cargo update -p zstd-sys --precise 2.0.8+zstd.1.5.5
cargo update -p flate2 --precise 1.0.35
cargo update -p home --precise 0.5.5
cargo update -p zerofrom --precise 0.1.5
cargo update -p half --precise 2.4.1
cargo update -p url --precise 2.5.2
# For wasm32-unknown-unknown target
cargo update -p triomphe --precise 0.1.11
";
buildInputs = buildInputs ++ WASMInputs ++ [ msrv_toolchain ];
inherit nativeBuildInputs;
} // envVars);
stable = pkgs.mkShell ({
shellHook = ''${_shellHook}'';
buildInputs = buildInputs ++ WASMInputs ++ [ stable_toolchain ];
inherit nativeBuildInputs;
} // envVars);
nightly = pkgs.mkShell ({
shellHook = ''
${_shellHook}
# Needed for github ci
export LD_LIBRARY_PATH=${pkgs.lib.makeLibraryPath [
pkgs.zlib
]}:$LD_LIBRARY_PATH
export RUST_SRC_PATH=${nightly_toolchain}/lib/rustlib/src/rust/library
'';
buildInputs = buildInputs ++ [ nightly_toolchain ];
inherit nativeBuildInputs;
} // envVars);
# Shell with Docker for integration tests
integration = pkgs.mkShell ({
shellHook = ''
${_shellHook}
# Ensure Docker is available
if ! command -v docker &> /dev/null; then
echo "Docker is not installed or not in PATH"
echo "Please install Docker to run integration tests"
exit 1
fi
echo "Docker is available at $(which docker)"
echo "Docker version: $(docker --version)"
'';
buildInputs = buildInputs ++ [
stable_toolchain
pkgs.docker-client
];
inherit nativeBuildInputs;
} // envVars);
in
{
inherit msrv stable nightly integration;
default = stable;
};
}
);
}