Missing system dev tools when running nix develop on MacOS #649

Open
opened 2025-01-24 19:13:35 +00:00 by asutula · 7 comments

Describe the bug

I use simple fake files to configure development environments. Before running nix develop, command like tools like git are available and work as expected. After running nix develop, I get and error like error: tool 'git' not found. This is true for other tools like gcc as well.

Steps To Reproduce

  1. Create a flake.nix with the following content:
{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    utils.url = "github:numtide/flake-utils";
  };

  outputs = { self, nixpkgs, utils }:
    utils.lib.eachDefaultSystem (system:
      let
        pkgs = import nixpkgs {
          inherit system;
        };
      in
      {
        devShell = with pkgs; mkShell {
          buildInputs = [
            nodejs
            pnpm
          ];
        };
      }
    );
}
  1. Run nix develop
  2. Run git --version and see the error error: tool 'git' not found

Expected behavior

I'd expect any program already installed on my computer to work inside a nix development shell.

nix --version output

nix --version
nix (Lix, like Nix) 2.92.0
System type: aarch64-darwin
Additional system types:
Features: gc, signed-caches
System configuration file: /etc/nix/nix.conf
User configuration files: /Users/aaron/.config/nix/nix.conf:/etc/xdg/nix/nix.conf
Store directory: /nix/store
State directory: /nix/var/nix
Data directory: /nix/store/y9mgqlvgyh0ixd0vgyn1y4kjgsn2gw36-lix-2.92.0/share

Additional context

Running MacOS 15.2 (Sequoia) on a M4 MacbookPro. I haven't yet installed nix-darwin.

## Describe the bug I use simple fake files to configure development environments. Before running `nix develop`, command like tools like `git` are available and work as expected. After running `nix develop`, I get and error like `error: tool 'git' not found`. This is true for other tools like `gcc` as well. ## Steps To Reproduce 1. Create a `flake.nix` with the following content: ``` { inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; utils.url = "github:numtide/flake-utils"; }; outputs = { self, nixpkgs, utils }: utils.lib.eachDefaultSystem (system: let pkgs = import nixpkgs { inherit system; }; in { devShell = with pkgs; mkShell { buildInputs = [ nodejs pnpm ]; }; } ); } ``` 2. Run `nix develop` 3. Run `git --version` and see the error `error: tool 'git' not found` ## Expected behavior I'd expect any program already installed on my computer to work inside a nix development shell. ## `nix --version` output nix --version nix (Lix, like Nix) 2.92.0 System type: aarch64-darwin Additional system types: Features: gc, signed-caches System configuration file: /etc/nix/nix.conf User configuration files: /Users/aaron/.config/nix/nix.conf:/etc/xdg/nix/nix.conf Store directory: /nix/store State directory: /nix/var/nix Data directory: /nix/store/y9mgqlvgyh0ixd0vgyn1y4kjgsn2gw36-lix-2.92.0/share ## Additional context Running MacOS 15.2 (Sequoia) on a M4 MacbookPro. I haven't yet installed `nix-darwin`.
Owner

Sadly I can't reproduce this. Can you echo $PATH inside that nix shell?

Another thing that is really curious about that error message is that that is not an error message emitted by zsh or bash.

(nix:nix-shell-env) jades-Virtual-Machine:lix-2025-02-03-bug-649 jade$ sgdfsdfglksgdfl
bash: sgdfsdfglksgdfl: command not found
jade@jades-Virtual-Machine lix-2025-02-03-bug-649 % sldfgksglkdflhsdfg
zsh: command not found: sldfgksglkdflhsdfg

