Skip to content
Merged
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
11 changes: 6 additions & 5 deletions .github/workflows/depends.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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 }}
Expand All @@ -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
"
4 changes: 2 additions & 2 deletions .github/workflows/fmt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 13 additions & 4 deletions .github/workflows/nix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
"
8 changes: 4 additions & 4 deletions flake.lock

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

223 changes: 139 additions & 84 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
);
}
Loading