Skip to content

MacOS Only: git is unavailable inside every nix dev shell except .#release #1906

Open

Description

@AdamuAbba

On macOS, running git inside any nix develop shell fails:

nix develop .#kotlin -c git --version
error: tool 'git' not found

This affects the default shell too, which means anyone using the repo's .envrc (use flake .) has no working git in the project directory until they leave the shell. .#release is the only shell that works, because it's the only one that lists git in its packages.

why this happens is because /usr/bin/git on macOS is not git — it's Apple's xcode-select shim, which locates the real binary via DEVELOPER_DIR when that variable is set, falling back to xcode-select -p when it isn't.

Nix's Darwin stdenv sets DEVELOPER_DIR to its own pinned Apple SDK so that compilers and linkers don't depend on whatever Xcode is installed on the host:

DEVELOPER_DIR=/nix/store/d8s89pc5...-apple-sdk-14.4

That SDK ships only xcrun — no git. So the shim looks inside it, finds nothing, and emits Apple's error. /usr/bin/git is still first on PATH; it just can't resolve a real binary anymore.

the shim is the problem, not the absence of git:

nix develop .#kotlin -c env -u DEVELOPER_DIR git --version
git version 2.54.0 (Apple Git-157)
nix develop .#kotlin -c /Library/Developer/CommandLineTools/usr/bin/git --version
git version 2.54.0 (Apple Git-157)

the SDK nix points DEVELOPER_DIR at contains only xcrun:

nix develop .#kotlin -c bash -c 'ls $DEVELOPER_DIR/usr/bin'
xcrun

fix i'm proposing

Add git to each dev shell's packages, the way releaseDevShell already does. nix's git then precedes /usr/bin on PATH, so the shim is never consulted. the crane devShell definition is shared, so the first change covers default/nightly/stable/msrv. nix's git also ships git-credential-osxkeychain, so the macOS keychain credential helper keeps working.

crane shells (default/nightly/stable/msrv):

             packages =
               with pkgs;
               [
                 cargo-edit
                 cargo-nextest
                 cargo-watch
                 rust-analyzer
                 cargo-fuzz
                 bzip2 # needed for some machines to have access to libzip at runtime
                 codespell
+                git
               ]
               ++ pkgs.lib.optionals (!pkgs.stdenv.isDarwin) [
                 cargo-llvm-cov
               ];

javascriptDevShell:

             llvmPackages.clang-unwrapped
             llvmPackages.bintools-unwrapped
             lld
             bzip2 # needed for some machines to have access to libzip at runtime
+            git
           ];

dartDevShell:

             [
               rustVersions.msrv
               dart
               bzip2
               curl
               jq
+              git
             ]

same flow for csharpDevShell, kotlinDevShell and pythonDevShell

I've got a branch with the diffs applied and i can open a PR if this is worth fixing now? let me know what you guys think.

environment:

  • macOS 27.0, aarch64-darwin (apple silicon)
  • Determinate Nix 3.21.8 (nix 2.34.8)
  • apple-sdk-14.4 (what DEVELOPER_DIR resolves to inside the shells)

