Skip to content

claude-code: TLS still fails on darwin when NIX_SSL_CERT_FILE is unset (e.g. GUI apps) #596917

Backlog

Description

@anandrajaram21

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"
fi

This 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
fi

Workaround

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-code 2.1.332 (nixpkgs-unstable)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions