2024-01-02 11:29:13 +00:00
|
|
|
{ lib
|
|
|
|
, stdenv
|
|
|
|
, fetchFromGitHub
|
|
|
|
, python3
|
|
|
|
, stanc
|
|
|
|
, buildPackages
|
|
|
|
, runtimeShell
|
|
|
|
, runCommandCC
|
|
|
|
, cmdstan
|
|
|
|
}:
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-12-17 10:02:37 +00:00
|
|
|
stdenv.mkDerivation rec {
|
|
|
|
pname = "cmdstan";
|
2024-06-20 14:57:18 +00:00
|
|
|
version = "2.35.0";
|
2023-01-11 07:51:40 +00:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "stan-dev";
|
|
|
|
repo = pname;
|
|
|
|
rev = "v${version}";
|
|
|
|
fetchSubmodules = true;
|
2024-06-20 14:57:18 +00:00
|
|
|
hash = "sha256-bmzkXbR4KSnpfXjs2MAx8mbNSbNrIWDP/O8S+JGWrcg=";
|
2023-01-11 07:51:40 +00:00
|
|
|
};
|
|
|
|
|
2022-05-18 14:49:53 +00:00
|
|
|
postPatch = ''
|
|
|
|
substituteInPlace stan/lib/stan_math/make/libraries \
|
|
|
|
--replace "/usr/bin/env bash" "bash"
|
|
|
|
'';
|
|
|
|
|
2024-01-02 11:29:13 +00:00
|
|
|
nativeBuildInputs = [
|
|
|
|
python3
|
|
|
|
stanc
|
|
|
|
];
|
|
|
|
|
2023-01-11 07:51:40 +00:00
|
|
|
preConfigure = ''
|
2024-01-02 11:29:13 +00:00
|
|
|
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
|
2023-01-11 07:51:40 +00:00
|
|
|
mkdir -p bin
|
|
|
|
ln -s ${buildPackages.stanc}/bin/stanc bin/stanc
|
|
|
|
'';
|
|
|
|
|
2024-01-02 11:29:13 +00:00
|
|
|
makeFlags = [
|
|
|
|
"build"
|
2024-09-26 11:04:55 +00:00
|
|
|
] ++ lib.optionals stdenv.hostPlatform.isDarwin [
|
2024-01-02 11:29:13 +00:00
|
|
|
"arch=${stdenv.hostPlatform.darwinArch}"
|
|
|
|
];
|
2023-01-11 07:51:40 +00:00
|
|
|
|
2024-01-02 11:29:13 +00:00
|
|
|
# Disable inclusion of timestamps in PCH files when using Clang.
|
|
|
|
env.CXXFLAGS = lib.optionalString stdenv.cc.isClang "-Xclang -fno-pch-timestamp";
|
|
|
|
|
|
|
|
enableParallelBuilding = true;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
installPhase = ''
|
2024-01-02 11:29:13 +00:00
|
|
|
runHook preInstall
|
|
|
|
|
|
|
|
mkdir -p $out/bin
|
2020-04-24 23:36:52 +00:00
|
|
|
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
|
2024-01-02 11:29:13 +00:00
|
|
|
|
|
|
|
runHook postInstall
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
|
2024-01-02 11:29:13 +00:00
|
|
|
passthru.tests = {
|
|
|
|
test = runCommandCC "cmdstan-test" { } ''
|
|
|
|
cp -R ${cmdstan}/opt/cmdstan cmdstan
|
|
|
|
chmod -R +w cmdstan
|
|
|
|
cd cmdstan
|
|
|
|
./runCmdStanTests.py -j$NIX_BUILD_CORES src/test/interface
|
|
|
|
touch $out
|
|
|
|
'';
|
|
|
|
};
|
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
|
|
|
};
|
|
|
|
}
|