nixpkgs/pkgs/development/compilers/cmdstan/default.nix

74 lines
2.2 KiB
Nix
Raw Normal View History

2023-01-08 22:57:02 +00:00
{ lib, stdenv, fetchFromGitHub, stanc, python3, buildPackages, runtimeShell }:
2015-12-11 12:35:17 +00:00
2022-12-08 13:19:42 +00:00
stdenv.mkDerivation rec {
pname = "cmdstan";
2023-01-08 22:57:02 +00:00
version = "2.31.0";
src = fetchFromGitHub {
owner = "stan-dev";
repo = pname;
rev = "v${version}";
fetchSubmodules = true;
sha256 = "sha256-Uh/ZhEnbhQwC8xGFjDzH9No3VRgVbHYk2KoC+e3YhJw=";
};
nativeBuildInputs = [ stanc ];
2015-12-11 12:35:17 +00:00
buildFlags = [ "build" ];
2015-12-11 12:35:17 +00:00
enableParallelBuilding = true;
doCheck = true;
nativeCheckInputs = [ python3 ];
2022-04-13 18:51:50 +00:00
2022-06-18 04:20:00 +00:00
CXXFLAGS = lib.optionalString stdenv.isDarwin "-D_BOOST_LGAMMA";
2022-04-13 18:51:50 +00:00
postPatch = ''
substituteInPlace stan/lib/stan_math/make/libraries \
--replace "/usr/bin/env bash" "bash"
patchShebangs .
2022-12-08 13:19:42 +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-04-13 18:51:50 +00:00
'';
2023-01-08 22:57:02 +00:00
preConfigure = ''
mkdir -p bin
ln -s ${buildPackages.stanc}/bin/stanc bin/stanc
'';
makeFlags = lib.optional stdenv.isDarwin "arch=${stdenv.hostPlatform.darwinArch}";
2022-04-13 18:51:50 +00:00
checkPhase = ''
./runCmdStanTests.py -j$NIX_BUILD_CORES src/test/interface
'';
2015-12-11 12:35:17 +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}
2015-12-11 12:35:17 +00:00
make -C $out/opt/cmdstan "\$(realpath "\$1")"
EOF
chmod a+x $out/bin/stan
'';
2022-04-13 18:51:50 +00:00
# Hack to ensure that patchelf --shrink-rpath get rids of a $TMPDIR reference.
2022-12-08 13:19:42 +00:00
preFixup = "rm -rf stan";
2022-04-13 18:51:50 +00:00
2023-01-08 22:57:02 +00:00
meta = with lib; {
2015-12-11 12:35:17 +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-08 22:57:02 +00:00
license = licenses.bsd3;
maintainers = with maintainers; [ wegank ];
platforms = platforms.unix;
2015-12-11 12:35:17 +00:00
};
}