From cd438cc5e767b21fd956672e8814685d14f40bee Mon Sep 17 00:00:00 2001 From: amackillop Date: Tue, 9 Jun 2026 07:42:21 -0700 Subject: [PATCH] Add dev shell flake and justfile for local checks Introduce a Nix dev shell and a justfile so work on this fork has a reproducible toolchain and a one-command local gate, mirroring the setup in the ldk-node repo. The toolchain is pinned to stable 1.90.0 via fenix rather than tracking latest. The version is bounded on both ends: clippy must be at least 1.87 so ci/check-lint.sh can resolve the lint names it allows (older clippy hard-errors on the unknown clippy::manual_is_multiple_of), but 1.92+ adds clippy::assertions_on_constants which fires on existing code in lightning/src/chain/channelmonitor.rs and would break -D warnings on the inherited tree. 1.90.0 sits in that window and matches what CI's stable resolves to today. fenix is used over rust-overlay because it pins an exact channel by hash, so the shell can't drift. just check only compiles and runs the workspace test suite. It deliberately skips clippy and rustfmt: this branch is not clean under either of CI's gates (pre-existing dead code in lsps2/lsps4 trips check-lint.sh's -D warnings, and the tree predates the pinned rustfmt), and reformatting or de-linting code we don't own is out of scope. --- .envrc | 1 + flake.lock | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 85 +++++++++++++++++++++++++++++++++++++++++++++ justfile | 14 ++++++++ 4 files changed, 200 insertions(+) create mode 100644 .envrc create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 justfile diff --git a/.envrc b/.envrc new file mode 100644 index 00000000000..3550a30f2de --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000000..832c92f6e26 --- /dev/null +++ b/flake.lock @@ -0,0 +1,100 @@ +{ + "nodes": { + "fenix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "rust-analyzer-src": "rust-analyzer-src" + }, + "locked": { + "lastModified": 1780999471, + "narHash": "sha256-rY4yNlSzDY3OoYBdgjwlpVKWY/oUeOb65709i/tJbns=", + "owner": "nix-community", + "repo": "fenix", + "rev": "db976d430cbb6b0d6b300b4e22cbb28462841af2", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1764521362, + "narHash": "sha256-M101xMtWdF1eSD0xhiR8nG8CXRlHmv6V+VoY65Smwf4=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "871b9fd269ff6246794583ce4ee1031e1da71895", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "25.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "fenix": "fenix", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "rust-analyzer-src": { + "flake": false, + "locked": { + "lastModified": 1780924205, + "narHash": "sha256-5s6nPSNU1Mo/Qy90XxCTNj6/rB70zgX8VqleTdLoESA=", + "owner": "rust-lang", + "repo": "rust-analyzer", + "rev": "4fde9dd9822df453dc6f20149b8e375efbbe66c0", + "type": "github" + }, + "original": { + "owner": "rust-lang", + "ref": "nightly", + "repo": "rust-analyzer", + "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 00000000000..0f7a38e46cb --- /dev/null +++ b/flake.nix @@ -0,0 +1,85 @@ +{ + description = "Rust Lightning Development Environment"; + + inputs = { + # Nixpkgs channel. New channels are released every 6 months. + # See: https://github.com/NixOS/nixpkgs/tags + nixpkgs.url = "github:nixos/nixpkgs/25.11"; + + # This makes it easy for the flake to be multi-platform. + # See: https://github.com/numtide/flake-utils + flake-utils.url = "github:numtide/flake-utils"; + + # Provides pinned Rust toolchains. + # See: https://github.com/nix-community/fenix + fenix = { + url = "github:nix-community/fenix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = + { + self, + nixpkgs, + flake-utils, + fenix, + }: + flake-utils.lib.eachDefaultSystem ( + system: + let + pkgs = import nixpkgs { inherit system; }; + + # Pinned stable toolchain. The version is deliberately bounded: + # * clippy must be >= 1.87 so `./ci/check-lint.sh` resolves the lints it + # `-A`s (e.g. `clippy::manual_is_multiple_of`); older clippy E0602s on the + # unknown lint name. + # * but NOT 1.92+, whose clippy grows `assertions_on_constants` (fires on + # `assert!(cfg!(fuzzing), ..)` in lightning/src/chain/channelmonitor.rs) + # and would break `-D warnings` on the pre-existing tree. + # 1.90.0 sits in that window and matches what CI's `stable` resolves to. + rust-toolchain = + (fenix.packages.${system}.toolchainOf { + channel = "1.90.0"; + sha256 = "sha256-SJwZ8g0zF2WrKDVmHrVG3pD2RGoQeo24MEXnNx5FyuI="; + }).withComponents + [ + "rustc" + "cargo" + "clippy" + "rustfmt" + "rust-src" # Needed for the rust-analyzer extension to work. + ]; + in + { + # The default development shell. Use `nix develop` or direnv to enter it. + devShells.default = pkgs.mkShell { + name = "rust-lightning-dev-shell"; + + packages = [ + rust-toolchain + ] + ++ (with pkgs; [ + just # Command runner + nodejs # JavaScript runtime, required for MCP tools + mold # Fast linker for Rust/C/C++ + pnpm # Package manager for JavaScript, required for MCP tools + stdenv.cc.cc.lib # C++ standard library for runtime + ]); + + env = { + # OpenSSL configuration for Nix + PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig"; + # C++ standard library path for runtime + LD_LIBRARY_PATH = "${pkgs.stdenv.cc.cc.lib}/lib"; + }; + + shellHook = '' + echo "Rust Lightning dev shell" + rustc --version + cargo --version + ''; + }; + } + ); +} diff --git a/justfile b/justfile new file mode 100644 index 00000000000..ad4ad0626f5 --- /dev/null +++ b/justfile @@ -0,0 +1,14 @@ +default: + @just --list --unsorted + +# Run all code quality checks. TODO: Add format and linting when branch is clean +check: + RUSTFLAGS="--cfg=lsps1_service" cargo test --workspace + +# Run just the tests +test: + RUSTFLAGS="--cfg=lsps1_service" cargo test --workspace + +# Format all sources in place. +fmt: + cargo fmt --all