On macOS, I’m using llvmPackages_19.clangNoLibcxx, but I’ve tried llvmPackages_19.clangUseLLVM and llvmPackages_19.libcxxClang. I keep getting issues where the standard library headers are not correctly included/found. Also, the linker is replaced automatically which makes some linking fail that expects the default ld.
I thought libcxx was the issue, but even using clangNoLibcxx, I saw that the libcxx derivation from nix was being included rather than the default macOS ones. Any advice? Would very appreciate.
How are you using llvmPackages_19.clangNoLibcxx
? Are you trying to link against the system libc++ instead of the one from nixpkgs?
If you want to replace the toolchain in a stdenv
or dev shell, you need to use overrideCC
to replace the compiler in the stdenv
(or the dev shell’s stdenv
).
I switched back to llvmPackages_19.libcxxClang
; I was trying clangNoLibcxx
to try to use system libc++, but I realized that the issue is actually that llvmPackages_19.clang-tools
clangd is unable to locate headers like cstdint or vector even though its logs contain the following flags.
-cxx-isystem /nix/store/j3dhkx4m14m38drh3f40bccrwrgzlsg5-libcxx-19.1.7-dev/include/c++/v1 -internal-isystem /nix/store/c397xq3dql1js7q2my001jz51fwxk8f2-clang-19.1.7/lib/clang/19/include
libcxxClang
clang does, however, successfully compile C++ programs. But another issue is that libcxxClang
replaces the system ld, and my Rust programs fails to link with ld: library not found for -liconv
.
Linking against the system libc++ with a nixpkgs toolchain isn’t supported. The Darwin SDK removes the headers and text-based stubs for the system libc++ because it is expected that libc++ from nixpkgs will be used. If you need to link the system libc++, the best approach is to use a native toolchain (e.g., via xcodeenv). Another approach would be to use install_name_tool
to change the libc++ reference in the linked binary to system one.
What release are you using? Is there a flake or shell.nix
you can share? The Darwin SDK as of 24.11 includes libiconv. It should no longer be necessary to include it as a buildInput
when building Rust applications.
I see, that makes sense.
I’m on the unstable channel; the flake I have right now is
{
description = "nix-darwin system flake";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
nix-darwin.url = "github:LnL7/nix-darwin";
nix-darwin.inputs.nixpkgs.follows = "nixpkgs";
nix-homebrew.url = "github:zhaofengli-wip/nix-homebrew";
};
outputs =
inputs@{
self,
nix-darwin,
nixpkgs,
nix-homebrew,
}:
let
configuration =
{ pkgs, config, ... }:
let
paths = {
home = "/Users/denniseum";
config = "/Users/denniseum/.config";
};
in
{
environment = {
etc."pam.d/sudo_local".text = ''
auth optional ${pkgs.pam-reattach}/lib/pam/pam_reattach.so ignore_ssh
auth sufficient pam_tid.so
'';
shells = [
pkgs.zsh
];
systemPackages = [
pkgs.appcleaner
pkgs.buf
pkgs.cmake
pkgs.cmake-format
pkgs.cocoapods
pkgs.dafny
pkgs.dotnetCorePackages.dotnet_8.sdk
pkgs.fd
pkgs.fzf
pkgs.go
pkgs.google-chrome
(pkgs.neovim.override {
viAlias = true;
vimAlias = true;
})
pkgs.ninja
pkgs.nixfmt-rfc-style
pkgs.ollama
pkgs.opam
pkgs.pam-reattach
pkgs.python312Full
pkgs.ripgrep
pkgs.rustup
pkgs.slack
pkgs.spotify
pkgs.sqlc
pkgs.tex-fmt
pkgs.texliveFull
pkgs.tmux
pkgs.uv
pkgs.volta
pkgs.vscode
pkgs.zoom-us
];
};
fonts.packages = [
pkgs.jetbrains-mono
];
homebrew = {
enable = true;
brews = [
"autoconf"
"automake"
"autoconf-archive"
"ghcup"
"libtool"
"llvm@19"
"openjdk@17"
"pkg-config"
];
casks = [
"1password"
"flutter"
"ghostty"
"orbstack"
];
masApps = {
"Goodnotes 6" = 1444383602;
"KakaoTalk" = 869223134;
"Messenger" = 1480068668;
"SurfShark" = 1437809329;
"Todoist" = 585829637;
"WhatsApp" = 310633997;
};
onActivation.autoUpdate = true;
onActivation.cleanup = "zap";
onActivation.upgrade = true;
};
networking = {
knownNetworkServices = [
"Wi-Fi"
];
dns = [
"1.1.1.1"
"1.0.0.1"
"2606:4700:4700::1111"
"2606:4700:4700::1001"
];
hostName = "Denniss-MacBook-Pro";
};
nix.settings.experimental-features = "nix-command flakes";
nixpkgs = {
hostPlatform = "aarch64-darwin";
config.allowUnfree = true;
};
power.sleep = {
computer = 20;
display = 15;
};
programs.zsh = {
enable = true;
enableGlobalCompInit = true;
enableBashCompletion = true;
shellInit = ''
export XDG_CACHE_HOME="$HOME/.cache"
export XDG_CONFIG_HOME="$HOME/.config"
export XDG_DATA_HOME="$HOME/.local/share"
export ZDOTDIR="$XDG_CONFIG_HOME/zsh"
export EDITOR="nvim"
export VISUAL="nvim"
'';
};
services = {
skhd.enable = true;
yabai = {
enable = true;
enableScriptingAddition = true;
};
};
system = {
activationScripts.applications.text =
let
env = pkgs.buildEnv {
name = "system-applications";
paths = config.environment.systemPackages;
pathsToLink = "/Applications";
};
in
pkgs.lib.mkForce ''
echo "setting up /Applications..." >&2
dir=/Applications/Nix\ Apps
rm -rf "$dir"
mkdir -p "$dir"
find ${env}/Applications -maxdepth 1 -type l -exec readlink '{}' + |
while read -r src; do
# Syncs the app as a trampoline
app_name=$(basename -s ".app" "$src")
echo "syncing $app_name" >&2
${pkgs.rsync}/bin/rsync --archive --checksum --chmod=-w --copy-unsafe-links --delete "$src/" "$dir/$app_name.app"
# Replaces icons if replacement exist
icns_src="${paths.config}/icons/$app_name.icns"
if [ -f "$icns_src" ]; then
icns_tgt=$(find "$dir/$app_name.app/Contents/Resources" -name "*.icns")
cp "$icns_src" "$icns_tgt"
fi
done
rm -rf /Library/Caches/com.apple.iconservices.store 2>/dev/null
find /private/var/folders/ \( -name com.apple.dock.iconcache -or -name com.apple.iconservices \) -exec rm -rf {} \; 2>/dev/null
killall Finder
killall Dock
'';
configurationRevision = self.rev or self.dirtyRev or null;
defaults = {
dock = {
autohide = true;
persistent-apps = [
"/Applications/Nix Apps/Google Chrome.app"
"/System/Applications/Mail.app"
"/System/Applications/Calendar.app"
"/Applications/Todoist.app"
"/Applications/Nix Apps/Spotify.app"
"/Applications/Ghostty.app"
"/Applications/Nix Apps/Visual Studio Code.app"
"/Applications/Nix Apps/Slack.app"
"/Applications/KakaoTalk.app"
"/Applications/WhatsApp.app"
"/Applications/Messenger.app"
"/System/Applications/System Settings.app"
];
show-recents = false;
};
finder = {
AppleShowAllExtensions = true;
AppleShowAllFiles = false;
CreateDesktop = false;
FXEnableExtensionChangeWarning = false;
FXPreferredViewStyle = "clmv";
FXRemoveOldTrashItems = true;
ShowPathbar = false;
ShowStatusBar = false;
};
loginwindow.GuestEnabled = false;
WindowManager = {
EnableStandardClickToShowDesktop = false;
GloballyEnabled = false;
StandardHideDesktopIcons = false;
};
};
keyboard = {
enableKeyMapping = true;
remapCapsLockToEscape = true;
};
stateVersion = 5;
};
};
in
{
darwinConfigurations."main" = nix-darwin.lib.darwinSystem {
modules = [
configuration
nix-homebrew.darwinModules.nix-homebrew
{
nix-homebrew = {
enable = true;
enableRosetta = true;
user = "denniseum";
};
}
];
};
};
}
Originally, I didn’t have the cask llvm@19
(I’m using it right now as an alternative since I need some C++23 features, and the included clangd works perfectly with this), instead having in systemPackages
pkgs.llvmPackages_19.clang-tools
pkgs.llvmPackages_19.libcxxClang
The linker error appears specifically with the libcxxClang – maybe there is a way to avoid using the included linker and let the system linker be used?