How to make mkShell to use clang's stdenv?

I have a following “default” shell.nix for hacking on random projects:

with import <nixpkgs> {};
pkgs.mkShell {
  buildInputs = [
    pkgconfig
    python cmake
    openssl zlib libgit2 libxml2 pcre
    xorg.libX11
    ncurses
    gtk3 glib
    vulkan-loader
  ];
  shellHook = ''
    export LD_LIBRARY_PATH="${vulkan-loader}/lib:${xlibs.libX11.out}/lib"
  '';
}

How do I modify it such that it uses clang’s stdenv? So that CC is clang, etc.

1 Like

Looking at the definition, I would try to use (mkShell.override { stdenv = clangStdenv; }).

3 Likes

Indeed, that did the trick!

Here’s full example:

with import <nixpkgs> {};
(mkShell.override { stdenv = llvmPackages_10.stdenv; }) {
  buildInputs = [
    pkgconfig
    python cmake
    openssl zlib libgit2 libxml2 pcre
    xorg.libX11
    ncurses
    gtk3 glib
    vulkan-loader
    llvmPackages.libclang
  ];
  shellHook = ''
    export LD_LIBRARY_PATH="${vulkan-loader}/lib:${xlibs.libX11.out}/lib:${llvmPackages.libclang}/lib"
  '';
}

Meta question: shouldn’t this forum have “mark as a solution” checkbox?
Meta answer: it has, if you actually tag your question as learn :smiley:

1 Like