How to install a specific version of Clang?

Hi all,

I’m currently trying to reproduce some old bugs in clang version 3.9.0 and older. I thought that using nix to fix the compiler would make it easier to reproduce the bugs. I have looked at the resources:

However they seem to be more interested in using Clang as the compiler of another package, instead of as an individual executable. My current best effort try is using autoPatchelfHook and wrapCC in an overlay.

  final: prev: let
    pkgs = final;
  in {
    clang-3_9_0 = pkgs.wrapCC (pkgs.stdenv.mkDerivation {
      name = "clang-3_9_0";
      version = "3.9.0";
      src = fetchTarball {
        url = "https://releases.llvm.org/3.9.0/clang+llvm-3.9.0-x86_64-linux-gnu-ubuntu-14.04.tar.xz";
        sha256 = "sha256:12b8zgl84pg42xfaiyyg4g0i5yfsp1w50yzzpzxgjaasddiqpbh3";
      };
      nativeBuildInputs = with pkgs; [autoPatchelfHook];

      buildInputs = with pkgs; [glibc gcc-unwrapped ncurses5 zlib];
      passthru.isClang = true;
      installPhase = ''
        mkdir -p $out/bin
        cp $src/bin/clang $out/bin/clang-3.9.0
      '';
    });
  }

Which actually fares pretty well, but fails while linking:

$ clang-3.9.0 test.c
/nix/store/2ab5740x0cy1d74qvbpl5s28qikmppl5-binutils-2.40/bin/ld: cannot find crt1.o: No such file or directory
/nix/store/2ab5740x0cy1d74qvbpl5s28qikmppl5-binutils-2.40/bin/ld: cannot find crti.o: No such file or directory
/nix/store/2ab5740x0cy1d74qvbpl5s28qikmppl5-binutils-2.40/bin/ld: cannot find crtbegin.o: No such file or directory
/nix/store/2ab5740x0cy1d74qvbpl5s28qikmppl5-binutils-2.40/bin/ld: cannot find -lgcc: No such file or directory
/nix/store/2ab5740x0cy1d74qvbpl5s28qikmppl5-binutils-2.40/bin/ld: cannot find -lgcc_s: No such file or directory
clang-3.9.0: error: linker command failed with exit code 1 (use -v to see invocation)

Where the content of test is:

$ cat test.c 
int main() {
  return 0;
}

I’m clearly not an expert in compiling C and I’m sure that I’m missing something obvious, and I’ll appreciate any help I can get!