← Back to Pull requests

fix(linker): cache macOS links built against a Nix store SDK #1042

Closed
unknown closed this pull request without merging on Nov 29, 2026 20:59 UTC
View on GitHub
unknown unknown commented on Nov 29, 2026 20:21 UTC
Author

In a Nix dev shell on macOS, mbx now caches native links (tests, executables, proc macros) instead of bypassing every one of them. This is option 2 of discussion jdx/mr-boxington#1039.

Trigger. A stock nixpkgs mkShell on aarch64-darwin sets the SDK from nixpkgs' apple-sdk:

SDKROOT=/nix/store/…-apple-sdk-14.4/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
DEVELOPER_DIR=/nix/store/…-apple-sdk-14.4

xcrun cannot describe that SDK. mbx needs the SDK's identity in each link key, so it refused the host. mbx explain reported every native link as unportable-native-link ("the macOS SDK could not be identified").

Now. If xcrun fails and SDKROOT resolves to a path inside a /nix/store/<hash>-<name> entry, mbx identifies the SDK by that store path. Store entries are immutable, and their names change when their inputs change, so the path alone tells two SDKs apart. mbx also reads the version from the SDK's SDKSettings.json and the build from System/Library/CoreServices/SystemVersion.plist, so keys stay readable. The version is required. The build is included when the plist reports it.

Everything else is still refused: an SDKROOT outside the store, a path that reaches the store only through .. or a symlink trick (the path is canonicalized first), the store directory itself, and a store entry with no SDK version. Hosts where xcrun works behave the same as before. docs/limits.md now describes the exception.

Validation.

  • Unit tests for the fallback run on every platform and use a temporary directory as the store. One checks that a store SDK is identified, one that two store entries with the same version get different keys, and one covers each refusal above.

  • A macOS-only test copies the real SDK's SDKSettings.json and SystemVersion.plist into a fake store entry and checks that the fallback reports the same version and build as xcrun. It passed on an Apple M6 Mac mini (macOS 27.2.1, Command Line Tools SDK 27.2, build 26B118), along with the rest of the linker tests.

  • Not tested in a real Nix shell: neither test Mac has Nix installed. The nixpkgs layout and file formats are taken from the issue report and from Apple's SDK, which nixpkgs repackages.
  • AI-assisted — Tool: Claude Code; model: anthropic/claude-sonnet-5-5; version: unavailable.

    🤖 Generated with Claude Code

    <!-- CURSOR_SUMMARY -->
    ---

    [!NOTE]

    Medium Risk

    Changes macOS linker cache key generation for SDK identity; incorrect fallback logic could mis-key or refuse links, but scope is limited to the Nix store SDKROOT path when xcrun fails.

    > Overview

    When xcrun cannot describe macOS SDK (common with nixpkgs apple-sdk in SDKROOT), mbx falls back to identifying the SDK by its canonical Nix store path plus version from SDKSettings.json and build from SystemVersion.plist (or build unreported).

    > Non-store paths, symlink tricks, invalid entries, and missing version are still refused. docs/limits.md documents this Nix store exception. sdk_identity_for now uses describe().or_else(from_store); new helpers store_sdk_identity and plist_string back the fallback, with unit tests covering identification, differentiation, and refusal cases.

    > <sup>Reviewed by Cursor Bugbot for commit 5cb74d982a92dd458da9a37a3e72e2ca567b7ba1. Bugbot is set up for automated code reviews on this repo. Configure here.</sup>

    <!-- /CURSOR_SUMMARY -->

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->

    <!-- coderabbit-ai-generated:v1 -->

    Summary by CodeRabbit

    Bug Fixes
    macOS builds can now identify SDKs in the Nix store when xcrun cannot describe them, using the SDK’s recorded version and build information when available.
    Documentation
    Clarified the requirements for using Nix store SDKs with macOS host linking.

    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 507 lines (+380 / -127) across 6 files Reviewer: jdx Review duration: 37m
    All Vouch review confidence checks passed
    Residual risk 0.19 = Change Risk (0.48) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.48 · 507 lines diff across 6 files
    0.48
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.373
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #1042"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 47.6% (MEDIUM) · Higher = larger blast radius
    47.6%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 18.8% · Safe to merge
    18.8%