|
xrpld
|
Common issues encountered when using the Nix development shell, and how to resolve them.
If a shell suddenly can't find nix at all:
then Nix is almost certainly still installed — only the shell hook that puts it on your PATH is gone. Confirm that first:
If that exists, the installation is fine and this is purely a PATH problem.
The installer does not touch your dotfiles. Instead it sources a setup script from the Nix store by editing system-wide rc files:
| Shell | File the installer edits |
|---|---|
| bash | /etc/bashrc, /etc/bash.bashrc |
| zsh | /etc/zshrc |
| fish | $__fish_sysconf_dir/conf.d/nix.fish |
macOS manages /etc/zshrc, so an OS update can replace it with the vendor copy and silently drop the Nix block. /etc/bashrc and the fish file usually survive, which is why the breakage often shows up in zsh only. You can verify this by diffing against the backup the installer left behind:
If they are identical, the Nix snippet was wiped. This is upstream issue NixOS/nix#3616.
To unblock the current shell:
For a permanent fix, add the snippet to your user rc file rather than restoring /etc/zshrc — user dotfiles are not clobbered by OS updates:
The scripts guard against double-sourcing via __ETC_PROFILE_NIX_SOURCED, so this is safe even if a system-wide hook is later restored.
If nix develop fails with an error like:
then your Nix is linked against a libgit2 older than 1.9.4. Git 2.48+ writes the extensions.relativeWorktrees config entry when a worktree is created with relative paths (git worktree add --relative-paths, or with worktree.useRelativePaths=true), and older libgit2 versions refuse to open a repository that uses it. Nix uses libgit2 to read the flake, so evaluation fails.
These work today, with any Nix version:
The fix is in libgit2 1.9.4, so the real solution is a Nix that links against libgit2 1.9.4 or newer. Check which version yours links against:
nixpkgs has already rebuilt Nix against the fixed libgit2 (e.g. nix-2.34.7+1), so the cleanest path is to reinstall Nix using your usual installation method once it picks up that rebuild, then re-run the grep libgit2 check above to confirm it reports 1.9.4 or newer.
Until then, prefer the workarounds above.
A build that mixes the Nix toolchain with the system SDK fails in libc++ itself, with errors that look nothing like your code:
The give-away is the second path: Nix's libc++ headers are being combined with the Xcode Command Line Tools SDK instead of the Nix one.
SDKROOT and DEVELOPER_DIR are what point the toolchain at the Nix SDK, and they are not baked into the compiler — a dev shell gets them from the apple-sdk setup hook. CMake, finding neither, asks xcrun, which answers with the system SDK. Nix's libc++ and Apple's headers then declare the same types twice.
Run the build from inside the dev shell (nix develop), or from an environment that exports both variables. To confirm which SDK a configured build is using:
It should print a /nix/store/...-apple-sdk-* path. If it prints /Library/Developer/CommandLineTools/..., re-configure from within the shell — CMake caches the sysroot, so an existing build/ directory keeps the wrong one.
A binary stops starting after a nix flake update, or after nix-collect-garbage removes the paths the previous toolchain used:
bin/check-nix-store-refs.sh finds the same thing without having to run anything, and names the file:
Conan's cache folders are named after a truncated package name plus a hash, so ask Conan which package the offending one belongs to — pass the folder holding the hash, not the file itself:
The binary records a store path that no longer exists. Nothing we build should: see Prebuilt packages for why, and libresolvSystemStub in nix/darwin.nix for the one dependency that needed help to comply.
A Conan package ID does not encode the nixpkgs revision, so a package built before that stub existed stays in your local cache and keeps being reused. The dev shell is also what tends to produce one: it is a slightly less isolated build environment than CI's, because mkShell puts every tool's headers and libraries on the compiler's search path — which is how c-ares found the Nix libresolv in the first place.
Drop that package and let Conan refetch or rebuild it: