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

96 lines
2.3 KiB
Nix
Raw Normal View History

2023-12-18 00:10:37 +00:00
{ lib
, stdenv
, fetchFromGitHub
, python3
, stanc
, buildPackages
, runtimeShell
, runCommandCC
, cmdstan
}:
2015-12-11 12:35:17 +00:00
2022-12-08 13:19:42 +00:00
stdenv.mkDerivation rec {
pname = "cmdstan";
2024-06-04 03:32:45 +01:00
version = "2.35.0";
2023-01-08 22:57:02 +00:00
src = fetchFromGitHub {
owner = "stan-dev";
repo = pname;
rev = "v${version}";
fetchSubmodules = true;
2024-06-04 03:32:45 +01:00
hash = "sha256-bmzkXbR4KSnpfXjs2MAx8mbNSbNrIWDP/O8S+JGWrcg=";
2023-01-08 22:57:02 +00:00
};
2022-04-13 19:51:50 +01:00
postPatch = ''
substituteInPlace stan/lib/stan_math/make/libraries \
--replace "/usr/bin/env bash" "bash"
'';
2023-12-18 00:10:37 +00:00
nativeBuildInputs = [
python3
stanc
];
2023-01-08 22:57:02 +00:00
preConfigure = ''
2023-12-18 00:10:37 +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-08 22:57:02 +00:00
mkdir -p bin
ln -s ${buildPackages.stanc}/bin/stanc bin/stanc
'';
2023-12-18 00:10:37 +00:00
makeFlags = [
"build"
] ++ lib.optionals stdenv.isDarwin [
"arch=${stdenv.hostPlatform.darwinArch}"
];
2023-01-08 22:57:02 +00:00
2023-12-18 00:10:37 +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;
2015-12-11 12:35:17 +00:00
installPhase = ''
2023-12-18 00:10:37 +00:00
runHook preInstall
mkdir -p $out/bin
2015-12-11 12:35:17 +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}
2015-12-11 12:35:17 +00:00
make -C $out/opt/cmdstan "\$(realpath "\$1")"
EOF
chmod a+x $out/bin/stan
2023-12-18 00:10:37 +00:00
runHook postInstall
2015-12-11 12:35:17 +00:00
'';
2023-12-18 00:10:37 +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-04-13 19:51:50 +01: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
};
}