sage: 8.1 -> 8.2, use system packages

This commit is contained in:
Timo Kaufmann
2018-06-30 01:21:31 +02:00
parent 84d89a1ec6
commit 17e6b391eb
37 changed files with 2695 additions and 413 deletions
+224 -223
View File
@@ -1,230 +1,231 @@
# TODO
# - consider writing a script to convert spkgs to nix packages, similar to vim
# or cabal2nix. This would allow a more efficient and "cleaner" build, greater
# flexibility and the possibility to select which dependencies to add and which
# to remove. It would also allow to use system packages for some dependencies
# and recompile others (optimized for the system) without recompiling everything.
# - add optdeps:
# - imagemagick
# - texlive full for documentation
# - ...
# - further seperate build outputs. Also maybe run `make doc`.
# Configure flags like --bindir and --libdir oculd also be used for that, see
# ./configure --help`.
# Other resources:
# - https://wiki.debian.org/DebianScience/Sage
# - https://github.com/cschwan/sage-on-gentoo
# - https://git.archlinux.org/svntogit/community.git/tree/trunk?h=packages/sagemath
{ stdenv
, bash
, fetchurl
, perl
, gfortran6
, python
, autoreconfHook
, gettext
, which
, texlive
, texinfo
, hevea
, buildDocs ? false
, optimize ? false # optimize sage to the current system (obviously impure)
{ nixpkgs
, withDoc ? false
}:
stdenv.mkDerivation rec {
version = "8.1";
name = "sage-${version}";
let
inherit (nixpkgs) fetchpatch fetchurl symlinkJoin fetchFromGitHub callPackage nodePackages_8_x;
# Modified version of patchShebangs that patches to the sage-internal version if possible
# and falls back to the system version if not.
patchSageShebangs = ./patchSageShebangs.sh;
src = fetchurl {
# Note that the source is *not* fetched from github, since that doesn't
# the upstream folder with all the source tarballs of the spkgs.
# If those are not present they are fetched at build time, which breaks
# when building in a sandbox (and probably only works if you install the
# latest sage version).
urls = [
"http://mirrors.mit.edu/sage/src/sage-${version}.tar.gz"
"ftp://ftp.fu-berlin.de/unix/misc/sage/src/sage-${version}.tar.gz"
"http://sagemath.polytechnic.edu.na/src/sage-${version}.tar.gz"
"ftp://ftp.sun.ac.za/pub/mirrors/www.sagemath.org/src/sage-${version}.tar.gz"
"http://sagemath.mirror.ac.za/src/sage-${version}.tar.gz"
"https://ftp.leg.uct.ac.za/pub/packages/sage/src/sage-${version}.tar.gz"
"http://mirror.ufs.ac.za/sagemath/src/sage-${version}.tar.gz"
"https://mirrors-usa.go-parts.com/sage/sagemath/src/sage-${version}.tar.gz"
"http://www.cecm.sfu.ca/sage/src/sage-${version}.tar.gz"
"http://files.sagemath.org/src/sage-${version}.tar.gz"
"https://mirrors.xmission.com/sage/src/sage-${version}.tar.gz"
"http://sagemath.c3sl.ufpr.br/src/sage-${version}.tar.gz"
"http://linorg.usp.br/sage/src/sage-${version}.tar.gz"
"http://mirror.hust.edu.cn/sagemath/src/sage-${version}.tar.gz"
"https://ftp.iitm.ac.in/sage/src/sage-${version}.tar.gz"
"http://ftp.kaist.ac.kr/sage/src/sage-${version}.tar.gz"
"https://ftp.riken.jp/sagemath/src/sage-${version}.tar.gz"
"https://mirrors.tuna.tsinghua.edu.cn/sagemath/src/sage-${version}.tar.gz"
"https://mirrors.ustc.edu.cn/sagemath/src/sage-${version}.tar.gz"
"http://ftp.tsukuba.wide.ad.jp/software/sage/src/sage-${version}.tar.gz"
"https://ftp.yz.yamagata-u.ac.jp/pub/math/sage/src/sage-${version}.tar.gz"
"https://mirror.yandex.ru/mirrors/sage.math.washington.edu/src/sage-${version}.tar.gz"
"https://mirror.aarnet.edu.au/pub/sage/src/sage-${version}.tar.gz"
"https://sage.mirror.garr.it/mirrors/sage/src/sage-${version}.tar.gz"
"https://www.mirrorservice.org/sites/www.sagemath.org/src/sage-${version}.tar.gz"
"http://mirror.switch.ch/mirror/sagemath/src/sage-${version}.tar.gz"
"https://mirrors.up.pt/pub/sage/src/sage-${version}.tar.gz"
"http://www-ftp.lip6.fr/pub/math/sagemath/src/sage-${version}.tar.gz"
"http://ftp.ntua.gr/pub/sagemath/src/sage-${version}.tar.gz"
# https://trac.sagemath.org/ticket/15980 for tracking of python3 support
python = nixpkgs.python2.override {
packageOverrides = self: super: {
cypari2 = super.cypari2.override { inherit pari; };
cysignals = super.cysignals.override { inherit pari; };
cvxopt = super.cvxopt.override { inherit glpk; };
# https://github.com/sagemath/sagenb/issues/437
flask-babel = super.flask-babel.overridePythonAttrs (attrs: rec {
version = "0.9";
src = attrs.src.override {
inherit version;
sha256 = "0k7vk4k54y55ma0nx2k5s0phfqbriwslhy5shh3b0d046q7ibzaa";
};
doCheck = false;
});
# python packages that appear unmaintained and were not accepted into the nixpkgs
# tree because of that. These packages are only dependencies of the more-or-less
# deprecated sagenb. However sagenb is still a default dependency and the doctests
# depend on it.
# See https://github.com/NixOS/nixpkgs/pull/38787 for a discussion.
flask-oldsessions = self.callPackage ./flask-oldsessions.nix {};
flask-openid = self.callPackage ./flask-openid.nix {};
python-openid = self.callPackage ./python-openid.nix {};
pybrial = self.callPackage ./pybrial.nix {};
sagelib = self.callPackage ./sagelib.nix {
inherit flint ecl pari glpk eclib;
inherit sage-src openblas-blas-pc openblas-cblas-pc openblas-lapack-pc pynac singular;
linbox = nixpkgs.linbox.override { withSage = true; };
# tracking: https://trac.sagemath.org/ticket/24927
arb = nixpkgs.arb.overrideAttrs (attrs: rec {
name = "arb-${version}";
version = "2.12.0";
doCheck = false; # https://github.com/fredrik-johansson/arb/issues/194
src = fetchFromGitHub {
owner = "fredrik-johansson";
repo = attrs.pname;
rev = version;
sha256 = "18bwxlcbqb70cj7l9x6w1h4yghrqfhmbhdby373q8vdrdfx58niq";
};
});
};
sagenb = self.callPackage ./sagenb.nix {
mathjax = nodePackages_8_x.mathjax;
};
sagedoc = self.callPackage ./sagedoc.nix {
inherit sage-src;
};
env-locations = self.callPackage ./env-locations.nix {
inherit pari_data ecl pari;
inherit singular;
three = nodePackages_8_x.three;
mathjax = nodePackages_8_x.mathjax;
};
sage-env = self.callPackage ./sage-env.nix {
inherit sage-src python rWrapper openblas-cblas-pc glpk ecl singular eclib pari palp flint pynac pythonEnv;
pkg-config = nixpkgs.pkgconfig; # not to confuse with pythonPackages.pkgconfig
};
sage-with-env = self.callPackage ./sage-with-env.nix {
inherit pari eclib pythonEnv;
inherit sage-src openblas-blas-pc openblas-cblas-pc openblas-lapack-pc pynac singular;
pkg-config = nixpkgs.pkgconfig; # not to confuse with pythonPackages.pkgconfig
three = nodePackages_8_x.three;
};
sage = self.callPackage ./sage.nix { };
sage-wrapper = self.callPackage ./sage-wrapper.nix {
inherit sage-src withDoc;
};
};
};
openblas-blas-pc = callPackage ./openblas-pc.nix { name = "blas"; };
openblas-cblas-pc = callPackage ./openblas-pc.nix { name = "cblas"; };
openblas-lapack-pc = callPackage ./openblas-pc.nix { name = "lapack"; };
sage-src = callPackage ./sage-src.nix {};
pythonRuntimeDeps = with python.pkgs; [
sagelib
pybrial
sagenb
cvxopt
networkx
service-identity
psutil
sympy
fpylll
matplotlib
scipy
ipywidgets
rpy2
sphinx
typing
pillow
];
pythonEnv = python.buildEnv.override {
extraLibs = pythonRuntimeDeps;
ignoreCollisions = true;
} // { extraLibs = pythonRuntimeDeps; }; # make the libs accessible
# needs to be rWrapper, standard "R" doesn't include default packages
rWrapper = nixpkgs.rWrapper.override {
# https://trac.sagemath.org/ticket/25674
R = nixpkgs.R.overrideAttrs (attrs: rec {
name = "R-3.4.4";
src = fetchurl {
url = "http://cran.r-project.org/src/base/R-3/${name}.tar.gz";
sha256 = "0dq3jsnwsb5j3fhl0wi3p5ycv8avf8s5j1y4ap3d2mkjmcppvsdk";
};
});
};
# update causes issues
# https://groups.google.com/forum/#!topic/sage-packaging/cS3v05Q0zso
# https://trac.sagemath.org/ticket/24735
singular = nixpkgs.singular.overrideAttrs (oldAttrs: {
name = "singular-4.1.0p3";
src = fetchurl {
url = "http://www.mathematik.uni-kl.de/ftp/pub/Math/Singular/SOURCES/4-1-0/singular-4.1.0p3.tar.gz";
sha256 = "105zs3zk46b1cps403ap9423rl48824ap5gyrdgmg8fma34680a4";
};
});
# *not* to confuse with the python package "pynac"
# https://trac.sagemath.org/ticket/24838 (depends on arb update)
pynac = (nixpkgs.pynac.override { inherit singular; }).overrideAttrs (oldAttrs: rec {
name = "pynac-0.7.16";
src = fetchFromGitHub {
owner = "pynac";
repo = "pynac";
rev = name;
sha256 = "106an189sg4rpgzfrmy3699271vg4ddazw9wvh51wx7qnm1v86ik";
};
});
eclib = nixpkgs.eclib.override { inherit pari; };
# With openblas (64 bit), the tests fail the same way as when sage is build with
# openblas instead of openblasCompat. Apparently other packages somehow use flints
# blas when it is available. Alternative would be to override flint to use
# openblasCompat.
flint = nixpkgs.flint.override { withBlas = false; };
# Multiple palp dimensions need to be available and sage expects them all to be
# in the same folder.
palp = symlinkJoin {
name = "palp-${nixpkgs.palp.version}";
paths = [
(nixpkgs.palp.override { dimensions = 4; doSymlink = false; })
(nixpkgs.palp.override { dimensions = 5; doSymlink = false; })
(nixpkgs.palp.override { dimensions = 6; doSymlink = true; })
(nixpkgs.palp.override { dimensions = 11; doSymlink = false; })
];
sha256 = "1cpcs1mr0yii64s152xmxyd450bfzjb22jjj0zh9y3n6g9alzpyq";
};
postPatch = ''
substituteAllInPlace src/bin/sage-env
bash=${bash} substituteAllInPlace build/bin/sage-spkg
'';
installPhase = ''
# Sage installs during first `make`, `make install` is no-op and just takes time.
'';
outputs = [ "out" ] ++ stdenv.lib.optionals (buildDocs) [ "doc" ];
buildInputs = [
bash # needed for the build
perl # needed for the build
python # needed for the build
gfortran6 # needed to build giac, openblas
autoreconfHook # needed to configure sage with prefix
gettext # needed to build the singular spkg
which # needed in configure of mpir
texinfo # needed to build maxima
] ++ stdenv.lib.optionals(buildDocs) [
hevea # needed to build the docs of the giac spkg
(texlive.combine { inherit (texlive)
scheme-basic
collection-pstricks # needed by giac
times # font needed by giac
stmaryrd # needed by giac
babel-greek # optional for giac, otherwise throws a bunch of latex command not founds
;
})
];
nativeBuildInputs = [ gfortran6 perl which ];
patches = [
# fix usages of /bin/rm
./spkg-singular.patch
# help python find the crypt library
# patches python3 and indirectly python2, since those installation files are symlinked
./spkg-python.patch
# fix usages of /usr/bin/perl
./spkg-git.patch
# fix usages of /bin/cp and add necessary argument to function call
./spkg-giac.patch
# environment
./env.patch
# adjust wrapper shebang and patch shebangs after each spkg build
./shebangs.patch
];
enableParallelBuilding = true;
hardeningDisable = [
"format" # needed to build palp, for lines like `printf(ctime(&_NFL->TIME))`
# TODO could be patched with `sed s|printf(ctime(\(.*\)))|%s... or fixed upstream
];
configureFlags = stdenv.lib.optionals(buildDocs) [ "--docdir=$(doc)" ];
preConfigure = ''
export SAGE_NUM_THREADS="$NIX_BUILD_CORES"
export HOME=/tmp/sage-home
export SAGE_ROOT="$PWD"
export SAGE_SRC="$PWD"
mkdir -p "$HOME"
mkdir -p "$out"
# we need to keep the source around
dir="$PWD"
cd ..
mv "$dir" "$out/sage-root"
export SAGE_SPKG_INSTALL_DOCS='no'
cd "$out/sage-root" # build in target dir, since `make` is also `make install`
''
+ stdenv.lib.optionalString (buildDocs) ''
mkdir -p "$doc"
export SAGE_DOC="$doc"
export SAGE_DOCBUILD_OPTS="--no-pdf-links -k"
''
+ stdenv.lib.optionalString (!optimize) ''
export SAGE_FAT_BINARY=yes
'';
buildFlags = if (buildDocs) then "doc" else "build";
# for reference: http://doc.sagemath.org/html/en/installation/source.html
preBuild = ''
# symlink python to make sure the shebangs are patched to the sage path
# while still being able to use python before building it
# (this is important because otherwise sage will try to install python
# packages globally later on)
ln -s "${python}/bin/python2" $out/bin/python2
ln -s "$out/bin/python2" $out/bin/python
touch $out/bin/python3
bash $patchSageShebangs .
'';
postBuild = ''
# Clean up
rm -r "$out/sage-root/upstream" # don't keep the sources of all the spkgs
rm -rf "$out/sage-root/src/build"
rm -rf "$out/sage-root/src/autom4te.cache"
rm -rf "$out/sage-root/src/config"
rm -rf "$out/sage-root/src/m4"
rm -rf "$out/sage-root/.git"
rm -r "$out/sage-root/logs"
rm -r "$out"/lib/python*/test
# Fix dependency cycle between out and doc
rm -f "$out/sage-root/config.log"
rm -f "$out/sage-root/config.status"
rm -f "$out/sage-root/build/make/Makefile-auto"
rm -f "$out/sage-home/.sage/gap/libgap-workspace-"*
# Make sure unnessessary packages don't end up in the build closure
find "$out" \
-iname 'config.log' \
-delete \
-or -iname 'Makefile' \
-delete
rm -f "$out/lib/R/etc/Renviron"
# Make sure all shebangs are properly patched
bash $patchSageShebangs $out
'';
# TODO there are some doctest failures, which seem harmless.
# We should figure out a way to fix the failures or ignore only those tests.
doCheck = false;
checkTarget = "ptestalllong"; # all long tests in parallell
preCheck = ''
export SAGE_TIMEOUT=0 # no timeout
export SAGE_TIMEOUT_LONG=0 # no timeout
'';
meta = {
homepage = http://www.sagemath.org;
description = "A free open source mathematics software system";
# taken from the homepage
longDescription = ''
SageMath is a free open-source mathematics software system licensed under the GPL. It builds on top of many existing open-source packages: NumPy, SciPy, matplotlib, Sympy, Maxima, GAP, FLINT, R and many more. Access their combined power through a common, Python-based language or directly via interfaces or wrappers.
Mission: Creating a viable free open source alternative to Magma, Maple, Mathematica and Matlab.
'';
license = stdenv.lib.licenses.gpl2Plus;
platforms = ["x86_64-linux" "i686-linux"];
maintainers = with stdenv.lib.maintainers; [ timokau ];
# Sage expects those in the same directory.
pari_data = symlinkJoin {
name = "pari_data";
paths = with nixpkgs; [
pari-galdata
pari-seadata-small
];
};
}
# https://trac.sagemath.org/ticket/22191
ecl = nixpkgs.ecl_16_1_2;
# sage currently uses an unreleased version of pari
pari = (nixpkgs.pari.override { withThread = false; }).overrideAttrs (attrs: rec {
version = "2.10-1280-g88fb5b3"; # on update remove pari-stackwarn patch from `sage-src.nix`
src = fetchurl {
url = "mirror://sageupstream/pari/pari-${version}.tar.gz";
sha256 = "19gbsm8jqq3hraanbmsvzkbh88iwlqbckzbnga3y76r7k42akn7m";
};
});
# https://trac.sagemath.org/ticket/24824
glpk = nixpkgs.glpk.overrideAttrs (attrs: rec {
version = "4.63";
name = "glpk-${version}";
src = fetchurl {
url = "mirror://gnu/glpk/${name}.tar.gz";
sha256 = "1xp7nclmp8inp20968bvvfcwmz3mz03sbm0v3yjz8aqwlpqjfkci";
};
patches = (attrs.patches or []) ++ [
# Alternatively patch sage with debians
# https://sources.debian.org/data/main/s/sagemath/8.1-7/debian/patches/t-version-glpk-4.60-extra-hack-fixes.patch
# The header of that debian patch contains a good description of the issue. The gist of it:
# > If GLPK in Sage causes one error, and this is caught by Sage and recovered from, then
# > later (because upstream GLPK does not clear the "error" flag) Sage will append
# > all subsequent terminal output of GLPK into the error_message string but not
# > actually forward it to the user's terminal. This breaks some doctests.
(fetchpatch {
name = "error_recovery.patch";
url = "https://git.sagemath.org/sage.git/plain/build/pkgs/glpk/patches/error_recovery.patch?id=07d6c37d18811e2b377a9689790a7c5e24da16ba";
sha256 = "0z99z9gd31apb6x5n5n26411qzx0ma3s6dnznc4x61x86bhq31qf";
})
# Allow setting a exact verbosity level (OFF|ERR|ON|ALL|DBG)
(fetchpatch {
name = "exact_verbosity.patch";
url = "https://git.sagemath.org/sage.git/plain/build/pkgs/glpk/patches/glp_exact_verbosity.patch?id=07d6c37d18811e2b377a9689790a7c5e24da16ba";
sha256 = "15gm5i2alqla3m463i1qq6jx6c0ns6lip7njvbhp37pgxg4s9hx8";
})
];
});
in
python.pkgs.sage-wrapper // {
doc = python.pkgs.sagedoc;
lib = python.pkgs.sagelib;
}