{ lib, stdenv, fetchFromGitHub, python3, stanc, buildPackages, runtimeShell, runCommandCC, cmdstan, }: stdenv.mkDerivation rec { pname = "cmdstan"; version = "2.36.0"; src = fetchFromGitHub { owner = "stan-dev"; repo = "cmdstan"; tag = "v${version}"; fetchSubmodules = true; hash = "sha256-9Dan86C0nxxxkIXaOSKExY0hngAgWTpL4RlI3rTnBZo="; }; postPatch = '' substituteInPlace stan/lib/stan_math/make/libraries \ --replace "/usr/bin/env bash" "bash" ''; nativeBuildInputs = [ python3 stanc ]; preConfigure = '' patchShebangs test-all.sh runCmdStanTests.py stan/ '' # Fix inclusion of hardcoded paths in PCH files, by building in the store. + '' mkdir -p $out/opt cp -R . $out/opt/cmdstan cd $out/opt/cmdstan mkdir -p bin ln -s ${buildPackages.stanc}/bin/stanc bin/stanc ''; makeFlags = [ "build" ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ "arch=${stdenv.hostPlatform.darwinArch}" ]; # Disable inclusion of timestamps in PCH files when using Clang. env.CXXFLAGS = lib.optionalString stdenv.cc.isClang "-Xclang -fno-pch-timestamp"; enableParallelBuilding = true; installPhase = '' runHook preInstall mkdir -p $out/bin ln -s $out/opt/cmdstan/bin/stanc $out/bin/stanc ln -s $out/opt/cmdstan/bin/stansummary $out/bin/stansummary cat > $out/bin/stan <