Skip to content

Commit e13d87d

Browse files
nix: dev-shell fixes (#9437)
Add the packages required for prebuilt LLVM to `LD_LIBRARY_PATH`. Also, switch from `stdenvNoCC` to a proper clang/llvm stdenv. --------- Co-authored-by: Ellie Hermaszewska <[email protected]>
1 parent 5981afd commit e13d87d

File tree

1 file changed

+40
-17
lines changed

1 file changed

+40
-17
lines changed

flake.nix

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,44 @@
1414
system:
1515
let
1616
pkgs = import nixpkgs { inherit system; };
17+
llvmPackages = pkgs.llvmPackages_21;
18+
# We want to use Clang instead of GCC because it seems to behave better
19+
# with LLDB, so we use `mkShell` with the LLVM stdenv
20+
mkShell = pkgs.mkShell.override { stdenv = llvmPackages.stdenv; };
21+
# We must use the clangd from `clang-tools` package so that it is
22+
# wrapped properly. This is harder than it seems becase there is a
23+
# clangd in clang-unwrapped, which would normally come first thanks to
24+
# the cc-wrapper/setup-hook adding ${clang-unwrapped}/bin to PATH very
25+
# early in `mkDerivation` setup. We work around this using a shell hook
26+
# (below) as that executes very late in shell instantiation and can
27+
# therefore override cc-wrapper.
28+
#
29+
# See https://github.com/NixOS/nixpkgs/issues/76486 for the upstream bug.
30+
clangd-only = (
31+
pkgs.linkFarm "clangd-only" [
32+
{
33+
name = "bin/clangd";
34+
# New enough to support `HeaderInsertion: Never` in `.clangd`.
35+
path = "${llvmPackages.clang-tools}/bin/clangd";
36+
}
37+
]
38+
);
1739
in
1840
{
19-
# We want to use Clang instead of GCC because it seems to behave better
20-
# with LLDB, so we use `mkShellNoCC` here instead of `mkShell` because
21-
# the latter brings in GCC by default on Linux.
22-
devShell = pkgs.mkShellNoCC {
41+
devShell = mkShell {
2342
buildInputs = [
24-
# We must list clangd before the `clang` package to make sure it
25-
# comes earlier on the `PATH`, and we must get it from the
26-
# `clang-tools` package so that it is wrapped properly.
27-
(pkgs.linkFarm "clangd-21" [
28-
{
29-
name = "bin/clangd";
30-
# New enough to support `HeaderInsertion: Never` in `.clangd`.
31-
path = "${pkgs.llvmPackages_21.clang-tools}/bin/clangd";
32-
}
33-
])
43+
# Pull in only clang-format from clang-tools 17. This matches the
44+
# version used in CI.
3445
(pkgs.linkFarm "clang-format-17" [
3546
{
3647
name = "bin/clang-format";
37-
# Match the clang-format version used in CI.
3848
path = "${pkgs.llvmPackages_17.clang-tools}/bin/clang-format";
3949
}
4050
])
4151

42-
pkgs.clang
4352
pkgs.cmake
4453
pkgs.gersemi
45-
pkgs.lldb
54+
llvmPackages.lldb
4655
pkgs.ninja
4756
pkgs.nixfmt-rfc-style
4857
pkgs.prettier
@@ -51,12 +60,26 @@
5160
pkgs.vulkan-loader # Ensure this gets built to use in library path.
5261
pkgs.xorg.libX11
5362
];
63+
5464
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [
5565
# In addition to this, running the Vulkan tests on Linux distros
5666
# other than NixOS may require the use of nixGL:
5767
# https://github.com/nix-community/nixGL
5868
pkgs.vulkan-loader
69+
# Needed for the prebuilt LLVM
70+
pkgs.libz
71+
pkgs.zstd
72+
# Despite requiring this packages (slang) to be built with Clang,
73+
# the prebuilt libslang-llvm.so is actually linked against GCC's
74+
# libstdc++.so.6
75+
pkgs.stdenv.cc.cc.lib
5976
];
77+
78+
# Use a shell hook to make sure the wrapped clangd is in the path
79+
# before the unwrapped one included by llvmPackages.stdenv
80+
shellHook = ''
81+
PATH="${clangd-only}/bin:$PATH"
82+
'';
6083
};
6184
}
6285
);

0 commit comments

Comments
 (0)