Activity

  1. xstoicunicornx commented on Sep 29, 2026

    @xstoicunicornx
    Collaborator

    I think it could be worth adding to crane shells. I am not as sure about adding it to the bindings shells? What do we need git for in there?

    I haven't run into this issue myself, I am on macOS 15 darwin.

  2. AdamuAbba commented on Oct 5, 2026

    @AdamuAbba
    ContributorAuthor

    Hey @xstoicunicornx, thanks for taking a look! you're right, the bindings shells don't need git since we just enter them to build or test the bindings and leave. I'll limit the change to the crane shells.

    On why you might not be seeing it: the bug triggers when the first git on PATH is Apple's /usr/bin/git shim. If you have git from Homebrew or elsewhere earlier on your PATH, the shim is never used. Could you check nix develop -c which -a git? On my machine it resolves to /usr/bin/git, so after direnv allow I lose git, and after direnv deny it comes back.

  3. xstoicunicornx commented on Oct 13, 2026

    @xstoicunicornx
    Collaborator

    Hey @AdamuAbba , sorry for delay in getting back to you. I still can't seem to replicate what you are seeing. Here is what I get:

    rust-payjoin on  pr1887 [!1?5]
    ❯ nix develop -c git --version
    evaluation warning: crane requires at least nixpkgs-26.05, supplied nixpkgs-25.11
    git version 2.50.1 (Apple Git-155)
    
    rust-payjoin on  pr1887 [!1?5]
    ❯ nix develop -c env -u DEVELOPER_DIR git --version
    evaluation warning: crane requires at least nixpkgs-26.05, supplied nixpkgs-25.11
    git version 2.50.1 (Apple Git-155)
    
    rust-payjoin on  pr1887 [!1?5]
    ❯ nix develop -c /Library/Developer/CommandLineTools/usr/bin/git --version
    evaluation warning: crane requires at least nixpkgs-26.05, supplied nixpkgs-25.11
    git version 2.39.5 (Apple Git-154)

    Just to confirm, running nix develop -c git --version errors for you still? I'd like to pin down what the issue actually is before we move forward with updates.

  4. AdamuAbba commented on Oct 19, 2026

    @AdamuAbba
    ContributorAuthor

    Hey @xstoicunicornx, thanks for testing. Yes, it still fails for me. Here's what i get:

    $ nix develop -c git --version
    evaluation warning: crane requires at least nixpkgs-26.05, supplied nixpkgs-25.11
    error: tool 'git' not found
    $ nix develop -c env -u DEVELOPER_DIR git --version
    evaluation warning: crane requires at least nixpkgs-26.05, supplied nixpkgs-25.11
    git version 2.54.0 (Apple Git-157)

    On my machine (macOS 27.0.1), /usr/bin/git is a macOS stub that, when DEVELOPER_DIR is set, runs $DEVELOPER_DIR/usr/bin/xcrun. In the nix SDK that's xcbuild's xcrun, which prints the error. Since both of your commands gave the same result, either your stub behaves differently or DEVELOPER_DIR isn't set in your shell. This check needs no nix:

    d=$(mktemp -d)
    mkdir -p "$d/usr/bin"
    printf '#!/bin/sh\necho "fake xcrun called with: $*"\n' > "$d/usr/bin/xcrun"
    chmod +x "$d/usr/bin/xcrun"
    DEVELOPER_DIR="$d" /usr/bin/git --version
    rm -rf "$d"

    Mine prints fake xcrun called with: git --version. Could you share its output and nix develop -c bash -c 'echo $DEVELOPER_DIR'? You mentioned you're on macOS 15, so if the check prints a git version, it's likely a macOS version difference. If it matches mine, the difference is in your nix shell.

    Here's a flow diagram explaining the check i'd like you to run above:

         ┌───────────────────────────────────────────┐
         │ DEVELOPER_DIR="$d" /usr/bin/git --version │
         │ ($d contains only a fake usr/bin/xcrun)   │
         └─────────────────────┬─────────────────────┘
                               ▼
         ┌───────────────────────────────────────────┐
         │ Does the macOS stub run $d/usr/bin/xcrun? │
         └─────────┬───────────────────────┬─────────┘
               yes │                       │ no
                   ▼                       ▼
     ┌───────────────────────┐ ┌───────────────────────┐
     │ prints: fake xcrun    │ │ prints:               │
     │ called with: git      │ │ git version x.y.z     │
     │ --version             │ │                       │
     │ (mine, macOS 27.0.1)  │ │                       │
     └───────────┬───────────┘ └───────────┬───────────┘
                 ▼                         ▼
     ┌───────────────────────┐ ┌───────────────────────┐
     │ Does nix develop set  │ │ macOS difference      │
     │ DEVELOPER_DIR to the  │ │ (likely the version): │
     │ nix SDK?              │ │ the stub never runs   │
     │                       │ │ nix's xcrun           │
     └─────┬───────────┬─────┘ └───────────────────────┘
        no │           │ yes
           ▼           ▼
     ┌───────────┐ ┌──────────────────┐
     │ nix shell │ │ unexplained:     │
     │ difference│ │ git should fail, │
     └───────────┘ │ dig further      │
                   └──────────────────┘
    
  5. xstoicunicornx commented on Oct 19, 2026

    @xstoicunicornx
    Collaborator

    My outputs are below, seems to be something nix related then? What do you get for nix develop -c bash -c 'echo $DEVELOPER_DIR'?

    rust-payjoin on  fix/changelog-merge-base:master [!1?5]
    ❯ d=$(mktemp -d)
    mkdir -p "$d/usr/bin"
    printf '#!/bin/sh\necho "fake xcrun called with: $*"\n' > "$d/usr/bin/xcrun"
    chmod +x "$d/usr/bin/xcrun"
    DEVELOPER_DIR="$d" /usr/bin/git --version
    rm -rf "$d"
    fake xcrun called with: git --version
    
    rust-payjoin on  fix/changelog-merge-base:master [!1?5]
    ❯ nix develop -c bash -c 'echo $DEVELOPER_DIR'
    evaluation warning: crane requires at least nixpkgs-26.05, supplied nixpkgs-25.11
    /nix/store/d8s89pc5y7r8l09pgz3s80s2igqga9ir-apple-sdk-14.4
  6. AdamuAbba commented on Oct 25, 2026

    @AdamuAbba
    ContributorAuthor

    Thanks @xstoicunicornx Mine's actually the same path:

    $ nix develop -c bash -c 'echo $DEVELOPER_DIR'
    /nix/store d8s89pc5y7r8l09pgz3s80s2igqga9ir-apple-sdk-14.4

    So it isn't nix: same SDK, and your stub hands off to xcrun like mine does. That leaves which git is found first. nix develop keeps your existing PATH after its own entries, and in the shell mine only finds the stub:

    $ nix develop -c which -a git
    /usr/bin/git

    My guess is you have a real git (maybe Xcode's Contents/Developer/usr/bin) earlier on your PATH, so the stub never runs. Could you share what you get when you run this nix develop -c which -a git?

  7. xstoicunicornx commented on Nov 2, 2026

    @xstoicunicornx
    Collaborator

    I still get the same as you :/

    ❯ nix develop -c which -a git
    evaluation warning: crane requires at least nixpkgs-26.05, supplied nixpkgs-25.11
    /usr/bin/git
  8. AdamuAbba commented on Nov 4, 2026

    @AdamuAbba
    ContributorAuthor

    Hey @xstoicunicornx Thanks for testing this. At least that rules out my PATH guess. Since you can't reproduce it and it depends on local setup, I'm happy to install git through Homebrew on my end and move on. should I close this issue and #1969, or would you rather I leave them open?

    For anyone else who hits error: tool 'git' not found in the dev shell on macOS: nix's xcrun doesn't search /usr/bin and falls back to the /var/select/developer_dir and /var/db/xcode_select_link symlinks.

    If neither exists and /usr/bin/git is your first git on PATH, git fails. Installing git separately or running sudo xcode-select -s /Applications/Xcode.app/Contents/Developer should fix it but i'd advice installing git separately.

  9. xstoicunicornx commented on Nov 12, 2026

    @xstoicunicornx
    Collaborator

    You did all the real testing, thank you! I think lets just add to the crate, just to ensure no one else runs into this. Its very small change that doesn't cost much.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions