Repository navigation
Description
Describe the bug
Follow-up to #579204 and #579756.
The darwin wrapper in pkgs/by-name/cl/claude-code/package.nix currently sets:
export CLAUDE_CODE_CERT_STORE=${CLAUDE_CODE_CERT_STORE-'system'}
if [ -z "${NODE_EXTRA_CA_CERTS:-}" ] && [ -n "${NIX_SSL_CERT_FILE:-}" ]; then
export NODE_EXTRA_CA_CERTS="$NIX_SSL_CERT_FILE"
fiThis fixes terminal shells where Nix sets NIX_SSL_CERT_FILE, but still fails whenever claude is launched without NIX_SSL_CERT_FILE in the environment — which is the default for macOS GUI apps launched via launchd (IDEs, agent UIs, editors, etc.) as well as non-login shells.
When NIX_SSL_CERT_FILE is unset and /Library/Keychains/System.keychain contains any trusted custom CA (for example from mkcert, a local dev CA, or a corporate proxy), Claude Code loads only those keychain certificate(s) and omits Apple's built-in roots, causing every HTTPS API request to fail:
API Error: Unable to connect to API: SSL certificate verification failed (UNABLE_TO_GET_ISSUER_CERT_LOCALLY).
claude --debug confirms:
[DEBUG] CA certs: stores=system, extraCertsPath=undefined
[DEBUG] CA certs: Loaded 1 system CA certificates
[DEBUG] mTLS: Creating HTTPS agent with custom certificates
Steps to reproduce
On aarch64-darwin with at least one custom trusted certificate in /Library/Keychains/System.keychain:
env -u NIX_SSL_CERT_FILE -u NODE_EXTRA_CA_CERTS claude -p "reply ok"Compare with NIX_SSL_CERT_FILE set or CLAUDE_CODE_CERT_STORE=bundled,system, both of which succeed.
Expected behavior
claude should verify public TLS certificates on darwin even when invoked without NIX_SSL_CERT_FILE (e.g. from GUI apps).
Suggested fix
While keeping CLAUDE_CODE_CERT_STORE=system (per #576509 / #576544 so nixpkgs' cacert remains the root of trust), fall back when NIX_SSL_CERT_FILE is unset — for example checking /etc/ssl/certs/ca-certificates.crt (managed by nix-darwin) and falling back to ${cacert}/etc/ssl/certs/ca-bundle.crt:
if [ -z "${NODE_EXTRA_CA_CERTS:-}" ]; then
if [ -n "${NIX_SSL_CERT_FILE:-}" ]; then
export NODE_EXTRA_CA_CERTS="$NIX_SSL_CERT_FILE"
elif [ -r /etc/ssl/certs/ca-certificates.crt ]; then
export NODE_EXTRA_CA_CERTS=/etc/ssl/certs/ca-certificates.crt
else
export NODE_EXTRA_CA_CERTS="@cacert@/etc/ssl/certs/ca-bundle.crt"
fi
fiWorkaround
Add "CLAUDE_CODE_CERT_STORE": "bundled,system" (or "NODE_EXTRA_CA_CERTS": "/etc/ssl/certs/ca-certificates.crt") under env in ~/.claude/settings.json.
Metadata
- system:
aarch64-darwin - package:
claude-code2.1.332(nixpkgs-unstable)
Activity