c++clangdarwinnix-shell

nix-shell -p llvmPackages_8.stdenv doesn't have clang8 set in env


I'm trying to build a C++ project that requires a rather old version of clang, namely version 8. That project doesn't have any default.nix or shell.nix.

I tried:

> nix-shell -p llvmPackages_8.stdenv
[nix-shell:~/git/the-project]$ clang --version
clang version 11.1.0
Target: x86_64-apple-darwin
Thread model: posix
InstalledDir: /nix/store/s759kzdnl4p740wj1965bcygwn88n4xx-clang-11.1.0/bin

As you can see the clang version is not the one I expected it to be. I also tried

Am I getting something wrong with nix-shell?


Solution

  • I found it out my self. This is how I overcame the problem. I created a shell.nix in the repo with this content:

    with import <nixpkgs> {};
    llvmPackages.libcxxStdenv.mkDerivation {
      name = "env";
      nativeBuildInputs = [ clang-tools ];
      buildInputs = [ cmake openssl_1_1 python ] ++ lib.optionals libcxxStdenv.isDarwin (with darwin.apple_sdk.frameworks; [
        Cocoa
        CoreServices
      ]);
    }