anchor.diff:    sourceRoot = ".";
   
     fixPrebuiltBinary = if stdenv.isDarwin then ''
  -    wrapProgram $(pwd)/crystal-${version}-1/embedded/bin/crystal \
  +    wrapProgram $(pwd)/crystal-${version}-${patch}/embedded/bin/crystal \
           --suffix DYLD_LIBRARY_PATH : $libPath
     ''
     else ''
       patchelf --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \
  -      crystal-${version}-1/embedded/bin/crystal
  +      crystal-${version}-${patch}/embedded/bin/crystal
       patchelf --set-rpath ${ stdenv.lib.makeLibraryPath [ stdenv.cc.cc ] } \
  -      crystal-${version}-1/embedded/bin/crystal
  +      crystal-${version}-${patch}/embedded/bin/crystal
     '';
  +
  +  newline = "\n";
   
     buildPhase = ''
       # patch the script which launches the prebuilt compiler
  -    substituteInPlace $(pwd)/crystal-${version}-1/bin/crystal --replace \
  -      "/usr/bin/env bash" "${stdenv.shell}"
  -    substituteInPlace $(pwd)/crystal-${version}/bin/crystal --replace \
  -      "/usr/bin/env bash" "${stdenv.shell}"
  -
  +    patchShebangs $(pwd)/crystal-${version}-${patch}/bin/crystal
  +    patchShebangs $(pwd)/crystal-${version}/bin/crystal
  +    # Due to https://github.com/crystal-lang/crystal/issues/4719,
  +    # when building Crystal with LLVM 4 with debug infos from prebuilt binary (w/ LLVM 3.8) will always be failed.
  +    # So we are going to build a LLVM 4 version without debug info,
  +    # and use it to build Crystal with debug info on LLVM 4.
  +    substituteInPlace $(pwd)/crystal-${version}/Makefile --replace \
  +      "release ?=" "no_debug ?= ##${newline}force_rebuild ?= ##${newline}release ?="
  +    substituteInPlace $(pwd)/crystal-${version}/Makefile --replace \
  +      "FLAGS := " "FLAGS := \$(if \$(no_debug),--no-debug )"
  +    substituteInPlace $(pwd)/crystal-${version}/Makefile --replace \
  +      "$(O)/crystal:" "\$(O)/crystal: \$(if \$(force_rebuild),../rebuild.tmp)"
       ${fixPrebuiltBinary}
   
       cd crystal-${version}
  -    make release=1 PATH="../crystal-${version}-1/bin:$PATH"
  +    # Build without debug infos on LLVM 4
  +    make release=1 no_debug=1 PATH="../crystal-${version}-${patch}/bin:$PATH"
  +    
  +    # Rebuild Crystal with debug infos from the binary we just built
  +    touch $(pwd)/../rebuild.tmp
  +    wrapProgram .build/crystal \
  +        --suffix LIBRARY_PATH : $libPath
  +    make release=1 force_rebuild=1
       make doc
     '';
   
  
positive.code: { stdenv, fetchurl, boehmgc, libatomic_ops, pcre, libevent, libiconv, llvm_4, makeWrapper }:
  
  stdenv.mkDerivation rec {
    version = "0.23.0";
    name = "crystal-${version}-1";
    arch =
      {
        "x86_64-linux" = "linux-x86_64";
  
negative.code:     wrapProgram $out/bin/crystal \
          --suffix CRYSTAL_PATH : $out/lib/crystal \
          --suffix LIBRARY_PATH : $libPath
      install -dm755 $out/lib/crystal
      cp -r src/* $out/lib/crystal/
  
  