2023-01-11 07:51:40 +00:00
|
|
|
{ lib, stdenv, fetchFromGitHub, stanc, python3, buildPackages, runtimeShell }:
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-12-17 10:02:37 +00:00
|
|
|
stdenv.mkDerivation rec {
|
|
|
|
pname = "cmdstan";
|
2023-05-24 13:37:59 +00:00
|
|
|
version = "2.32.2";
|
2023-01-11 07:51:40 +00:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "stan-dev";
|
|
|
|
repo = pname;
|
|
|
|
rev = "v${version}";
|
|
|
|
fetchSubmodules = true;
|
2023-05-24 13:37:59 +00:00
|
|
|
hash = "sha256-obV+R1ZjBgunXndCNry+MEne1nQawo81IV2DWwYbbIQ=";
|
2023-01-11 07:51:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
nativeBuildInputs = [ stanc ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
buildFlags = [ "build" ];
|
|
|
|
enableParallelBuilding = true;
|
|
|
|
|
|
|
|
doCheck = true;
|
2023-02-02 18:25:31 +00:00
|
|
|
nativeCheckInputs = [ python3 ];
|
2022-05-18 14:49:53 +00:00
|
|
|
|
2022-08-12 12:06:08 +00:00
|
|
|
CXXFLAGS = lib.optionalString stdenv.isDarwin "-D_BOOST_LGAMMA";
|
|
|
|
|
2022-05-18 14:49:53 +00:00
|
|
|
postPatch = ''
|
|
|
|
substituteInPlace stan/lib/stan_math/make/libraries \
|
|
|
|
--replace "/usr/bin/env bash" "bash"
|
|
|
|
patchShebangs .
|
2022-12-17 10:02:37 +00:00
|
|
|
'' + lib.optionalString stdenv.isAarch64 ''
|
|
|
|
sed -z -i "s/TEST(CommandStansummary, check_console_output).*TEST(CommandStansummary, check_csv_output)/TEST(CommandStansummary, check_csv_output)/" \
|
|
|
|
src/test/interface/stansummary_test.cpp
|
2022-05-18 14:49:53 +00:00
|
|
|
'';
|
|
|
|
|
2023-01-11 07:51:40 +00:00
|
|
|
preConfigure = ''
|
|
|
|
mkdir -p bin
|
|
|
|
ln -s ${buildPackages.stanc}/bin/stanc bin/stanc
|
|
|
|
'';
|
|
|
|
|
|
|
|
makeFlags = lib.optional stdenv.isDarwin "arch=${stdenv.hostPlatform.darwinArch}";
|
|
|
|
|
2022-05-18 14:49:53 +00:00
|
|
|
checkPhase = ''
|
|
|
|
./runCmdStanTests.py -j$NIX_BUILD_CORES src/test/interface
|
|
|
|
'';
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out/opt $out/bin
|
|
|
|
cp -r . $out/opt/cmdstan
|
|
|
|
ln -s $out/opt/cmdstan/bin/stanc $out/bin/stanc
|
|
|
|
ln -s $out/opt/cmdstan/bin/stansummary $out/bin/stansummary
|
|
|
|
cat > $out/bin/stan <<EOF
|
|
|
|
#!${runtimeShell}
|
|
|
|
make -C $out/opt/cmdstan "\$(realpath "\$1")"
|
|
|
|
EOF
|
|
|
|
chmod a+x $out/bin/stan
|
|
|
|
'';
|
|
|
|
|
2022-05-18 14:49:53 +00:00
|
|
|
# Hack to ensure that patchelf --shrink-rpath get rids of a $TMPDIR reference.
|
2022-12-17 10:02:37 +00:00
|
|
|
preFixup = "rm -rf stan";
|
2022-05-18 14:49:53 +00:00
|
|
|
|
2023-01-11 07:51:40 +00:00
|
|
|
meta = with lib; {
|
2020-04-24 23:36:52 +00:00
|
|
|
description = "Command-line interface to Stan";
|
|
|
|
longDescription = ''
|
|
|
|
Stan is a probabilistic programming language implementing full Bayesian
|
|
|
|
statistical inference with MCMC sampling (NUTS, HMC), approximate Bayesian
|
|
|
|
inference with Variational inference (ADVI) and penalized maximum
|
|
|
|
likelihood estimation with Optimization (L-BFGS).
|
|
|
|
'';
|
|
|
|
homepage = "https://mc-stan.org/interfaces/cmdstan.html";
|
2023-01-11 07:51:40 +00:00
|
|
|
license = licenses.bsd3;
|
|
|
|
maintainers = with maintainers; [ wegank ];
|
|
|
|
platforms = platforms.unix;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
}
|