Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmdstan: bump to 2.25.0 #108843

Closed
wants to merge 1 commit into from
Closed

cmdstan: bump to 2.25.0 #108843

wants to merge 1 commit into from

Conversation

adkabo
Copy link

@adkabo adkabo commented Jan 9, 2021

Motivation for this change
Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

Copy link
Member

@prusnak prusnak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change commit message to:

cmdstan: 2.17.1 -> 2.25.0

Other improvements below.

Comment on lines +3 to +7
let
name = "cmdstan";
version = "2.25.0";
in stdenv.mkDerivation {
name = "${name}-${version}";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let
name = "cmdstan";
version = "2.25.0";
in stdenv.mkDerivation {
name = "${name}-${version}";
stdenv.mkDerivation rec {
pname = "cmdstan";
version = "2.25.0";


src = fetchurl {
url = "https://github.com/stan-dev/cmdstan/releases/download/v2.17.1/cmdstan-2.17.1.tar.gz";
sha256 = "1vq1cnrkvrvbfl40j6ajc60jdrjcxag1fi6kff5pqmadfdz9564j";
url =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  src = fetchFromGitHub {
    owner = "stan-dev";
    repo = pname;
    rev = "v${version}";
    sha256 = "TODO";
  };

Copy link
Author

@adkabo adkabo Jan 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This package, cmdstan, uses the stanc3 binary. stanc3 upstream uses nix, but the default.nix pins nixpkgs 19.09.
I haven't figured out a working stanc3 derivation on nixpkgs-unstable that doesn't use import-from-derivation (see below).

Using the release tarball with fetchTarball includes the binaries from stanc3 so it works fine. Using fetchFromGitHub excludes the bin/ directory so it doesn't work.

{ stdenv, fetchFromGitHub, python, runtimeShell, bash, gnumake, gcc }:
let
  stanc3 = import (fetchTarball {
    url = "https://github.com/stan-dev/stanc3/archive/v2.25.0.tar.gz";
    sha256 = "sha256:01iak3ac2hzdrjbyfcsbqiizjd2b4jmb422fxxia0vcw799jwhay";
  });
in stdenv.mkDerivation rec {
  pname = "cmdstan";
  version = "2.25.0";

  src = fetchFromGitHub {
    owner = "stan-dev";
    repo = "cmdstan";
    rev = "v${version}";
    sha256 = "sha256:1s49rhak2phkzqfjx1xmj74frqi79p99n3kcmndm3fbq6b695ag1";
    fetchSubmodules = true;
  };

  buildFlags = [ "build" ];
  enableParallelBuilding = true;

  postPatch = ''

    substituteInPlace stan/lib/stan_math/make/libraries \
        --replace "/usr/bin/env bash" ${bash}/bin/bash

    substituteInPlace stan/lib/stan_math/lib/boost_1.72.0/bootstrap.sh \
        --replace '`which echo`' echo

    patchShebangs .

    mkdir bin
    cp -r ${stanc3}/bin/* bin
    '';

  # Hack to avoid TMPDIR in RPATHs.
  # Copied from https://github.com/NixOS/nixpkgs/commit/f5c568446a12dbf58836925c5487e5cdad1fa578
  preFixup = ''
    rm -rf "$(pwd)"
    mkdir "$(pwd)"
  '';

  doCheck = false;
  checkInputs = [ python ];
  checkPhase = "python ./runCmdStanTests.py src/test/interface"; # see #5368

  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}
    export PATH="$PATH":${gcc}/bin
    ${gnumake}/bin/make -C $out/opt/cmdstan "\$(realpath "\$1")"
    EOF
    chmod a+x $out/bin/stan
  '';

  meta = {
    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";
    license = stdenv.lib.licenses.bsd3;
    platforms = stdenv.lib.platforms.all;
  };
}

};

buildFlags = [ "build" ];
enableParallelBuilding = true;

# Hack to avoid TMPDIR in RPATHs.
# Copied from https://github.com/NixOS/nixpkgs/commit/f5c568446a12dbf58836925c5487e5cdad1fa578
preFixup = ''rm -rf "$(pwd)" && mkdir "$(pwd)" '';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
preFixup = ''rm -rf "$(pwd)" && mkdir "$(pwd)" '';
preFixup = ''
rm -rf "$(pwd)"
mkdir "$(pwd)"
'';

Comment on lines +22 to +26
patchPhase = ''
substituteInPlace stan/lib/stan_math/make/libraries --replace "/usr/bin/env bash" ${bash}/bin/bash

patchShebangs .
'';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
patchPhase = ''
substituteInPlace stan/lib/stan_math/make/libraries --replace "/usr/bin/env bash" ${bash}/bin/bash
patchShebangs .
'';
postPhase = ''
substituteInPlace stan/lib/stan_math/make/libraries --replace "/usr/bin/env bash" ${bash}/bin/bash
patchShebangs .
'';

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find any documentation on postPhase. Is that a typo?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it is. I meant postPatch.

@adkabo
Copy link
Author

adkabo commented Feb 16, 2021

As I mentioned in #108843 (comment), I don't know how to do this without IFD. So I'm closing this for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants