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
13 changes: 13 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -euo pipefail

nix fmt . 2>/dev/null

changed=$(git diff --name-only)
if [ -n "$changed" ]; then
echo "nix fmt modified files:"
echo "$changed"
echo ""
echo "Stage the changes and retry your commit."
exit 1
fi
21 changes: 5 additions & 16 deletions .github/workflows/depends.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,8 @@ jobs:
run: nix flake check

- name: Build bitcoin from depends
run: |
nix develop .#depends --command bash -c "
set -eux

export CCACHE_DIR=${{ env.CCACHE_DIR }}
export SOURCES_PATH=${{ env.SOURCES_PATH }}
export BASE_CACHE=${{ env.BASE_CACHE }}

cd bitcoin
HOST_TRIPLET=\$(./depends/config.guess)
export HOST_TRIPLET
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
"
env:
CCACHE_DIR: ${{ env.CCACHE_DIR }}
SOURCES_PATH: ${{ env.SOURCES_PATH }}
BASE_CACHE: ${{ env.BASE_CACHE }}
run: nix develop .#depends --command ./scripts/build-depends.sh
18 changes: 3 additions & 15 deletions .github/workflows/nix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ jobs:
cores: 4
cmake_flags:
- system: x86_64-darwin
runner_label: macos-15-intel
cores: 4
runner_label: macos-latest
cores: 3
cmake_flags: -DWITH_USDT=OFF
- system: aarch64-darwin
runner_label: macos-latest
Expand Down Expand Up @@ -85,16 +85,4 @@ jobs:
run: nix flake check

- name: Build bitcoind
run: |
nix develop --command bash -c "
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${{ matrix.cores }}
ccache --show-stats
"
run: nix develop --command ./scripts/build-systemlibs.sh ${{ matrix.cores }} ${{ matrix.cmake_flags }}
6 changes: 3 additions & 3 deletions flake.lock

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

59 changes: 25 additions & 34 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,6 @@
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;
Expand All @@ -57,6 +43,19 @@
}
'';

patchelf-releases = pkgs.writeShellApplication {
name = "patchelf-releases";
runtimeInputs = with pkgs; [
patchelf
file
findutils
gnugrep
];
text = builtins.replaceStrings [ "@interp@" ] [ "${pkgs.glibc}/lib/ld-linux-x86-64.so.2" ] (
builtins.readFile ./scripts/patchelf-releases.sh
);
};

stdEnv =
let
llvmStdenv =
Expand All @@ -69,10 +68,10 @@
else
llvmPackages.stdenv;
in
if isLinux then
pkgs.stdenvAdapters.useMoldLinker (pkgs.ccacheStdenv.override { stdenv = llvmStdenv; })
else
pkgs.ccacheStdenv.override { stdenv = llvmStdenv; };
let
moldStdenv = if isLinux then pkgs.stdenvAdapters.useMoldLinker llvmStdenv else llvmStdenv;
in
pkgs.ccacheStdenv.override { stdenv = moldStdenv; };

pythonEnv = python.withPackages (
ps:
Expand All @@ -84,7 +83,6 @@
pyzmq
pycapnp
requests
vulture
]
++ lib.optionals isLinux [
bcc
Expand All @@ -108,17 +106,11 @@
pkgs.linuxPackages.bpftrace
];

qtBuildInputs = [
pkgs.qt6.qtbase # https://nixos.org/manual/nixpkgs/stable/#sec-language-qt
pkgs.qt6.qttools
];

# Will exist in the runtime environment
buildInputs = [
pkgs.boost
pkgs.capnproto
pkgs.libevent
pkgs.qrencode
pkgs.sqlite.dev
pkgs.zeromq
];
Expand All @@ -132,13 +124,15 @@
packages = [
clang-tidy-diff
pkgs.codespell
pkgs.doxygen
pkgs.hexdump
pkgs.include-what-you-use
pkgs.ruff
pkgs.ty
pythonEnv
]
++ lib.optionals isLinux [
patchelf-releases
pkgs.gdb
pkgs.valgrind
]
Expand All @@ -148,18 +142,15 @@
CMAKE_EXPORT_COMPILE_COMMANDS = 1;
LD_LIBRARY_PATH = lib.makeLibraryPath [ pkgs.capnproto ];
LOCALE_ARCHIVE = lib.optionalString isLinux "${pkgs.glibcLocales}/lib/locale/locale-archive";
# Force depends capnp to also use clang, otherwise it fails when
# looking for the default (gcc/g++)
build_CC = "clang";
build_CXX = "clang++";
};
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++";
});
devShells.default = mkDevShell nativeBuildInputs buildInputs;
devShells.depends = mkDevShell nativeBuildInputs [ ];
formatter = pkgs.nixfmt-tree;
}
);
Expand Down
23 changes: 23 additions & 0 deletions scripts/build-depends.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash
set -euo pipefail

cd bitcoin

# Nix sets CC/CXX to bare names (e.g. 'clang'), relying on PATH. The depends
# Makefile substitutes these into toolchain.cmake, but cmake's find_program
# searches system dirs before PATH, so a bare 'clang' resolves to the system
# compiler instead of the Nix one. This causes glibc version mismatches:
# objects compiled against Nix's newer glibc headers reference fortified
# symbols (e.g. __inet_pton_chk) absent from the runner's older glibc.
NIX_CC=$(command -v "$CC")
NIX_CXX=$(command -v "$CXX")

HOST_TRIPLET=$(./depends/config.guess)

make -C depends "-j$(nproc)" NO_QT=1 \
CC="$NIX_CC" CXX="$NIX_CXX" \
build_CC="$NIX_CC" build_CXX="$NIX_CXX"

cmake -B build --toolchain "depends/$HOST_TRIPLET/toolchain.cmake"
cmake --build build "-j$(nproc)"
ccache --show-stats
16 changes: 16 additions & 0 deletions scripts/build-systemlibs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
set -euo pipefail

CORES=${1:?usage: build-systemlibs.sh <cores> [cmake_flags...]}
shift
CMAKE_FLAGS=("$@")

cd bitcoin
cmake -B build \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
--preset dev-mode \
-DBUILD_GUI=OFF \
"${CMAKE_FLAGS[@]}"
cmake --build build "-j$CORES"
ccache --show-stats
24 changes: 24 additions & 0 deletions scripts/patchelf-releases.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
INTERP="@interp@"

if [ -z "${PREVIOUS_RELEASES_DIR:-}" ]; then
echo "error: PREVIOUS_RELEASES_DIR is not set" >&2
exit 1
fi

if [ ! -f "$INTERP" ]; then
echo "error: interpreter not found: $INTERP" >&2
exit 1
fi

echo "Using interpreter: $INTERP"

count=0
while IFS= read -r -d '' bin; do
if file "$bin" | grep -q 'ELF.*dynamically linked'; then
patchelf --set-interpreter "$INTERP" "$bin"
echo " patched: ${bin#"$PREVIOUS_RELEASES_DIR"/}"
count=$((count + 1))
fi
done < <(find "$PREVIOUS_RELEASES_DIR" -path '*/bin/*' -type f -print0)

echo "Patched $count binaries."
Loading