Skip to content

Commit 2339ee4

Browse files
committed
feat: add a depends only devshell
Add a depends devshell. This shell only includes packages needed for doing a depends build and some basic debugging tools. This needs to be a separate shell because depends building will fail if there are system packages installed. Conceptually, its also cleaner to only include the necessary dependencies for a depends build since this is precisely the scenario in which depends is useful.
1 parent 6827cc7 commit 2339ee4

1 file changed

Lines changed: 59 additions & 29 deletions

File tree

flake.nix

Lines changed: 59 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,17 @@
4747
bcc
4848
]);
4949

50-
# Will only exist in the build environment
51-
nativeBuildInputs = with pkgs;
50+
# USDT is only supported on linux
51+
usdtPkgs = with pkgs;
52+
platformPkgs isLinux [
53+
libsystemtap
54+
linuxPackages.bcc
55+
linuxPackages.bpftrace
56+
];
57+
58+
# Will only exist in the build environment and includes everything needed
59+
# for a depends build
60+
dependsNativeBuildInputs = with pkgs;
5261
[
5362
bison
5463
ccache
@@ -59,16 +68,16 @@
5968
llvmTools.clang-tools
6069
ninja
6170
pkg-config
62-
qt6.wrapQtAppsHook # https://nixos.org/manual/nixpkgs/stable/#sec-language-qt
6371
xz
6472
]
65-
++ platformPkgs isLinux [
66-
libsystemtap
67-
linuxPackages.bcc
68-
linuxPackages.bpftrace
73+
++ usdtPkgs;
74+
nativeBuildInputs = with pkgs;
75+
dependsNativeBuildInputs
76+
++ [
77+
qt6.wrapQtAppsHook # https://nixos.org/manual/nixpkgs/stable/#sec-language-qt
6978
];
7079

71-
# Will exist in the runtime environment
80+
# Will exist in the runtime environment - not needed for a depends build
7281
buildInputs = with pkgs;
7382
[
7483
boost
@@ -80,11 +89,7 @@
8089
sqlite.dev
8190
zeromq
8291
]
83-
++ platformPkgs isLinux [
84-
libsystemtap
85-
linuxPackages.bcc
86-
linuxPackages.bpftrace
87-
];
92+
++ usdtPkgs;
8893

8994
env = {
9095
CMAKE_GENERATOR = "Ninja";
@@ -93,22 +98,47 @@
9398
};
9499
in {
95100
# We use mkShelNoCC to avoid having Nix set up a gcc-based build environment
96-
devShells.default = pkgs.mkShellNoCC {
97-
inherit nativeBuildInputs buildInputs;
98-
packages =
99-
[
100-
pythonEnv
101-
pkgs.codespell
102-
pkgs.hexdump
103-
]
104-
++ platformPkgs isLinux [pkgs.gdb]
105-
++ platformPkgs isDarwin [llvmTools.lldb];
106-
107-
shellHook = ''
108-
# This can likely be removed if https://github.com/bitcoin/bitcoin/pull/32678 is merged
109-
unset SOURCE_DATE_EPOCH
110-
'';
111-
inherit (env) CMAKE_GENERATOR LD_LIBRARY_PATH LOCALE_ARCHIVE;
101+
devShells = {
102+
default = pkgs.mkShellNoCC {
103+
inherit nativeBuildInputs buildInputs;
104+
packages =
105+
[
106+
pythonEnv
107+
pkgs.codespell
108+
pkgs.hexdump
109+
]
110+
++ platformPkgs isLinux [pkgs.gdb]
111+
++ platformPkgs isDarwin [llvmTools.lldb];
112+
113+
inherit (env) CMAKE_GENERATOR LD_LIBRARY_PATH LOCALE_ARCHIVE;
114+
};
115+
# TODO: this could be ported to a gcc shell in the future to bring this closer in line
116+
# with our guix depends build. This would allow us to remove the shellHook hack that shims
117+
# in clang to masquerade as gcc
118+
depends = pkgs.mkShellNoCC {
119+
nativeBuildInputs = dependsNativeBuildInputs;
120+
buildInputs = usdtPkgs;
121+
shellHook = ''
122+
# having SOURCE_DATE_EPOCH set can interfere with the guix
123+
# build system, so we unset this in the depends devshell
124+
unset SOURCE_DATE_EPOCH
125+
126+
# its not super easy to override compiler defaults in
127+
# depends, so as a hack we just shim in clang and pretend
128+
# its gcc. this is done in a tmp dir to avoid polluting the
129+
# users shell and is cleaned up when the shell is exited.
130+
TMP_GCC_SHIM=$(mktemp -d "$TMPDIR/clang-shim.XXXXXX")
131+
132+
ln -sf $(command -v clang++) "$TMP_GCC_SHIM/g++"
133+
ln -sf $(command -v clang) "$TMP_GCC_SHIM/gcc"
134+
135+
export PATH="$TMP_GCC_SHIM:$PATH"
136+
echo "Using fake gcc/g++ -> clang in: $TMP_GCC_SHIM"
137+
138+
trap "rm -rf $TMP_GCC_SHIM" EXIT
139+
'';
140+
inherit (env) CMAKE_GENERATOR LOCALE_ARCHIVE;
141+
};
112142
};
113143

114144
formatter = pkgs.alejandra;

0 commit comments

Comments
 (0)