Here is my super simple flake.nix:
{
description = "A template for Nix based C++ project setup.";
inputs = {
# nixpkgs.url = "github:NixOS/nixpkgs/unstable";
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
};
outputs = { self, nixpkgs }: {
defaultPackage.x86_64-linux =
# Notice the reference to nixpkgs here.
with import nixpkgs { system = "x86_64-linux"; };
stdenv.mkDerivation {
name = "llvm-env";
src = self;
# where to find libgcc
NIX_LDFLAGS="-L${gccForLibs}/lib/gcc/${targetPlatform.config}/${gccForLibs.version}";
# teach clang about C startup file locations
CFLAGS="-B${gccForLibs}/lib/gcc/${targetPlatform.config}/${gccForLibs.version} -B ${stdenv.cc.libc}/lib";
cmakeFlags = [
"-DC_INCLUDE_DIRS=${stdenv.cc.libc.dev}/include"
"-GNinja"
# Debug for debug builds
"-DCMAKE_BUILD_TYPE=Release"
# inst will be our installation prefix
"-DCMAKE_INSTALL_PREFIX=../inst"
"-DLLVM_INSTALL_TOOLCHAIN_ONLY=ON"
# change this to enable the projects you need
"-DLLVM_ENABLE_PROJECTS=clang"
# enable libcxx* to come into play at runtimes
"-DLLVM_ENABLE_RUNTIMES=libcxx;libcxxabi;libunwind"
# this makes llvm only to produce code for the current platform, this saves CPU time, change it to what you need
"-DLLVM_TARGETS_TO_BUILD=host"
];
};
};
}
I run
nix develop --extra-experimental-features "nix-command flakes"
Then follow the steps in this guide to build clang: https://nixos.wiki/wiki/LLVM
However I keep running into “undefined reference to `__isoc23_strtoull’”. I checked and this comes from the libc.so library…
My C_INCLUDE_DIRS are /nix/store/ij144ma6vs8acil8r9hgr8xkb1dp9azg-glibc-2.39-5-dev/include
The library libc.so is located at /nix/store/35pq4hr29c3sl79lgfwgsvd9nwzyp4am-glibc-2.39-5/lib/libc.so
I tried updating LIBRARY_PATH / LD_LIBRARY_PATH to that location but it caused more build issues.
Any ideas on how to fix this?