This leads me to believe that somehow this is hitting xcode, since I think that xcode has this idea of "tools" as per the error you mentioned. There is a bug with the shell initialization on macOS that has surely been there for practically years (#645) which causes the various Nix profiles to get shoved at the start of PATH all the time such that they override whatever is included in the nix shell/nix develop. That might be a contributing cause?

Sadly I can't reproduce this. Can you `echo $PATH` inside that nix shell? Another thing that is *really* curious about that error message is that that is not an error message emitted by zsh or bash. ``` (nix:nix-shell-env) jades-Virtual-Machine:lix-2025-02-03-bug-649 jade$ sgdfsdfglksgdfl bash: sgdfsdfglksgdfl: command not found jade@jades-Virtual-Machine lix-2025-02-03-bug-649 % sldfgksglkdflhsdfg zsh: command not found: sldfgksglkdflhsdfg ``` This leads me to believe that somehow this is hitting xcode, since I think that xcode has this idea of "tools" as per the error you mentioned. There *is* a bug with the shell initialization on macOS that has surely been there for practically years (https://git.lix.systems/lix-project/lix/issues/645) which causes the various Nix profiles to get shoved at the start of PATH all the time such that they override whatever is included in the `nix shell`/`nix develop`. That might be a contributing cause?
Author

Thanks for the reply @jade. Here's a copy paste of a couple commands and my PATH. Yes, it does seem like something is going wrong with how the developer tools are shimmed and resolved when you run them. i.e. zsh seems to know about git, but when you try to run git something breaks along the way.

(nix:nix-shell-env) pachuca:js-recall aaron$ which git
/usr/bin/git
(nix:nix-shell-env) pachuca:js-recall aaron$ git status
error: tool 'git' not found
(nix:nix-shell-env) pachuca:js-recall aaron$ echo $PATH
/nix/store/x25662zlrvzy1aavv8y5vrk40bj8c8hr-clang-wrapper-19.1.6/bin:/nix/store/ynh5hdy6j9zxss67miwm8j44k2ggvisc-clang-19.1.6/bin:/nix/store/27hlrqpjy40ifmmy3rw2fbi5b57l8cmw-coreutils-9.5/bin:/nix/store/n8607yw4jvrxsr5jlnjl6vvzh05whz3h-cctools-binutils-darwin-wrapper-1010.6/bin:/nix/store/a217km5hlmmxdsb6ff3bfi7dfihm8pbm-cctools-binutils-darwin-1010.6/bin:/nix/store/l45wpqa95wm1ghmnw28zy55v1xqbyppr-xcbuild-0.1.1-unstable-2019-11-20-xcrun/bin:/nix/store/ygk01vha6k5zxgn9rsxi3k6cm2kbnwsc-nodejs-22.12.0/bin:/nix/store/ns9rxfag2c8lnm5k33yabbn0dpnl41i0-pnpm-10.1.0/bin:/nix/store/xlrxyhdh3irs3fh5rc94y99n9mvpjj7v-libiconv-107/bin:/nix/store/27hlrqpjy40ifmmy3rw2fbi5b57l8cmw-coreutils-9.5/bin:/nix/store/2kixgwpf8y4xd88hv28wckv6irqvlv1a-findutils-4.10.0/bin:/nix/store/d4b4vfci0x8q80r42mjm0q62z7711ffw-diffutils-3.10/bin:/nix/store/a682ixpxigvv182r3l4km27vc17x1848-gnused-4.9/bin:/nix/store/2l7h1k77n3dxw34ipwll9x2jrxf1whi2-gnugrep-3.11/bin:/nix/store/invr3ksha5yiidygjapnxjgrhbnj10dl-gawk-5.3.1/bin:/nix/store/jii7r1dzxrmwni63r092vh1q4pvyg6lz-gnutar-1.35/bin:/nix/store/h6dg2cxp4j9fs8dmcxshz9sa3f8dcjrh-gzip-1.13/bin:/nix/store/m511j7qjg93h7cia4jv4yhlszyprj79d-bzip2-1.0.8-bin/bin:/nix/store/lgwqlms7xmi8blp2859r44kjacr5zxh4-gnumake-4.4.1/bin:/nix/store/iv1k5wr7hbxm51qmdn6l2inq7rd2vfhk-bash-5.2p37/bin:/nix/store/h681ir0m8v2i0psmcfrl85cdqxi90w7c-patch-2.7.6/bin:/nix/store/fmgshpsi3m4c00hipfv9sqandfr7xjwl-xz-5.6.3-bin/bin:/nix/store/jlkrvhxalxc35ggbcgaww83mc2nsnpnn-file-5.46/bin:/Users/aaron/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/Users/aaron/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:/usr/local/MacGPG2/bin:/Users/aaron/.cargo/bin:/Users/aaron/.nix-profile/bin:/nix/var/nix/profiles/default/bin

I'll try to make sense of that PATH value asap and chime in with any thoughts here.

Thanks for the reply @jade. Here's a copy paste of a couple commands and my PATH. Yes, it does seem like something is going wrong with how the developer tools are shimmed and resolved when you run them. i.e. zsh seems to know about `git`, but when you try to run `git` something breaks along the way. ``` (nix:nix-shell-env) pachuca:js-recall aaron$ which git /usr/bin/git (nix:nix-shell-env) pachuca:js-recall aaron$ git status error: tool 'git' not found (nix:nix-shell-env) pachuca:js-recall aaron$ echo $PATH /nix/store/x25662zlrvzy1aavv8y5vrk40bj8c8hr-clang-wrapper-19.1.6/bin:/nix/store/ynh5hdy6j9zxss67miwm8j44k2ggvisc-clang-19.1.6/bin:/nix/store/27hlrqpjy40ifmmy3rw2fbi5b57l8cmw-coreutils-9.5/bin:/nix/store/n8607yw4jvrxsr5jlnjl6vvzh05whz3h-cctools-binutils-darwin-wrapper-1010.6/bin:/nix/store/a217km5hlmmxdsb6ff3bfi7dfihm8pbm-cctools-binutils-darwin-1010.6/bin:/nix/store/l45wpqa95wm1ghmnw28zy55v1xqbyppr-xcbuild-0.1.1-unstable-2019-11-20-xcrun/bin:/nix/store/ygk01vha6k5zxgn9rsxi3k6cm2kbnwsc-nodejs-22.12.0/bin:/nix/store/ns9rxfag2c8lnm5k33yabbn0dpnl41i0-pnpm-10.1.0/bin:/nix/store/xlrxyhdh3irs3fh5rc94y99n9mvpjj7v-libiconv-107/bin:/nix/store/27hlrqpjy40ifmmy3rw2fbi5b57l8cmw-coreutils-9.5/bin:/nix/store/2kixgwpf8y4xd88hv28wckv6irqvlv1a-findutils-4.10.0/bin:/nix/store/d4b4vfci0x8q80r42mjm0q62z7711ffw-diffutils-3.10/bin:/nix/store/a682ixpxigvv182r3l4km27vc17x1848-gnused-4.9/bin:/nix/store/2l7h1k77n3dxw34ipwll9x2jrxf1whi2-gnugrep-3.11/bin:/nix/store/invr3ksha5yiidygjapnxjgrhbnj10dl-gawk-5.3.1/bin:/nix/store/jii7r1dzxrmwni63r092vh1q4pvyg6lz-gnutar-1.35/bin:/nix/store/h6dg2cxp4j9fs8dmcxshz9sa3f8dcjrh-gzip-1.13/bin:/nix/store/m511j7qjg93h7cia4jv4yhlszyprj79d-bzip2-1.0.8-bin/bin:/nix/store/lgwqlms7xmi8blp2859r44kjacr5zxh4-gnumake-4.4.1/bin:/nix/store/iv1k5wr7hbxm51qmdn6l2inq7rd2vfhk-bash-5.2p37/bin:/nix/store/h681ir0m8v2i0psmcfrl85cdqxi90w7c-patch-2.7.6/bin:/nix/store/fmgshpsi3m4c00hipfv9sqandfr7xjwl-xz-5.6.3-bin/bin:/nix/store/jlkrvhxalxc35ggbcgaww83mc2nsnpnn-file-5.46/bin:/Users/aaron/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/Users/aaron/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:/usr/local/MacGPG2/bin:/Users/aaron/.cargo/bin:/Users/aaron/.nix-profile/bin:/nix/var/nix/profiles/default/bin ``` I'll try to make sense of that PATH value asap and chime in with any thoughts here.
Author

Here is PATH with some line breaks:

/nix/store/x25662zlrvzy1aavv8y5vrk40bj8c8hr-clang-wrapper-19.1.6/bin
/nix/store/ynh5hdy6j9zxss67miwm8j44k2ggvisc-clang-19.1.6/bin
/nix/store/27hlrqpjy40ifmmy3rw2fbi5b57l8cmw-coreutils-9.5/bin
/nix/store/n8607yw4jvrxsr5jlnjl6vvzh05whz3h-cctools-binutils-darwin-wrapper-1010.6/bin
/nix/store/a217km5hlmmxdsb6ff3bfi7dfihm8pbm-cctools-binutils-darwin-1010.6/bin
/nix/store/l45wpqa95wm1ghmnw28zy55v1xqbyppr-xcbuild-0.1.1-unstable-2019-11-20-xcrun/bin
/nix/store/ygk01vha6k5zxgn9rsxi3k6cm2kbnwsc-nodejs-22.12.0/bin
/nix/store/ns9rxfag2c8lnm5k33yabbn0dpnl41i0-pnpm-10.1.0/bin
/nix/store/xlrxyhdh3irs3fh5rc94y99n9mvpjj7v-libiconv-107/bin
/nix/store/27hlrqpjy40ifmmy3rw2fbi5b57l8cmw-coreutils-9.5/bin
/nix/store/2kixgwpf8y4xd88hv28wckv6irqvlv1a-findutils-4.10.0/bin
/nix/store/d4b4vfci0x8q80r42mjm0q62z7711ffw-diffutils-3.10/bin
/nix/store/a682ixpxigvv182r3l4km27vc17x1848-gnused-4.9/bin
/nix/store/2l7h1k77n3dxw34ipwll9x2jrxf1whi2-gnugrep-3.11/bin
/nix/store/invr3ksha5yiidygjapnxjgrhbnj10dl-gawk-5.3.1/bin
/nix/store/jii7r1dzxrmwni63r092vh1q4pvyg6lz-gnutar-1.35/bin
/nix/store/h6dg2cxp4j9fs8dmcxshz9sa3f8dcjrh-gzip-1.13/bin
/nix/store/m511j7qjg93h7cia4jv4yhlszyprj79d-bzip2-1.0.8-bin/bin
/nix/store/lgwqlms7xmi8blp2859r44kjacr5zxh4-gnumake-4.4.1/bin
/nix/store/iv1k5wr7hbxm51qmdn6l2inq7rd2vfhk-bash-5.2p37/bin
/nix/store/h681ir0m8v2i0psmcfrl85cdqxi90w7c-patch-2.7.6/bin
/nix/store/fmgshpsi3m4c00hipfv9sqandfr7xjwl-xz-5.6.3-bin/bin
/nix/store/jlkrvhxalxc35ggbcgaww83mc2nsnpnn-file-5.46/bin
/Users/aaron/.nix-profile/bin
/nix/var/nix/profiles/default/bin
/Users/aaron/.nix-profile/bin
/nix/var/nix/profiles/default/bin
/usr/local/bin
/System/Cryptexes/App/usr/bin
/usr/bin
/bin
/usr/sbin
/sbin
/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin
/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin
/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin
/Library/Apple/usr/bin
/usr/local/MacGPG2/bin
/Users/aaron/.cargo/bin
/Users/aaron/.nix-profile/bin
/nix/var/nix/profiles/default/bin
Here is PATH with some line breaks: ``` /nix/store/x25662zlrvzy1aavv8y5vrk40bj8c8hr-clang-wrapper-19.1.6/bin /nix/store/ynh5hdy6j9zxss67miwm8j44k2ggvisc-clang-19.1.6/bin /nix/store/27hlrqpjy40ifmmy3rw2fbi5b57l8cmw-coreutils-9.5/bin /nix/store/n8607yw4jvrxsr5jlnjl6vvzh05whz3h-cctools-binutils-darwin-wrapper-1010.6/bin /nix/store/a217km5hlmmxdsb6ff3bfi7dfihm8pbm-cctools-binutils-darwin-1010.6/bin /nix/store/l45wpqa95wm1ghmnw28zy55v1xqbyppr-xcbuild-0.1.1-unstable-2019-11-20-xcrun/bin /nix/store/ygk01vha6k5zxgn9rsxi3k6cm2kbnwsc-nodejs-22.12.0/bin /nix/store/ns9rxfag2c8lnm5k33yabbn0dpnl41i0-pnpm-10.1.0/bin /nix/store/xlrxyhdh3irs3fh5rc94y99n9mvpjj7v-libiconv-107/bin /nix/store/27hlrqpjy40ifmmy3rw2fbi5b57l8cmw-coreutils-9.5/bin /nix/store/2kixgwpf8y4xd88hv28wckv6irqvlv1a-findutils-4.10.0/bin /nix/store/d4b4vfci0x8q80r42mjm0q62z7711ffw-diffutils-3.10/bin /nix/store/a682ixpxigvv182r3l4km27vc17x1848-gnused-4.9/bin /nix/store/2l7h1k77n3dxw34ipwll9x2jrxf1whi2-gnugrep-3.11/bin /nix/store/invr3ksha5yiidygjapnxjgrhbnj10dl-gawk-5.3.1/bin /nix/store/jii7r1dzxrmwni63r092vh1q4pvyg6lz-gnutar-1.35/bin /nix/store/h6dg2cxp4j9fs8dmcxshz9sa3f8dcjrh-gzip-1.13/bin /nix/store/m511j7qjg93h7cia4jv4yhlszyprj79d-bzip2-1.0.8-bin/bin /nix/store/lgwqlms7xmi8blp2859r44kjacr5zxh4-gnumake-4.4.1/bin /nix/store/iv1k5wr7hbxm51qmdn6l2inq7rd2vfhk-bash-5.2p37/bin /nix/store/h681ir0m8v2i0psmcfrl85cdqxi90w7c-patch-2.7.6/bin /nix/store/fmgshpsi3m4c00hipfv9sqandfr7xjwl-xz-5.6.3-bin/bin /nix/store/jlkrvhxalxc35ggbcgaww83mc2nsnpnn-file-5.46/bin /Users/aaron/.nix-profile/bin /nix/var/nix/profiles/default/bin /Users/aaron/.nix-profile/bin /nix/var/nix/profiles/default/bin /usr/local/bin /System/Cryptexes/App/usr/bin /usr/bin /bin /usr/sbin /sbin /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin /Library/Apple/usr/bin /usr/local/MacGPG2/bin /Users/aaron/.cargo/bin /Users/aaron/.nix-profile/bin /nix/var/nix/profiles/default/bin ```
Author

Out of curiosity, just did a fresh install of MacOS Ventura on a different computer (vs Sequoia in my original post). Fresh OS install, installed Lix, installed the command line tools using xcode-select --install, the configured and ran my flake using nix develop... Same error with error: tool 'git' not found.

Out of curiosity, just did a fresh install of MacOS Ventura on a different computer (vs Sequoia in my original post). Fresh OS install, installed Lix, installed the command line tools using `xcode-select --install`, the configured and ran my flake using `nix develop`... Same error with `error: tool 'git' not found`.
Author

Ok, I have things working, but I don't understand why.

I noticed that when I was not in a nix development environment, xcode-select --print-path returned /Library/Developer/CommandLineTools.

When I was in a nix development environment, the same command returned /nix/store/6py65dicilvc6qxfra4mzw0xpxw2vc06-apple-sdk-11.3.

Digging into that nix store folder for apple_sdk, I could see many commands were exist in /Library/Developer/CommandLineTools were missing in apple_sdk (including the one I was testing with,git).

Out of curiosity, in the nix environment, I ran xcode-select --switch /Library/Developer/CommandLineTools, and then git and other commands were working fine.

Strangely, I can now exit the nix developer shell, and restart it, and NOT run xcode-select --switch, and things continue to work. If I do run xcode-select --print-path in the nix shell, it still prints /nix/store/6py65dicilvc6qxfra4mzw0xpxw2vc06-apple-sdk-11.3, but for whatever reason, other commands continue to work.

Like I said, I don't understand this, but I'll happily take it. Seems like something about how MacOS and nix are interacting to resolve the Apple developer command line tools was somehow straightened out by running xcode-select --switch /Library/Developer/CommandLineTools that single time.

Ok, I have things working, but I don't understand why. I noticed that when I was not in a nix development environment, `xcode-select --print-path` returned `/Library/Developer/CommandLineTools`. When I was in a nix development environment, the same command returned `/nix/store/6py65dicilvc6qxfra4mzw0xpxw2vc06-apple-sdk-11.3`. Digging into that nix store folder for `apple_sdk`, I could see many commands were exist in `/Library/Developer/CommandLineTools` were missing in `apple_sdk` (including the one I was testing with,`git`). Out of curiosity, in the nix environment, I ran `xcode-select --switch /Library/Developer/CommandLineTools`, and then `git` and other commands were working fine. Strangely, I can now exit the nix developer shell, and restart it, and NOT run `xcode-select --switch`, and things continue to work. If I do run `xcode-select --print-path` in the nix shell, it still prints `/nix/store/6py65dicilvc6qxfra4mzw0xpxw2vc06-apple-sdk-11.3`, but for whatever reason, other commands continue to work. Like I said, I don't understand this, but I'll happily take it. Seems like something about how MacOS and nix are interacting to resolve the Apple developer command line tools was somehow straightened out by running `xcode-select --switch /Library/Developer/CommandLineTools` that single time.
Owner

I wonder, try grepping the output of env for the xcode developer tools store path for nixpkgs' weird ones (the one that doesn't have git in it). It's probably some environment variable overriding the path xcode is using.

I wonder, try grepping the output of `env` for the xcode developer tools store path for nixpkgs' weird ones (the one that doesn't have git in it). It's probably some environment variable overriding the path xcode is using.
Owner

I also find this happens if I run lldb in the lix repo's dev shell. beats me as to why.

I also find this happens if I run `lldb` in the lix repo's dev shell. beats me as to why.
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: lix-project/lix#649
No description provided.