diff --git a/.github/workflows/depends.yml b/.github/workflows/depends.yml index 65cbd85..c8e5760 100644 --- a/.github/workflows/depends.yml +++ b/.github/workflows/depends.yml @@ -19,6 +19,7 @@ jobs: CCACHE_DIR: ${{ github.workspace }}/.ccache SOURCES_PATH: ${{ github.workspace }}/depends-sources BASE_CACHE: ${{ github.workspace }}/depends-base + NIX_SHOW_LOG: "1" steps: - name: Checkout Repo @@ -27,8 +28,8 @@ jobs: - name: Checkout Bitcoin Repo uses: actions/checkout@v4 with: - repository: willcl-ark/bitcoin - ref: cmake-dependency-provider + repository: bitcoin/bitcoin + ref: master path: bitcoin fetch-depth: 1 @@ -80,7 +81,7 @@ jobs: - name: Build bitcoin from depends run: | - nix develop --command bash -c " + nix develop .#depends --command bash -c " set -eux export CCACHE_DIR=${{ env.CCACHE_DIR }} @@ -90,8 +91,8 @@ jobs: cd bitcoin HOST_TRIPLET=\$(./depends/config.guess) export HOST_TRIPLET - make -C depends -j\$(nproc) NO_QT=1 - cmake -B build --toolchain \"depends/\$HOST_TRIPLET/toolchain.cmake\" -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=\"depends/\$HOST_TRIPLET/dependency_provider.cmake\" + make -C depends -j\$(nproc) NO_QT=1 build_CC="$CC" build_CXX="$CXX" + cmake -B build --toolchain \"depends/\$HOST_TRIPLET/toolchain.cmake\" cmake --build build -j\$(nproc) ccache --show-stats " diff --git a/.github/workflows/fmt.yml b/.github/workflows/fmt.yml index c25d368..511a70c 100644 --- a/.github/workflows/fmt.yml +++ b/.github/workflows/fmt.yml @@ -33,8 +33,8 @@ jobs: - name: Check formatting run: | - if ! nix run nixpkgs#alejandra -- --check .; then - nix run nixpkgs#alejandra -- . + if ! nix run nixpkgs#nixfmt-tree .; then + nix run nixpkgs#nixfmt-tree . git diff exit 1 fi diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml index 8407f60..61120cb 100644 --- a/.github/workflows/nix.yml +++ b/.github/workflows/nix.yml @@ -21,19 +21,24 @@ jobs: include: - system: x86_64-linux runner_label: ubuntu-latest + cores: 4 cmake_flags: - system: aarch64-linux runner_label: ubuntu-24.04-arm + cores: 4 cmake_flags: - system: x86_64-darwin - runner_label: macos-13 + runner_label: macos-15-intel + cores: 4 cmake_flags: -DWITH_USDT=OFF - system: aarch64-darwin - runner_label: macos-14 + runner_label: macos-latest + cores: 3 cmake_flags: -DWITH_USDT=OFF env: CCACHE_DIR: ${{ github.workspace }}/.ccache + NIX_SHOW_LOG: "1" steps: - name: Checkout Repo @@ -85,7 +90,11 @@ jobs: set -eux export CCACHE_DIR=${{ env.CCACHE_DIR }} cd bitcoin - cmake -B build -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache --preset dev-mode ${{ matrix.cmake_flags }} - cmake --build build -j$(nproc) + cmake -B build \ + -DCMAKE_C_COMPILER_LAUNCHER=ccache \ + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ + --preset dev-mode \ + ${{ matrix.cmake_flags }} + cmake --build build -j${{ matrix.cores }} ccache --show-stats " diff --git a/flake.lock b/flake.lock index ec4cfca..6714924 100644 --- a/flake.lock +++ b/flake.lock @@ -20,16 +20,16 @@ }, "nixpkgs": { "locked": { - "lastModified": 1748889542, - "narHash": "sha256-Hb4iMhIbjX45GcrgOp3b8xnyli+ysRPqAgZ/LZgyT5k=", + "lastModified": 1768886240, + "narHash": "sha256-C2TjvwYZ2VDxYWeqvvJ5XPPp6U7H66zeJlRaErJKoEM=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "10d7f8d34e5eb9c0f9a0485186c1ca691d2c5922", + "rev": "80e4adbcf8992d3fd27ad4964fbb84907f9478b0", "type": "github" }, "original": { "owner": "NixOS", - "ref": "nixos-25.05", + "ref": "nixos-unstable", "repo": "nixpkgs", "type": "github" } diff --git a/flake.nix b/flake.nix index adef51a..fcf531c 100644 --- a/flake.nix +++ b/flake.nix @@ -2,110 +2,165 @@ description = "Bitcoin development environment with tools for building, testing, and debugging"; inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; flake-utils.url = "github:numtide/flake-utils"; }; - outputs = { - nixpkgs, - flake-utils, - ... - }: - flake-utils.lib.eachDefaultSystem (system: let - pkgs = import nixpkgs {inherit system;}; - isLinux = pkgs.stdenv.isLinux; - isDarwin = pkgs.stdenv.isDarwin; - lib = pkgs.lib; + outputs = + { + nixpkgs, + flake-utils, + ... + }: + flake-utils.lib.eachDefaultSystem ( + system: + let + pkgs = import nixpkgs { + inherit system; + overlays = [ + (final: prev: { + capnproto = prev.capnproto.overrideAttrs (oldAttrs: rec { + version = "1.3.0"; + src = prev.fetchFromGitHub { + owner = "capnproto"; + repo = "capnproto"; + rev = "v${version}"; + hash = "sha256-fvZzNDBZr73U+xbj1LhVj1qWZyNmblKluh7lhacV+6I="; + }; + patches = [ ]; + }); + }) + ]; + }; + inherit (pkgs) lib; + inherit (pkgs.stdenv) isLinux isDarwin; - # Configure LLVM and python version for the environment - llvmVersion = "20"; - pythonVersion = "13"; + python = pkgs.python313; + llvmPackages = pkgs.llvmPackages_latest; - llvmPackages = pkgs."llvmPackages_${llvmVersion}"; - llvmTools = { - inherit (llvmPackages) bintools clang clang-tools; - lldb = pkgs."lldb_${llvmVersion}"; - }; + clang-tidy-diff = + pkgs.runCommand "clang-tidy-diff" + { + nativeBuildInputs = [ pkgs.makeWrapper ]; + } + '' + mkdir -p $out/bin + cp ${llvmPackages.clang-unwrapped.src}/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py \ + $out/bin/clang-tidy-diff + chmod +x $out/bin/clang-tidy-diff + wrapProgram $out/bin/clang-tidy-diff \ + --prefix PATH : ${ + lib.makeBinPath [ + pkgs.clang-tools + pythonEnv + ] + } + ''; - # Helper for platform-specific packages - platformPkgs = cond: pkgs: - if cond - then pkgs - else []; + stdEnv = + let + llvmStdenv = + if isLinux then + llvmPackages.stdenv.override { + cc = llvmPackages.stdenv.cc.override { + bintools = llvmPackages.bintools; + }; + } + else + llvmPackages.stdenv; + in + if isLinux then + pkgs.stdenvAdapters.useMoldLinker (pkgs.ccacheStdenv.override { stdenv = llvmStdenv; }) + else + pkgs.ccacheStdenv.override { stdenv = llvmStdenv; }; - # Use a single pythonEnv throughout and specifically in the devShell to make sure bcc is available. - pythonEnv = pkgs."python3${pythonVersion}".withPackages (ps: - with ps; + pythonEnv = python.withPackages ( + ps: + with ps; [ flake8 lief mypy pyzmq + pycapnp + requests vulture ] - ++ platformPkgs isLinux [ + ++ lib.optionals isLinux [ bcc - ]); + ] + ); - # Will only exist in the build environment - nativeBuildInputs = with pkgs; - [ - bison - ccache - cmake - curlMinimal - llvmTools.bintools - llvmTools.clang - llvmTools.clang-tools - ninja - pkg-config - qt6.wrapQtAppsHook # https://nixos.org/manual/nixpkgs/stable/#sec-language-qt - xz + # Will only exist in the build environment + nativeBuildInputs = [ + pkgs.bison + pkgs.ccache + pkgs.clang-tools + pkgs.cmakeCurses + pkgs.curlMinimal + pkgs.ninja + pkgs.pkg-config + pkgs.xz ] - ++ platformPkgs isLinux [ - libsystemtap - linuxPackages.bcc - linuxPackages.bpftrace + ++ lib.optionals isLinux [ + pkgs.libsystemtap + pkgs.linuxPackages.bcc + pkgs.linuxPackages.bpftrace ]; - # Will exist in the runtime environment - buildInputs = with pkgs; - [ - boost - capnproto - libevent - qrencode - qt6.qtbase # https://nixos.org/manual/nixpkgs/stable/#sec-language-qt - qt6.qttools - sqlite.dev - zeromq - ] - ++ platformPkgs isLinux [ - libsystemtap - linuxPackages.bcc - linuxPackages.bpftrace + qtBuildInputs = [ + pkgs.qt6.qtbase # https://nixos.org/manual/nixpkgs/stable/#sec-language-qt + pkgs.qt6.qttools ]; - env = { - CMAKE_GENERATOR = "Ninja"; - LD_LIBRARY_PATH = lib.makeLibraryPath [pkgs.capnproto]; - LOCALE_ARCHIVE = lib.optionalString isLinux "${pkgs.glibcLocales}/lib/locale/locale-archive"; - }; - in { - # We use mkShelNoCC to avoid having Nix set up a gcc-based build environment - devShells.default = pkgs.mkShellNoCC { - inherit nativeBuildInputs buildInputs; - packages = - [ - pythonEnv - pkgs.codespell - pkgs.hexdump - ] - ++ platformPkgs isLinux [pkgs.gdb] - ++ platformPkgs isDarwin [llvmTools.lldb]; - inherit (env) CMAKE_GENERATOR LD_LIBRARY_PATH LOCALE_ARCHIVE; - }; + # Will exist in the runtime environment + buildInputs = [ + pkgs.boost + pkgs.capnproto + pkgs.libevent + pkgs.qrencode + pkgs.sqlite.dev + pkgs.zeromq + ]; + + mkDevShell = + nativeInputs: buildInputs: + (pkgs.mkShell.override { stdenv = stdEnv; }) { + nativeBuildInputs = nativeInputs; + inherit buildInputs; + hardeningDisable = lib.optionals isDarwin [ "stackclashprotection" ]; + packages = [ + clang-tidy-diff + pkgs.codespell + pkgs.hexdump + pkgs.include-what-you-use + pkgs.ruff + pkgs.ty + pythonEnv + ] + ++ lib.optionals isLinux [ + pkgs.gdb + pkgs.valgrind + ] + ++ lib.optionals isDarwin [ llvmPackages.lldb ]; - formatter = pkgs.alejandra; - }); + CMAKE_GENERATOR = "Ninja"; + CMAKE_EXPORT_COMPILE_COMMANDS = 1; + LD_LIBRARY_PATH = lib.makeLibraryPath [ pkgs.capnproto ]; + LOCALE_ARCHIVE = lib.optionalString isLinux "${pkgs.glibcLocales}/lib/locale/locale-archive"; + }; + in + { + devShells.default = mkDevShell nativeBuildInputs ( + buildInputs ++ qtBuildInputs ++ [ pkgs.qt6.wrapQtAppsHook ] + ); + devShells.depends = (mkDevShell nativeBuildInputs qtBuildInputs).overrideAttrs (oldAttrs: { + # Set these to force depends capnp to also use clang, otherwise it + # fails when looking for the default (gcc/g++) + build_CC = "clang"; + build_CXX = "clang++"; + }); + formatter = pkgs.nixfmt-tree; + } + ); }