anchor.diff:         else throw "mpi type ${mpiName} not supported";
   
   in stdenv.mkDerivation {
  -  name = "bagel-${version}";
  +  name = "bagel-${version}" + lib.optionalString (blasName != "openblas") "-${blasName}";
   
     src = fetchFromGitHub {
       owner = "nubakery";
       repo = "bagel";
       rev = "v${version}";
  -    sha256 = "1yxkhqd9rng02g3zd7c1b32ish1b0gkrvfij58v5qrd8yaiy6pyy";
  +    sha256 = "1c6pz3b73i4mly0pw1gv5cn1p88b1gjjyqn5nh1xspp3pfls6fs5";
     };
   
  -  nativeBuildInputs = [ autoconf automake libtool openssh ];
  -  buildInputs = [ python boost libxc openblas scalapack mpi ];
  +  nativeBuildInputs = [ autoconf automake libtool openssh boost159 ];
  +  buildInputs = [ python boost159 libxc blas mpi ] 
  +                ++ lib.optional (scalapack != null) scalapack;
   
  -  CXXFLAGS="-DNDEBUG -O3 -mavx -lopenblas";
  +  #
  +  # Furthermore, if relativistic calculations fail without MKL,
  +  # users may consider reconfiguring and recompiling with -DZDOT_RETURN in CXXFLAGS.
  +  CXXFLAGS="-DNDEBUG -O3 -mavx -DCOMPILE_J_ORB "
  +           + lib.optionalString (blasName == "openblas") "-lopenblas -DZDOT_RETURN"
  +           + lib.optionalString (blasName == "mkl") "-L${blas}/lib/intel64";
   
  -  configureFlags = [ "--with-libxc" "--with-mpi=${mpiType}" ];
  +  LDFLAGS = lib.optionalString (blasName == "mkl") "-L${blas}/lib/intel64";
   
  -  outputs = [ "out" "tests" ];
  +  BOOST_ROOT=boost159;
  +
  +  configureFlags = [ "--with-libxc" "--with-mpi=${mpiType}" "--with-boost=${boost159}" ] 
  +                   ++ lib.optional ( blasName == "mkl" ) "--enable-mkl";
  +
  +#  outputs = [ "out" ];
   
     postPatch = ''
       # Fixed upstream
  
positive.code:     EOF
      chmod 755 $out/bin/bagel
  
      # copy test jobs
      mkdir -p $tests/
      cp test/* $tests 
    '';
  
    installCheckPhase = ''
  
negative.code: { stdenv, lib, pkgs, fetchFromGitHub, autoconf, automake, libtool
  , python, boost159, mpi ? pkgs.openmpi, libxc, fetchpatch, blas
  , scalapack ? null, makeWrapper, openssh
  } :
  
  let
    version = "1.1.2";
  
    blasName = (builtins.parseDrvName blas.name).name;
  
    mpiName = (builtins.parseDrvName mpi.name).name;
    mpiType = if mpiName == "openmpi" then mpiName
  