summary refs log tree commit diff
path: root/pkgs/applications/science
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/applications/science')
-rw-r--r--pkgs/applications/science/logic/cryptoverif/default.nix6
-rw-r--r--pkgs/applications/science/math/giac/default.nix4
-rw-r--r--pkgs/applications/science/math/maxima/default.nix4
-rw-r--r--pkgs/applications/science/math/nauty/default.nix2
-rw-r--r--pkgs/applications/science/math/pari/default.nix3
-rw-r--r--pkgs/applications/science/math/pynac/default.nix9
-rw-r--r--pkgs/applications/science/math/sage/default.nix65
-rw-r--r--pkgs/applications/science/math/sage/env-locations.nix2
-rw-r--r--pkgs/applications/science/math/sage/flask-oldsessions.nix36
-rw-r--r--pkgs/applications/science/math/sage/flask-openid.nix28
-rw-r--r--pkgs/applications/science/math/sage/patches/Only-test-py2-py3-optional-tests-when-all-of-sage-is.patch21
-rw-r--r--pkgs/applications/science/math/sage/patches/do-not-test-find-library.patch33
-rw-r--r--pkgs/applications/science/math/sage/patches/docutils-0.15.patch24
-rw-r--r--pkgs/applications/science/math/sage/patches/ignore-cmp-deprecation.patch30
-rw-r--r--pkgs/applications/science/math/sage/patches/ignore-werkzeug-immutable-dict-deprecation.patch12
-rw-r--r--pkgs/applications/science/math/sage/patches/pari-stackwarn.patch20
-rw-r--r--pkgs/applications/science/math/sage/patches/pillow-update.patch39
-rw-r--r--pkgs/applications/science/math/sage/patches/python-5755-hotpatch.patch28
-rw-r--r--pkgs/applications/science/math/sage/patches/register-pretty-printer-earlier.patch36
-rw-r--r--pkgs/applications/science/math/sage/patches/sagenb-cmp-deprecation.patch13
-rw-r--r--pkgs/applications/science/math/sage/patches/sagespawn-implicit-casting.patch13
-rw-r--r--pkgs/applications/science/math/sage/patches/sphinx-docbuild-subprocesses.patch2
-rw-r--r--pkgs/applications/science/math/sage/patches/sympow-cache.patch14
-rw-r--r--pkgs/applications/science/math/sage/pybrial.nix25
-rw-r--r--pkgs/applications/science/math/sage/python-openid.nix40
-rw-r--r--pkgs/applications/science/math/sage/sage-env.nix25
-rw-r--r--pkgs/applications/science/math/sage/sage-src.nix136
-rw-r--r--pkgs/applications/science/math/sage/sage-with-env.nix8
-rw-r--r--pkgs/applications/science/math/sage/sage.nix1
-rw-r--r--pkgs/applications/science/math/sage/sagedoc.nix24
-rw-r--r--pkgs/applications/science/math/sage/sagelib.nix4
-rw-r--r--pkgs/applications/science/math/sage/sagenb.nix57
-rw-r--r--pkgs/applications/science/misc/simgrid/default.nix4
33 files changed, 294 insertions, 474 deletions
diff --git a/pkgs/applications/science/logic/cryptoverif/default.nix b/pkgs/applications/science/logic/cryptoverif/default.nix
index 28295ea2892..78861786def 100644
--- a/pkgs/applications/science/logic/cryptoverif/default.nix
+++ b/pkgs/applications/science/logic/cryptoverif/default.nix
@@ -2,11 +2,11 @@
 
 stdenv.mkDerivation rec {
   pname = "cryptoverif";
-  version = "2.03pl1";
+  version = "2.04";
 
   src = fetchurl {
     url    = "http://prosecco.gforge.inria.fr/personal/bblanche/cryptoverif/cryptoverif${version}.tar.gz";
-    sha256 = "0q7qa1qm7mbky3m36445gdmgmkb9mrhrdsk7mmwn8fzw0rfc6z00";
+    sha256 = "1mzk6n0g2vdsv38y493zg85lxrpz72b92cmsray3g970xzanqd6s";
   };
 
   buildInputs = [ ocaml ];
@@ -15,7 +15,7 @@ stdenv.mkDerivation rec {
   ** from under $out/libexec. By default, it expects to find the files
   ** in $CWD which doesn't work. */
   patchPhase = ''
-    substituteInPlace ./src/settings.ml \
+    substituteInPlace ./src/syntax.ml \
       --replace \"default\" \"$out/libexec/default\"
   '';
 
diff --git a/pkgs/applications/science/math/giac/default.nix b/pkgs/applications/science/math/giac/default.nix
index ea9c921f19e..b090274919b 100644
--- a/pkgs/applications/science/math/giac/default.nix
+++ b/pkgs/applications/science/math/giac/default.nix
@@ -9,11 +9,11 @@ assert (!blas.isILP64) && (!lapack.isILP64);
 
 stdenv.mkDerivation rec {
   pname = "giac${lib.optionalString enableGUI "-with-xcas"}";
-  version = "1.5.0-21"; # TODO try to remove preCheck phase on upgrade
+  version = "1.5.0-87"; # TODO try to remove preCheck phase on upgrade
 
   src = fetchurl {
     url = "https://www-fourier.ujf-grenoble.fr/~parisse/debian/dists/stable/main/source/giac_${version}.tar.gz";
-    sha256 = "1b9khiv0mk2xzw1rblm2jy6qsf8y6f9k7qy15sxpb21d72hzzbl2";
+    sha256 = "1d0h1yb7qvh9x7wwv9yrzmcp712f49w1iljkxp4y6g9pzsmg1mmv";
   };
 
   patches = stdenv.lib.optionals (!enableGUI) [
diff --git a/pkgs/applications/science/math/maxima/default.nix b/pkgs/applications/science/math/maxima/default.nix
index 1bf7d16f290..cdc81a87646 100644
--- a/pkgs/applications/science/math/maxima/default.nix
+++ b/pkgs/applications/science/math/maxima/default.nix
@@ -87,6 +87,10 @@ stdenv.mkDerivation ({
 
   enableParallelBuilding = true;
 
+  passthru = {
+    ecl = ecl;
+  };
+
   meta = {
     description = "Computer algebra system";
     homepage = "http://maxima.sourceforge.net";
diff --git a/pkgs/applications/science/math/nauty/default.nix b/pkgs/applications/science/math/nauty/default.nix
index 76e7c796a13..94b7ad266c4 100644
--- a/pkgs/applications/science/math/nauty/default.nix
+++ b/pkgs/applications/science/math/nauty/default.nix
@@ -7,7 +7,7 @@ stdenv.mkDerivation rec {
   version = "27r1";
   src = fetchurl {
     url = "http://pallini.di.uniroma1.it/nauty${version}.tar.gz";
-    sha256 = "1nym0p2djws8ylkpr0kgpxfa6fxdlh46cmvz0gn5vd02jzgs0aww";
+    sha256 = "0xsfqfcknbd6g6wzpa5l7crmmk3bf3zjh37rhylq6b20dqcmvjkn";
   };
   outputs = [ "out" "dev" ];
   configureFlags = [
diff --git a/pkgs/applications/science/math/pari/default.nix b/pkgs/applications/science/math/pari/default.nix
index a3e2f99ab27..7ec42d11ab1 100644
--- a/pkgs/applications/science/math/pari/default.nix
+++ b/pkgs/applications/science/math/pari/default.nix
@@ -15,7 +15,8 @@ stdenv.mkDerivation rec {
   version = "2.11.4";
 
   src = fetchurl {
-    url = "https://pari.math.u-bordeaux.fr/pub/pari/unix/${pname}-${version}.tar.gz";
+    # Versions with current majorMinor values are at http://pari.math.u-bordeaux.fr/pub/pari/unix/${pname}-${version}.tar.gz
+    url = "https://pari.math.u-bordeaux.fr/pub/pari/OLD/${stdenv.lib.versions.majorMinor version}/${pname}-${version}.tar.gz";
     sha256 = "sha256-v8iPxPc1L0hA5uNSxy8DacvqikVAOxg0piafNwmXCxw=";
   };
 
diff --git a/pkgs/applications/science/math/pynac/default.nix b/pkgs/applications/science/math/pynac/default.nix
index 87fb205174b..e3474d865e2 100644
--- a/pkgs/applications/science/math/pynac/default.nix
+++ b/pkgs/applications/science/math/pynac/default.nix
@@ -1,5 +1,6 @@
 { stdenv
 , fetchFromGitHub
+, fetchurl
 , autoreconfHook
 , pkgconfig
 , flint
@@ -33,6 +34,14 @@ stdenv.mkDerivation rec {
     pkgconfig
   ];
 
+  patches = [
+    (fetchurl {
+      name = "py_ssize_t_clean.patch";
+      url = "https://git.sagemath.org/sage.git/plain/build/pkgs/pynac/patches/py_ssize_t_clean.patch?h=9.2";
+      sha256 = "0l3gbg9hc4v671zf4w376krnk3wh8hj3649610nlvzzxckcryzab";
+    })
+  ];
+
   meta = with stdenv.lib; {
     description = "Python is Not a CAS -- modified version of Ginac";
     longDescription = ''
diff --git a/pkgs/applications/science/math/sage/default.nix b/pkgs/applications/science/math/sage/default.nix
index caf51c3da25..416f2b957b7 100644
--- a/pkgs/applications/science/math/sage/default.nix
+++ b/pkgs/applications/science/math/sage/default.nix
@@ -9,31 +9,13 @@
 let
   inherit (pkgs) symlinkJoin callPackage nodePackages;
 
-  # https://trac.sagemath.org/ticket/15980 for tracking of python3 support
-  python = pkgs.python2.override {
+  python3 = pkgs.python3.override {
     packageOverrides = self: super: {
-      # 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.
-      # The dependency on the sage notebook (and therefore these packages) will be
-      # removed in the future:
-      # https://trac.sagemath.org/ticket/25837
-      flask-oldsessions = self.callPackage ./flask-oldsessions.nix {};
-      flask-openid = self.callPackage ./flask-openid.nix {};
-      python-openid = self.callPackage ./python-openid.nix {};
-      sagenb = self.callPackage ./sagenb.nix {
-        mathjax = nodePackages.mathjax;
-      };
-
-      # Package with a cyclic dependency with sage
-      pybrial = self.callPackage ./pybrial.nix {};
-
       # `sagelib`, i.e. all of sage except some wrappers and runtime dependencies
       sagelib = self.callPackage ./sagelib.nix {
-        inherit flint ecl arb;
+        inherit flint arb;
         inherit sage-src env-locations pynac singular;
+        ecl = maxima-ecl.ecl;
         linbox = pkgs.linbox.override { withSage = true; };
         pkg-config = pkgs.pkgconfig; # not to confuse with pythonPackages.pkgconfig
       };
@@ -59,9 +41,10 @@ let
   # A bash script setting various environment variables to tell sage where
   # the files its looking fore are located. Also see `sage-env`.
   env-locations = callPackage ./env-locations.nix {
-    inherit pari_data ecl;
+    inherit pari_data;
     inherit singular maxima-ecl;
-    cysignals = python.pkgs.cysignals;
+    ecl = maxima-ecl.ecl;
+    cysignals = python3.pkgs.cysignals;
     three = nodePackages.three;
     mathjax = nodePackages.mathjax;
   };
@@ -69,21 +52,22 @@ let
   # The shell file that gets sourced on every sage start. Will also source
   # the env-locations file.
   sage-env = callPackage ./sage-env.nix {
-    sagelib = python.pkgs.sagelib;
+    sagelib = python3.pkgs.sagelib;
     inherit env-locations;
-    inherit python ecl singular palp flint pynac pythonEnv maxima-ecl;
+    inherit python3 singular palp flint pynac pythonEnv maxima-ecl;
+    ecl = maxima-ecl.ecl;
     pkg-config = pkgs.pkgconfig; # not to confuse with pythonPackages.pkgconfig
   };
 
   # The documentation for sage, building it takes a lot of ram.
   sagedoc = callPackage ./sagedoc.nix {
     inherit sage-with-env;
-    inherit python maxima-ecl;
+    inherit python3 maxima-ecl;
   };
 
   # sagelib with added wrappers and a dependency on sage-tests to make sure thet tests were run.
   sage-with-env = callPackage ./sage-with-env.nix {
-    inherit pythonEnv;
+    inherit python3 pythonEnv;
     inherit sage-env;
     inherit pynac singular maxima-ecl;
     pkg-config = pkgs.pkgconfig; # not to confuse with pythonPackages.pkgconfig
@@ -100,10 +84,8 @@ let
 
   sage-src = callPackage ./sage-src.nix {};
 
-  pythonRuntimeDeps = with python.pkgs; [
+  pythonRuntimeDeps = with python3.pkgs; [
     sagelib
-    pybrial
-    sagenb
     cvxopt
     networkx
     service-identity
@@ -116,11 +98,10 @@ let
     ipywidgets
     rpy2
     sphinx
-    typing
     pillow
   ];
 
-  pythonEnv = python.buildEnv.override {
+  pythonEnv = python3.buildEnv.override {
     extraLibs = pythonRuntimeDeps;
     ignoreCollisions = true;
   } // { extraLibs = pythonRuntimeDeps; }; # make the libs accessible
@@ -129,8 +110,21 @@ let
 
   singular = pkgs.singular.override { inherit flint; };
 
-  # https://trac.sagemath.org/ticket/26625
-  maxima-ecl = pkgs.maxima-ecl;
+  maxima-ecl = pkgs.maxima-ecl.override {
+    ecl = pkgs.ecl.override {
+      # "echo syntax error | ecl > /dev/full 2>&1" segfaults in
+      # ECL. We apply a patch to fix it (write_error.patch), but it
+      # only works if threads are disabled.  sage 9.2 tests this
+      # (src/sage/interfaces/tests.py) and ships ecl like so.
+      # https://gitlab.com/embeddable-common-lisp/ecl/-/merge_requests/1#note_1657275
+      threadSupport = false;
+
+      # if we don't use the system boehmgc, sending a SIGINT to ecl
+      # can segfault if we it happens during memory allocation.
+      # src/sage/libs/ecl.pyx would intermittently fail in this case.
+      useBoehmgc = true;
+    };
+  };
 
   # *not* to confuse with the python package "pynac"
   pynac = pkgs.pynac.override { inherit singular flint; };
@@ -161,9 +155,6 @@ let
       pari-seadata-small
     ];
   };
-
-  # https://trac.sagemath.org/ticket/22191
-  ecl = pkgs.ecl_16_1_2;
 in
 # A wrapper around sage that makes sure sage finds its docs (if they were build).
 callPackage ./sage.nix {
diff --git a/pkgs/applications/science/math/sage/env-locations.nix b/pkgs/applications/science/math/sage/env-locations.nix
index bda2d23b9e5..b1ad0aad9c7 100644
--- a/pkgs/applications/science/math/sage/env-locations.nix
+++ b/pkgs/applications/science/math/sage/env-locations.nix
@@ -44,6 +44,6 @@ writeTextFile rec {
     export JSMOL_DIR="${jmol}/share/jsmol"
     export MATHJAX_DIR="${mathjax}/lib/node_modules/mathjax"
     export THREEJS_DIR="${three}/lib/node_modules/three"
-    export SAGE_INCLUDE_DIRECTORIES="${cysignals}/lib/python2.7/site-packages"
+    export SAGE_INCLUDE_DIRECTORIES="${cysignals}/${cysignals.pythonModule.sitePackages}"
   '';
 }
diff --git a/pkgs/applications/science/math/sage/flask-oldsessions.nix b/pkgs/applications/science/math/sage/flask-oldsessions.nix
deleted file mode 100644
index 86fe9912c19..00000000000
--- a/pkgs/applications/science/math/sage/flask-oldsessions.nix
+++ /dev/null
@@ -1,36 +0,0 @@
-{ stdenv
-, buildPythonPackage
-, fetchFromGitHub
-, python
-, flask
-}:
-
-buildPythonPackage rec {
-  pname = "Flask-OldSessions";
-  version = "0.10";
-
-  # no artifact on pypi: https://github.com/mitsuhiko/flask-oldsessions/issues/1
-  src = fetchFromGitHub {
-    owner = "mitsuhiko";
-    repo = "flask-oldsessions";
-    rev = version;
-    sha256 = "04b5m8njjiwld9a0zw55iqwvyjgwcpdbhz1cic8nyhgcmypbicqn";
-  };
-
-  propagatedBuildInputs = [
-    flask
-  ];
-
-  # missing module flask.testsuite, probably assumes an old version of flask
-  doCheck = false;
-  checkPhase = ''
-    ${python.interpreter} run-tests.py
-  '';
-
-  meta = with stdenv.lib; {
-    description = "Provides a session class that works like the one in Flask before 0.10.";
-    license = licenses.bsd2;
-    maintainers = teams.sage.members;
-    homepage = "https://github.com/mitsuhiko/flask-oldsessions";
-  };
-}
diff --git a/pkgs/applications/science/math/sage/flask-openid.nix b/pkgs/applications/science/math/sage/flask-openid.nix
deleted file mode 100644
index 900b033429e..00000000000
--- a/pkgs/applications/science/math/sage/flask-openid.nix
+++ /dev/null
@@ -1,28 +0,0 @@
-{ stdenv
-, buildPythonPackage
-, fetchPypi
-, flask
-, python-openid
-}:
-
-buildPythonPackage rec {
-  pname = "Flask-OpenID";
-  version = "1.2.5";
-
-  src = fetchPypi {
-    inherit pname version;
-    sha256 = "1aycwmwi7ilcaa5ab8hm0bp6323zl8z25q9ha0gwrl8aihfgx3ss";
-  };
-
-  propagatedBuildInputs = [
-    flask
-    python-openid
-  ];
-
-  meta = with stdenv.lib; {
-    description = "Adds openid support to flask applications";
-    license = licenses.bsd2;
-    maintainers = teams.sage.members;
-    homepage = "https://pythonhosted.org/Flask-OpenID/";
-  };
-}
diff --git a/pkgs/applications/science/math/sage/patches/Only-test-py2-py3-optional-tests-when-all-of-sage-is.patch b/pkgs/applications/science/math/sage/patches/Only-test-py2-py3-optional-tests-when-all-of-sage-is.patch
index 8cd80281d0e..d5c19a54fd9 100644
--- a/pkgs/applications/science/math/sage/patches/Only-test-py2-py3-optional-tests-when-all-of-sage-is.patch
+++ b/pkgs/applications/science/math/sage/patches/Only-test-py2-py3-optional-tests-when-all-of-sage-is.patch
@@ -1,17 +1,17 @@
-From 8218bd4fdeb4c92de8af0d3aabec55980fc4fb3d Mon Sep 17 00:00:00 2001
+From f5ea42a7aaed7611fb55b65897b9fcf2b7bcf97e Mon Sep 17 00:00:00 2001
 From: Timo Kaufmann <timokau@zoho.com>
 Date: Sun, 21 Oct 2018 17:52:40 +0200
 Subject: [PATCH] Only test py2/py3 optional tests when all of sage is tested
 
 ---
- src/sage/doctest/control.py | 5 +++--
- 1 file changed, 3 insertions(+), 2 deletions(-)
+ src/sage/doctest/control.py | 3 ++-
+ 1 file changed, 2 insertions(+), 1 deletion(-)
 
 diff --git a/src/sage/doctest/control.py b/src/sage/doctest/control.py
-index bf18df8b2b..935c67abf7 100644
+index 2d93841e50..6d156e29a1 100644
 --- a/src/sage/doctest/control.py
 +++ b/src/sage/doctest/control.py
-@@ -362,7 +362,8 @@ class DocTestController(SageObject):
+@@ -375,7 +375,8 @@ class DocTestController(SageObject):
                      if not optionaltag_regex.search(o):
                          raise ValueError('invalid optional tag {!r}'.format(o))
  
@@ -21,15 +21,6 @@ index bf18df8b2b..935c67abf7 100644
  
          self.options = options
  
-@@ -765,7 +766,7 @@ class DocTestController(SageObject):
-             sage: DC = DocTestController(DD, [dirname])
-             sage: DC.expand_files_into_sources()
-             sage: sorted(DC.sources[0].options.optional)  # abs tol 1
--            ['guava', 'magma', 'py2']
-+            ['guava', 'magma']
- 
-         We check that files are skipped appropriately::
- 
 -- 
-2.18.1
+2.28.0
 
diff --git a/pkgs/applications/science/math/sage/patches/do-not-test-find-library.patch b/pkgs/applications/science/math/sage/patches/do-not-test-find-library.patch
index 3f844e1b1ef..98175920238 100644
--- a/pkgs/applications/science/math/sage/patches/do-not-test-find-library.patch
+++ b/pkgs/applications/science/math/sage/patches/do-not-test-find-library.patch
@@ -1,17 +1,17 @@
 diff --git a/src/sage/env.py b/src/sage/env.py
-index 061b94f3f1..67cd091540 100644
+index 1ddfc7cfb9..45033d6328 100644
 --- a/src/sage/env.py
 +++ b/src/sage/env.py
-@@ -189,88 +189,13 @@ var('MAXIMA_FAS')
+@@ -203,97 +203,13 @@ var('ARB_LIBRARY',                   'arb')
  var('SAGE_BANNER', '')
  var('SAGE_IMPORTALL', 'yes')
  
 -
 -def _get_shared_lib_filename(libname, *additional_libnames):
 -    """
--    Return the full path to a shared library file installed in the standard
--    location for the system within the ``LIBDIR`` prefix (or
--    ``$SAGE_LOCAL/lib`` in the case of manual build of Sage).
+-    Return the full path to a shared library file installed in
+-    ``$SAGE_LOCAL/lib`` or the directories associated with the
+-    Python sysconfig.
 -
 -    This can also be passed more than one library name (e.g. for cases where
 -    some library may have multiple names depending on the platform) in which
@@ -25,7 +25,7 @@ index 061b94f3f1..67cd091540 100644
 -    For distributions like Debian that use a multiarch layout, we also try the
 -    multiarch lib paths (i.e. ``/usr/lib/<arch>/``).
 -
--    Returns ``None`` if the file does not exist.
+-    This returns ``None`` if the file does not exist.
 -
 -    EXAMPLES::
 -
@@ -48,11 +48,17 @@ index 061b94f3f1..67cd091540 100644
 -
 -    for libname in (libname,) + additional_libnames:
 -        if sys.platform == 'cygwin':
--            bindir = sysconfig.get_config_var('BINDIR')
+-            # Later down we take the last matching DLL found, so search
+-            # SAGE_LOCAL second so that it takes precedence
+-            bindirs = [
+-                sysconfig.get_config_var('BINDIR'),
+-                os.path.join(SAGE_LOCAL, 'bin')
+-            ]
 -            pats = ['cyg{}.dll'.format(libname), 'cyg{}-*.dll'.format(libname)]
 -            filenames = []
--            for pat in pats:
--                filenames += glob.glob(os.path.join(bindir, pat))
+-            for bindir in bindirs:
+-                for pat in pats:
+-                    filenames += glob.glob(os.path.join(bindir, pat))
 -
 -            # Note: This is not very robust, since if there are multi DLL
 -            # versions for the same library this just selects one more or less
@@ -66,10 +72,13 @@ index 061b94f3f1..67cd091540 100644
 -            else:
 -                ext = 'so'
 -
--            libdirs = [sysconfig.get_config_var('LIBDIR')]
+-            libdirs = [
+-                os.path.join(SAGE_LOCAL, 'lib'),
+-                sysconfig.get_config_var('LIBDIR')
+-            ]
 -            multilib = sysconfig.get_config_var('MULTILIB')
 -            if multilib:
--                libdirs.insert(0, os.path.join(libdirs[0], multilib))
+-                libdirs.insert(1, os.path.join(libdirs[0], multilib))
 -
 -            for libdir in libdirs:
 -                basename = 'lib{}.{}'.format(libname, ext)
@@ -89,7 +98,7 @@ index 061b94f3f1..67cd091540 100644
  
  # locate libgap shared object
 -GAP_SO= _get_shared_lib_filename('gap','')
-+GAP_SO= '/default'
++GAP_SO = '/default'
  var('GAP_SO', GAP_SO)
  
  # post process
diff --git a/pkgs/applications/science/math/sage/patches/docutils-0.15.patch b/pkgs/applications/science/math/sage/patches/docutils-0.15.patch
deleted file mode 100644
index 63f5d2e146d..00000000000
--- a/pkgs/applications/science/math/sage/patches/docutils-0.15.patch
+++ /dev/null
@@ -1,24 +0,0 @@
-diff --git a/src/sage/misc/sphinxify.py b/src/sage/misc/sphinxify.py
-index 4849c2bffa..76b7bc8602 100644
---- a/src/sage/misc/sphinxify.py
-+++ b/src/sage/misc/sphinxify.py
-@@ -25,6 +25,7 @@ from __future__ import absolute_import, print_function
- import os
- import re
- import shutil
-+import warnings
- from tempfile import mkdtemp
- from sphinx.application import Sphinx
- 
-@@ -120,7 +121,10 @@ smart_quotes = no""")
-     # buildername, confoverrides, status, warning, freshenv).
-     sphinx_app = Sphinx(srcdir, confdir, outdir, doctreedir, format,
-                         confoverrides, None, None, True)
--    sphinx_app.build(None, [rst_name])
-+    with warnings.catch_warnings():
-+        # Quick and dirty workaround for https://trac.sagemath.org/ticket/28856#comment:19
-+        warnings.simplefilter("ignore")
-+        sphinx_app.build(None, [rst_name])
-     sys.path = old_sys_path
- 
-     # We need to remove "_" from __builtin__ that the gettext module installs
diff --git a/pkgs/applications/science/math/sage/patches/ignore-cmp-deprecation.patch b/pkgs/applications/science/math/sage/patches/ignore-cmp-deprecation.patch
index 11ca7481961..a91ee319b8f 100644
--- a/pkgs/applications/science/math/sage/patches/ignore-cmp-deprecation.patch
+++ b/pkgs/applications/science/math/sage/patches/ignore-cmp-deprecation.patch
@@ -1,24 +1,24 @@
 diff --git a/src/sage/tests/cmdline.py b/src/sage/tests/cmdline.py
-index bd6b76ab82..ccf1203dec 100644
+index 6e034dcb5a..8ec60ec72b 100644
 --- a/src/sage/tests/cmdline.py
 +++ b/src/sage/tests/cmdline.py
-@@ -837,8 +837,6 @@ def test_executable(args, input="", timeout=100.0, **kwds):
+@@ -660,8 +660,8 @@ def test_executable(args, input="", timeout=100.0, pydebug_ignore_warnings=False
+         sage: with open(input, 'w') as F:
+         ....:     _ = F.write(s)
+         sage: L = ["sage", "--rst2ipynb", input, output]
+-        sage: test_executable(L)                              # optional - rst2ipynb
+-        ('', '', 0)
++        sage: test_executable(L)[2]                           # optional - rst2ipynb
++        0
+         sage: import json                                     # optional - rst2ipynb
+         sage: d = json.load(open(output,'r'))                 # optional - rst2ipynb
+         sage: type(d)                                         # optional - rst2ipynb
+@@ -757,8 +757,6 @@ def test_executable(args, input="", timeout=100.0, pydebug_ignore_warnings=False
          ///
          4
          }}}
--        sage: err # py2
+-        sage: err # py2 # optional -- sagenb
 -        ''
-         sage: ret
+         sage: ret # py2 # optional -- sagenb
          0
  
-@@ -871,8 +869,8 @@ def test_executable(args, input="", timeout=100.0, **kwds):
-         sage: output = tmp_filename(ext='.sws')
-         sage: with open(input, 'w') as F:
-         ....:     _ = F.write(s)
--        sage: test_executable(["sage", "--rst2sws", input, output]) # py2
--        ('', '', 0)
-+        sage: test_executable(["sage", "--rst2sws", input, output])[2] # py2
-+        0
-         sage: import tarfile # py2
-         sage: f = tarfile.open(output, 'r') # py2
-         sage: print(f.extractfile('sage_worksheet/worksheet.html').read()) # py2
diff --git a/pkgs/applications/science/math/sage/patches/ignore-werkzeug-immutable-dict-deprecation.patch b/pkgs/applications/science/math/sage/patches/ignore-werkzeug-immutable-dict-deprecation.patch
deleted file mode 100644
index c5f95b498d5..00000000000
--- a/pkgs/applications/science/math/sage/patches/ignore-werkzeug-immutable-dict-deprecation.patch
+++ /dev/null
@@ -1,12 +0,0 @@
-diff --git a/src/sage/all.py b/src/sage/all.py
-index c87c9372e9..862fca4fcc 100644
---- a/src/sage/all.py
-+++ b/src/sage/all.py
-@@ -306,6 +306,7 @@ warnings.filters.remove(('ignore', None, DeprecationWarning, None, 0))
- # Ignore all deprecations from IPython etc.
- warnings.filterwarnings('ignore', category=DeprecationWarning,
-     module='.*(IPython|ipykernel|jupyter_client|jupyter_core|nbformat|notebook|ipywidgets|storemagic)')
-+warnings.filterwarnings('ignore', category=DeprecationWarning, message=r".*The import 'werkzeug.ImmutableDict' is deprecated")
- # Ignore collections.abc warnings, there are a lot of them but they are
- # harmless.
- warnings.filterwarnings('ignore', category=DeprecationWarning,
diff --git a/pkgs/applications/science/math/sage/patches/pari-stackwarn.patch b/pkgs/applications/science/math/sage/patches/pari-stackwarn.patch
deleted file mode 100644
index 49cdfd189b9..00000000000
--- a/pkgs/applications/science/math/sage/patches/pari-stackwarn.patch
+++ /dev/null
@@ -1,20 +0,0 @@
-diff --git a/src/sage/doctest/parsing.py b/src/sage/doctest/parsing.py
-index 6bdc9a0..31fc780 100644
---- a/src/sage/doctest/parsing.py
-+++ b/src/sage/doctest/parsing.py
-@@ -40,6 +40,7 @@ from .external import available_software
- 
- float_regex = re.compile('\s*([+-]?\s*((\d*\.?\d+)|(\d+\.?))([eE][+-]?\d+)?)')
- optional_regex = re.compile(r'(py2|py3|long time|not implemented|not tested|known bug)|([^ a-z]\s*optional\s*[:-]*((\s|\w)*))')
-+pari_stack_warning_regex = re.compile(r'\s*\*\*\*.*(Warning: increasing stack size to )\d+\.')
- find_sage_prompt = re.compile(r"^(\s*)sage: ", re.M)
- find_sage_continuation = re.compile(r"^(\s*)\.\.\.\.:", re.M)
- random_marker = re.compile('.*random', re.I)
-@@ -935,6 +936,7 @@ class SageOutputChecker(doctest.OutputChecker):
-             <type 'float'>
-         """
-         got = self.human_readable_escape_sequences(got)
-+        got = pari_stack_warning_regex.sub('', got)
-         if isinstance(want, MarkedOutput):
-             if want.random:
-                 return True
diff --git a/pkgs/applications/science/math/sage/patches/pillow-update.patch b/pkgs/applications/science/math/sage/patches/pillow-update.patch
new file mode 100644
index 00000000000..19d61552262
--- /dev/null
+++ b/pkgs/applications/science/math/sage/patches/pillow-update.patch
@@ -0,0 +1,39 @@
+diff --git a/src/sage/repl/image.py b/src/sage/repl/image.py
+index d7d00b0..cd1607a 100644
+--- a/src/sage/repl/image.py
++++ b/src/sage/repl/image.py
+@@ -77,7 +77,7 @@ class Image(SageObject):
+ 
+         - ``size`` -- 2-tuple, containing (width, height) in pixels.
+ 
+-        - ``color`` -- string or tuple of numeric. What colour to use
++        - ``color`` -- string, numeric or tuple of numeric. What colour to use
+           for the image. Default is black.  If given, this should be a
+           a tuple with one value per band. When creating RGB images,
+           you can also use colour strings as supported by the
+@@ -91,9 +91,15 @@ class Image(SageObject):
+         EXAMPLES::
+ 
+             sage: from sage.repl.image import Image
+-            sage: Image('P', (16, 16), (13,))
++            sage: Image('P', (16, 16), 13)
+             16x16px 8-bit Color image
+         """
++        # pillow does not support Sage integers as color
++        from sage.rings.integer import Integer
++        if isinstance(color, Integer):
++            color = int(color)
++        elif isinstance(color, tuple):
++            color = tuple(int(i) if isinstance(i, Integer) else i for i in color)
+         self._pil = PIL.Image.new(mode, size, color)
+ 
+     @property
+@@ -233,7 +239,7 @@ class Image(SageObject):
+         EXAMPLES::
+ 
+             sage: from sage.repl.image import Image
+-            sage: img = Image('P', (12, 34), (13,))
++            sage: img = Image('P', (12, 34), 13)
+             sage: filename = tmp_filename(ext='.png')
+             sage: img.save(filename)
+             sage: with open(filename, 'rb') as f:
diff --git a/pkgs/applications/science/math/sage/patches/python-5755-hotpatch.patch b/pkgs/applications/science/math/sage/patches/python-5755-hotpatch.patch
deleted file mode 100644
index 1b64f39fe60..00000000000
--- a/pkgs/applications/science/math/sage/patches/python-5755-hotpatch.patch
+++ /dev/null
@@ -1,28 +0,0 @@
-diff --git a/src/sage/all.py b/src/sage/all.py
-index ca309ef..be3186b 100644
---- a/src/sage/all.py
-+++ b/src/sage/all.py
-@@ -298,6 +298,23 @@ warnings.filterwarnings('ignore', module='matplotlib[.]font_manager')
- warnings.filterwarnings('default',
-     '[\s\S]*See http://trac.sagemath.org/[0-9]* for details.')
- 
-+# Hotpatch around https://bugs.python.org/issue5755 which won't be fixed for
-+# python 2.7. Idea by https://stackoverflow.com/a/36293331.
-+from distutils.command.build_ext import build_ext
-+from distutils.sysconfig import customize_compiler
-+
-+_build_extensions = build_ext.build_extensions
-+
-+def build_extensions_patched(self):
-+    customize_compiler(self.compiler)
-+    try:
-+        self.compiler.compiler_so.remove("-Wstrict-prototypes")
-+    except (AttributeError, ValueError):
-+        pass
-+    _build_extensions(self)
-+
-+build_ext.build_extensions = build_extensions_patched
-+
- 
- # Set a new random number seed as the very last thing
- # (so that printing initial_seed() and using that seed
diff --git a/pkgs/applications/science/math/sage/patches/register-pretty-printer-earlier.patch b/pkgs/applications/science/math/sage/patches/register-pretty-printer-earlier.patch
new file mode 100644
index 00000000000..83bd83a6d33
--- /dev/null
+++ b/pkgs/applications/science/math/sage/patches/register-pretty-printer-earlier.patch
@@ -0,0 +1,36 @@
+diff --git a/src/sage/doctest/forker.py b/src/sage/doctest/forker.py
+index cb3667659e..867f547d71 100644
+--- a/src/sage/doctest/forker.py
++++ b/src/sage/doctest/forker.py
+@@ -200,6 +200,15 @@ def init_sage(controller=None):
+     from sage.cpython._py2_random import Random
+     sage.misc.randstate.DEFAULT_PYTHON_RANDOM = Random
+ 
++    # IPython's pretty printer sorts the repr of dicts by their keys by default
++    # (or their keys' str() if they are not otherwise orderable).  However, it
++    # disables this for CPython 3.6+ opting to instead display dicts' "natural"
++    # insertion order, which is preserved in those versions).
++    # However, this order is random in some instances.
++    # Also modifications of code may affect the order.
++    # So here we fore sorted dict printing.
++    IPython.lib.pretty.for_type(dict, _sorted_dict_pprinter_factory('{', '}'))
++
+     if controller is None:
+         import sage.repl.ipython_kernel.all_jupyter
+     else:
+@@ -222,15 +231,6 @@ def init_sage(controller=None):
+     from sage.repl.rich_output.backend_doctest import BackendDoctest
+     dm.switch_backend(BackendDoctest())
+ 
+-    # IPython's pretty printer sorts the repr of dicts by their keys by default
+-    # (or their keys' str() if they are not otherwise orderable).  However, it
+-    # disables this for CPython 3.6+ opting to instead display dicts' "natural"
+-    # insertion order, which is preserved in those versions).
+-    # However, this order is random in some instances.
+-    # Also modifications of code may affect the order.
+-    # So here we fore sorted dict printing.
+-    IPython.lib.pretty.for_type(dict, _sorted_dict_pprinter_factory('{', '}'))
+-
+     # Switch on extra debugging
+     from sage.structure.debug_options import debug
+     debug.refine_category_hash_check = True
diff --git a/pkgs/applications/science/math/sage/patches/sagenb-cmp-deprecation.patch b/pkgs/applications/science/math/sage/patches/sagenb-cmp-deprecation.patch
deleted file mode 100644
index 9f502a66951..00000000000
--- a/pkgs/applications/science/math/sage/patches/sagenb-cmp-deprecation.patch
+++ /dev/null
@@ -1,13 +0,0 @@
-diff --git a/sagenb/__init__.py b/sagenb/__init__.py
-index 4db0d2cb..2fc5f01e 100644
---- a/sagenb/__init__.py
-+++ b/sagenb/__init__.py
-@@ -1,3 +1,8 @@
- # -*- coding: utf-8 -*
-   # init
-+import warnings
- from . import storage
-+
-+# deprecation in attrs, needs to be fixed in twisted
-+warnings.filterwarnings('ignore', category=DeprecationWarning,
-+    message=r'The usage of `cmp` is deprecated and will be removed.*')
diff --git a/pkgs/applications/science/math/sage/patches/sagespawn-implicit-casting.patch b/pkgs/applications/science/math/sage/patches/sagespawn-implicit-casting.patch
new file mode 100644
index 00000000000..2ee5db3e29c
--- /dev/null
+++ b/pkgs/applications/science/math/sage/patches/sagespawn-implicit-casting.patch
@@ -0,0 +1,13 @@
+diff --git a/src/sage/interfaces/sagespawn.pyx b/src/sage/interfaces/sagespawn.pyx
+index 9041238f1d..469befbc66 100644
+--- a/src/sage/interfaces/sagespawn.pyx
++++ b/src/sage/interfaces/sagespawn.pyx
+@@ -228,7 +228,7 @@ class SagePtyProcess(PtyProcess):
+         Check that the process eventually dies after calling
+         ``terminate_async``::
+ 
+-            sage: s.ptyproc.terminate_async(interval=0.2)
++            sage: s.ptyproc.terminate_async(interval=float(0.2))
+             sage: while True:
+             ....:     try:
+             ....:         os.kill(s.pid, 0)
diff --git a/pkgs/applications/science/math/sage/patches/sphinx-docbuild-subprocesses.patch b/pkgs/applications/science/math/sage/patches/sphinx-docbuild-subprocesses.patch
index 56f09279622..661077cfa8c 100644
--- a/pkgs/applications/science/math/sage/patches/sphinx-docbuild-subprocesses.patch
+++ b/pkgs/applications/science/math/sage/patches/sphinx-docbuild-subprocesses.patch
@@ -36,7 +36,7 @@ index 73a078e619..059125c59f 100644
          # Run Sphinx with Sage's special logger
 -        sys.argv = ["sphinx-build"] + build_command.split()
 -        from .sphinxbuild import runsphinx
-+        args = "python -um sage_setup.docbuild.sphinxbuild -N".split() + build_command.split()
++        args = "python3 -um sage_setup.docbuild.sphinxbuild -N".split() + build_command.split()
          try:
 -            runsphinx()
 +            subprocess.check_call(args)
diff --git a/pkgs/applications/science/math/sage/patches/sympow-cache.patch b/pkgs/applications/science/math/sage/patches/sympow-cache.patch
index 20020d610f8..d71f3acbc70 100644
--- a/pkgs/applications/science/math/sage/patches/sympow-cache.patch
+++ b/pkgs/applications/science/math/sage/patches/sympow-cache.patch
@@ -1,5 +1,5 @@
 diff --git a/src/sage/lfunctions/sympow.py b/src/sage/lfunctions/sympow.py
-index 1640ac4f6a..03578be7b8 100644
+index 92cb01fd73..b123e6accc 100644
 --- a/src/sage/lfunctions/sympow.py
 +++ b/src/sage/lfunctions/sympow.py
 @@ -50,6 +50,7 @@ from __future__ import print_function, absolute_import
@@ -8,14 +8,14 @@ index 1640ac4f6a..03578be7b8 100644
  
 +from sage.env import DOT_SAGE
  from sage.structure.sage_object import SageObject
- from sage.misc.all import pager, verbose
- import sage.rings.all
-@@ -76,7 +77,7 @@ class Sympow(SageObject):
+ from sage.misc.all import pager
+ from sage.misc.verbose import verbose
+@@ -78,7 +79,7 @@ class Sympow(SageObject):
          """
          Used to call sympow with given args
          """
--        cmd = 'sympow %s'%args
+-        cmd = 'sympow %s' % args
 +        cmd = 'env SYMPOW_CACHEDIR="%s/sympow///" sympow %s' % (DOT_SAGE, args)
-         v = os.popen(cmd).read().strip()
+         with os.popen(cmd) as f:
+             v = f.read().strip()
          verbose(v, level=2)
-         return v
diff --git a/pkgs/applications/science/math/sage/pybrial.nix b/pkgs/applications/science/math/sage/pybrial.nix
deleted file mode 100644
index 5fc8a4aa6f4..00000000000
--- a/pkgs/applications/science/math/sage/pybrial.nix
+++ /dev/null
@@ -1,25 +0,0 @@
-{ stdenv
-, fetchFromGitHub
-, buildPythonPackage
-, brial
-}:
-# This has a cyclic dependency with sage. I don't include sage in the
-# buildInputs and let python figure it out at runtime. Because of this,
-# I don't include the package in the main nipxkgs tree. It wouldn't be useful
-# outside of sage anyways (as you could just directly depend on sage and use
-# it).
-buildPythonPackage rec {
-    pname = "pyBRiAl";
-    version = brial.version;
-
-    # included with BRiAl source
-    src = brial.src;
-
-    sourceRoot = "source/sage-brial";
-
-    meta = with stdenv.lib; {
-      description = "python implementation of BRiAl";
-      license = licenses.gpl2;
-      maintainers = teams.sage.members;
-    };
-}
diff --git a/pkgs/applications/science/math/sage/python-openid.nix b/pkgs/applications/science/math/sage/python-openid.nix
deleted file mode 100644
index 1e8a908ac79..00000000000
--- a/pkgs/applications/science/math/sage/python-openid.nix
+++ /dev/null
@@ -1,40 +0,0 @@
-{ stdenv
-, buildPythonPackage
-, fetchPypi
-, isPy3k
-, django
-, nose
-, twill
-, pycrypto
-}:
-
-buildPythonPackage rec {
-  pname = "python-openid";
-  version = "2.2.5";
-
-  disabled = isPy3k;
-
-  src = fetchPypi {
-    inherit pname version;
-    sha256 = "1vvhxlghjan01snfdc4k7ykd80vkyjgizwgg9bncnin8rqz1ricj";
-  };
-
-  propagatedBuildInputs = [
-    pycrypto
-  ];
-
-  # Cannot access the djopenid example module.
-  # I don't know how to fix that (adding the examples dir to PYTHONPATH doesn't work)
-  doCheck = false;
-  checkInputs = [ nose django twill ];
-  checkPhase = ''
-    nosetests
-  '';
-
-  meta = with stdenv.lib; {
-    description = "OpenID library for Python";
-    license = licenses.asl20;
-    maintainers = teams.sage.members;
-    homepage = "https://github.com/openid/python-openid/";
-  };
-}
diff --git a/pkgs/applications/science/math/sage/sage-env.nix b/pkgs/applications/science/math/sage/sage-env.nix
index ba7f6ccd18b..568a4a39f39 100644
--- a/pkgs/applications/science/math/sage/sage-env.nix
+++ b/pkgs/applications/science/math/sage/sage-env.nix
@@ -1,7 +1,6 @@
 { stdenv
 , lib
 , writeTextFile
-, python
 , sagelib
 , env-locations
 , gfortran
@@ -67,11 +66,6 @@ let
     "@sage-local@"
     "@sage-local@/build"
     pythonEnv
-    # empty python env to add python wrapper that clears PYTHONHOME (see
-    # wrapper.nix). This is necessary because sage will call the python3 binary
-    # (from python2 code). The python2 PYTHONHOME (again set in wrapper.nix)
-    # will then confuse python3, if it is not overwritten.
-    python3.buildEnv
     gfortran # for inline fortran
     stdenv.cc # for cython
     bash
@@ -129,8 +123,21 @@ writeTextFile rec {
       ]
     }'
     export SAGE_ROOT='${sagelib.src}'
-    export SAGE_LOCAL='@sage-local@'
+  '' +
+    # TODO: is using pythonEnv instead of @sage-local@ here a good
+    # idea? there is a test in src/sage/env.py that checks if the values
+    # SAGE_ROOT and SAGE_LOCAL set here match the ones set in env.py.
+    # we fix up env.py's SAGE_ROOT in sage-src.nix (which does not
+    # have access to sage-with-env), but env.py autodetects
+    # SAGE_LOCAL to be pythonEnv.
+    # setting SAGE_LOCAL to pythonEnv also avoids having to create
+    # python3, ipython, ipython3 and jupyter symlinks in
+    # sage-with-env.nix.
+  ''
+    export SAGE_LOCAL='${pythonEnv}'
+
     export SAGE_SHARE='${sagelib}/share'
+    export SAGE_ENV_CONFIG_SOURCED=1 # sage-env complains if sage-env-config is not sourced beforehand
     orig_path="$PATH"
     export PATH='${runtimepath}'
 
@@ -177,9 +184,9 @@ writeTextFile rec {
       ])
     }'
 
-    export SAGE_LIB='${sagelib}/${python.sitePackages}'
+    export SAGE_LIB='${sagelib}/${python3.sitePackages}'
 
-    export SAGE_EXTCODE='${sagelib.src}/src/ext'
+    export SAGE_EXTCODE='${sagelib.src}/src/sage/ext_data'
 
   # for find_library
     export DYLD_LIBRARY_PATH="${lib.makeLibraryPath [stdenv.cc.libc singular]}''${DYLD_LIBRARY_PATH:+:}$DYLD_LIBRARY_PATH"
diff --git a/pkgs/applications/science/math/sage/sage-src.nix b/pkgs/applications/science/math/sage/sage-src.nix
index 4791d12450a..8948621a025 100644
--- a/pkgs/applications/science/math/sage/sage-src.nix
+++ b/pkgs/applications/science/math/sage/sage-src.nix
@@ -10,44 +10,23 @@
 # all get the same sources with the same patches applied.
 
 stdenv.mkDerivation rec {
-  version = "8.9";
+  version = "9.2";
   pname = "sage-src";
 
   src = fetchFromGitHub {
     owner = "sagemath";
     repo = "sage";
     rev = version;
-    sha256 = "1bwga58x3s8z42w5h51c232f91ndsc1861dlb1glhax3pn0rhn3a";
+    sha256 = "103j8d5x6szl9fxaz0dvdi4y47q1af9h9y5hmjh2xayi62qmp5ql";
   };
 
   # Patches needed because of particularities of nix or the way this is packaged.
   # The goal is to upstream all of them and get rid of this list.
   nixPatches = [
-    # https://trac.sagemath.org/ticket/25358
-    (fetchpatch {
-      name = "safe-directory-test-without-patch.patch";
-      url = "https://git.sagemath.org/sage.git/patch?id2=8bdc326ba57d1bb9664f63cf165a9e9920cc1afc&id=dc673c17555efca611f68398d5013b66e9825463";
-      sha256 = "1hhannz7xzprijakn2w2d0rhd5zv2zikik9p51i87bas3nc658f7";
-    })
-    
-    # `is_unitary` test in `matrix_double_dense.pyx` fails with some BLAS implementations
-    # https://trac.sagemath.org/ticket/29297 should be included in 9.1
-    (fetchpatch {
-      name = "is_unitary-special-case.patch";
-      url = "https://git.sagemath.org/sage.git/patch?id=cc3eb9ffa991e328b09028d32aab7e7cc2ddbb6a";
-      sha256 = "0jq4w8hnp5c9q99011ldr4n3knvm1rx2g85z0hidv3i9x868p0ay";
-    })
-
-    # Unfortunately inclusion in upstream sage was rejected. Instead the bug was
-    # fixed in python, but of course not backported to 2.7. So we'll probably
-    # have to keep this around until 2.7 is deprecated.
-    # https://trac.sagemath.org/ticket/25316
-    # https://github.com/python/cpython/pull/7476
-    ./patches/python-5755-hotpatch.patch
-
     # Make sure py2/py3 tests are only run when their expected context (all "sage"
     # tests) are also run. That is necessary to test dochtml individually. See
     # https://trac.sagemath.org/ticket/26110 for an upstream discussion.
+    # TODO: Determine if it is still necessary.
     ./patches/Only-test-py2-py3-optional-tests-when-all-of-sage-is.patch
 
     # Fixes a potential race condition which can lead to transient doctest failures.
@@ -61,10 +40,17 @@ stdenv.mkDerivation rec {
     # https://groups.google.com/forum/#!topic/sage-packaging/YGOm8tkADrE
     ./patches/sphinx-docbuild-subprocesses.patch
 
-    # Fix doctest failures with docutils 0.15:
-    # https://nix-cache.s3.amazonaws.com/log/dzmzrb2zvardsmpy7idg7djkizmkzdhs-sage-tests-8.9.drv
-    # https://trac.sagemath.org/ticket/28856#comment:19
-    ./patches/docutils-0.15.patch
+    # Sage's workaround to pretty print dicts (in
+    # src/sage/doctest/forker.py:init_sage) runs too late (after
+    # controller.load_environment(), which imports sage.all.*) to to
+    # affect sage.sandpiles.Sandpile{Config,Divisor}'s pretty printer.
+    # Due to the sandpiles module being lazily loaded, this only
+    # affects the first run (subsequent runs read from an import cache
+    # at ~/.sage/cache and are not affected), which is probably why
+    # other distributions don't hit this bug. This breaks two sandpile
+    # tests, so do the workaround a little bit earlier.
+    # https://trac.sagemath.org/ticket/31053
+    ./patches/register-pretty-printer-earlier.patch
   ];
 
   # Since sage unfortunately does not release bugfix releases, packagers must
@@ -74,6 +60,17 @@ stdenv.mkDerivation rec {
     # To help debug the transient error in
     # https://trac.sagemath.org/ticket/23087 when it next occurs.
     ./patches/configurationpy-error-verbose.patch
+
+    # fix intermittent errors in Sage 9.2's psage.py (this patch is
+    # already included in Sage 9.3): https://trac.sagemath.org/ticket/30730
+    (fetchpatch {
+      name = "fix-psage-is-locked.patch";
+      url = "https://git.sagemath.org/sage.git/patch/?id=75df605f216ddc7b6ca719be942d666b241520e9";
+      sha256 = "0g9pl1wbb3sgs26d3bvv70cpa77sfskylv4kd255y1794f1fgk4q";
+    })
+
+    # fix intermittent errors in sagespawn.pyx: https://trac.sagemath.org/ticket/31052
+    ./patches/sagespawn-implicit-casting.patch
   ];
 
   # Patches needed because of package updates. We could just pin the versions of
@@ -96,55 +93,16 @@ stdenv.mkDerivation rec {
       } // builtins.removeAttrs args [ "rev" "base" ])
     );
   in [
-    # New glpk version has new warnings, filter those out until upstream sage has found a solution
-    # Should be fixed with glpk > 4.65.
-    # https://trac.sagemath.org/ticket/24824
-    ./patches/pari-stackwarn.patch # not actually necessary since the pari upgrade, but necessary for the glpk patch to apply
-    (fetchpatch {
-      url = "https://salsa.debian.org/science-team/sagemath/raw/58bbba93a807ca2933ca317501d093a1bb4b84db/debian/patches/dt-version-glpk-4.65-ignore-warnings.patch";
-      sha256 = "0b9293v73wb4x13wv5zwyjgclc01zn16msccfzzi6znswklgvddp";
-      stripLen = 1;
-    })
-
     # After updating smypow to (https://trac.sagemath.org/ticket/3360) we can
     # now set the cache dir to be withing the .sage directory. This is not
     # strictly necessary, but keeps us from littering in the user's HOME.
     ./patches/sympow-cache.patch
 
-    # https://trac.sagemath.org/ticket/28472
-    (fetchpatch {
-      name = "eclib-20190909.patch";
-      url = "https://git.sagemath.org/sage.git/patch?id=d27dc479a5772d59e4bc85d805b6ffd595284f1d";
-      sha256 = "1nf1s9y7n30lhlbdnam7sghgaq9nasmv96415gl5jlcf7a3hlxk3";
-    })
-
     # ignore a deprecation warning for usage of `cmp` in the attrs library in the doctests
     ./patches/ignore-cmp-deprecation.patch
 
-    # Werkzeug has deprecated ImmutableDict, but it is still used in legacy
-    # sagenb. That's no big issue since sagenb will be removed soon anyways.
-    ./patches/ignore-werkzeug-immutable-dict-deprecation.patch
-
-    # threejs r109 (#28560)
-    (fetchpatch {
-      name = "threejs-r109.patch";
-      url = "https://git.sagemath.org/sage.git/patch?id=fcc11d6effa39f375bc5f4ea5831fb7a2f2767da";
-      sha256 = "0hnmc8ld3bblks0hcjvjjaydkgwdr1cs3dbl2ys4gfq964pjgqwc";
-    })
-
-    # https://trac.sagemath.org/ticket/28911
-    (fetchpatch {
-      name = "sympy-1.5.patch";
-      url = "https://git.sagemath.org/sage.git/patch/?h=c6d0308db15efd611211d26cfcbefbd180fc0831";
-      sha256 = "0nwai2jr22h49km4hx3kwafs3mzsc5kwsv7mqwjf6ibwfx2bbgyq";
-    })
-
-    # https://trac.sagemath.org/ticket/29313 (patch from ArchLinux)
-    (fetchpatch {
-      name = "pari-2.11.3.patch";
-      url = "https://aur.archlinux.org/cgit/aur.git/plain/sagemath-pari-2.11.3.patch?h=sagemath-git&id=02e1d58bd1cd70935d69a4990469d18be6bd2c43";
-      sha256 = "0z07444zvijyw96d11q7j81pvg7ysd6ycf1bbbjr6za9y74hv7d2";
-    })
+    # adapt sage's Image class to pillow 8.0.1 (https://trac.sagemath.org/ticket/30971)
+    ./patches/pillow-update.patch
   ];
 
   patches = nixPatches ++ bugfixPatches ++ packageUpgradePatches;
@@ -152,16 +110,16 @@ stdenv.mkDerivation rec {
   postPatch = ''
     # make sure shebangs etc are fixed, but sage-python23 still works
     find . -type f -exec sed \
-      -e 's/sage-python23/python/g' \
+      -e 's/sage-python23/python3/g' \
       -i {} \;
 
     echo '#!${runtimeShell}
-    python "$@"' > build/bin/sage-python23
+    python3 "$@"' > build/bin/sage-python23
 
     # Make sure sage can at least be imported without setting any environment
     # variables. It won't be close to feature complete though.
     sed -i \
-      "s|var('SAGE_LOCAL',.*|var('SAGE_LOCAL', '$out/src')|" \
+      "s|var('SAGE_ROOT'.*|var('SAGE_ROOT', '$out')|" \
       src/sage/env.py
 
     # Do not use sage-env-config (generated by ./configure).
@@ -169,7 +127,39 @@ stdenv.mkDerivation rec {
     echo '# do nothing' >  src/bin/sage-env-config
   '';
 
-  configurePhase = "# do nothing";
+  # Test src/doc/en/reference/spkg/conf.py will fail if
+  # src/doc/en/reference/spkg/index.rst is not generated.  It is
+  # generated by src/doc/bootstrap, so I've copied the relevant part
+  # here. An alternative would be to create an empty
+  # src/doc/en/reference/spkg/index.rst file.
+  configurePhase = ''
+    OUTPUT_DIR="src/doc/en/reference/spkg"
+    mkdir -p "$OUTPUT_DIR"
+    OUTPUT_INDEX="$OUTPUT_DIR"/index.rst
+    cat > "$OUTPUT_INDEX" <<EOF
+
+    External Packages
+    =================
+
+    .. toctree::
+       :maxdepth: 1
+
+    EOF
+    for PKG_SCRIPTS in build/pkgs/*; do
+        if [ -d "$PKG_SCRIPTS" ]; then
+            PKG_BASE=$(basename "$PKG_SCRIPTS")
+            if [ -f "$PKG_SCRIPTS"/SPKG.rst ]; then
+                # Instead of just copying, we may want to call
+                # a version of sage-spkg-info to format extra information.
+                cp "$PKG_SCRIPTS"/SPKG.rst "$OUTPUT_DIR"/$PKG_BASE.rst
+                echo >> "$OUTPUT_INDEX" "   $PKG_BASE"
+            fi
+        fi
+    done
+    cat >> "$OUTPUT_INDEX" <<EOF
+    .. include:: ../footer.txt
+    EOF
+  '';
 
   buildPhase = "# do nothing";
 
diff --git a/pkgs/applications/science/math/sage/sage-with-env.nix b/pkgs/applications/science/math/sage/sage-with-env.nix
index 87c1e07f530..f204d97961b 100644
--- a/pkgs/applications/science/math/sage/sage-with-env.nix
+++ b/pkgs/applications/science/math/sage/sage-with-env.nix
@@ -13,7 +13,7 @@
 , pari
 , gmp
 , gfan
-, python2
+, python3
 , flintqs
 , eclib
 , ntl
@@ -50,11 +50,11 @@ let
   ];
 
   # remove python prefix, replace "-" in the name by "_", apply patch_names
-  # python2.7-some-pkg-1.0 -> some_pkg-1.0
+  # python3.8-some-pkg-1.0 -> some_pkg-1.0
   pkg_to_spkg_name = pkg: patch_names: let
     parts = lib.splitString "-" pkg.name;
-    # remove python2.7-
-    stripped_parts = if (builtins.head parts) == python2.libPrefix then builtins.tail parts else parts;
+    # remove python3.8-
+    stripped_parts = if (builtins.head parts) == python3.libPrefix then builtins.tail parts else parts;
     version = lib.last stripped_parts;
     orig_pkgname = lib.init stripped_parts;
     pkgname = patch_names (lib.concatStringsSep "_" orig_pkgname);
diff --git a/pkgs/applications/science/math/sage/sage.nix b/pkgs/applications/science/math/sage/sage.nix
index a21bffea14c..e2acef7b8eb 100644
--- a/pkgs/applications/science/math/sage/sage.nix
+++ b/pkgs/applications/science/math/sage/sage.nix
@@ -61,7 +61,6 @@ stdenv.mkDerivation rec {
   };
 
   meta = with stdenv.lib; {
-    broken = true;
     description = "Open Source Mathematics Software, free alternative to Magma, Maple, Mathematica, and Matlab";
     license = licenses.gpl2;
     maintainers = teams.sage.members;
diff --git a/pkgs/applications/science/math/sage/sagedoc.nix b/pkgs/applications/science/math/sage/sagedoc.nix
index bf618fe64f4..a10672f3a09 100644
--- a/pkgs/applications/science/math/sage/sagedoc.nix
+++ b/pkgs/applications/science/math/sage/sagedoc.nix
@@ -1,6 +1,6 @@
 { stdenv
 , sage-with-env
-, python
+, python3
 , maxima-ecl
 , tachyon
 , jmol
@@ -17,16 +17,15 @@ stdenv.mkDerivation rec {
   # modules are imported and because matplotlib is used to produce plots.
   buildInputs = [
     sage-with-env.env.lib
-    python
+    python3
     maxima-ecl
     tachyon
     jmol
     cddlib
-  ] ++ (with python.pkgs; [
+  ] ++ (with python3.pkgs; [
     psutil
     future
     sphinx
-    sagenb
     scipy
     sympy
     matplotlib
@@ -35,8 +34,6 @@ stdenv.mkDerivation rec {
     ipykernel
     ipywidgets
     jupyter_client
-    typing
-    pybrial
   ]);
 
   unpackPhase = ''
@@ -47,13 +44,26 @@ stdenv.mkDerivation rec {
     chmod -R 755 "$SAGE_DOC_SRC_OVERRIDE"
   '';
 
+  postPatch = ''
+    # src/doc/bootstrap generates installation instructions for
+    # arch, debian, fedora, cygwin and homebrew. as a hack, disable
+    # including the generated files.
+    sed -i "/literalinclude/d" $SAGE_DOC_SRC_OVERRIDE/en/installation/source.rst
+  '';
+
   buildPhase = ''
     export SAGE_NUM_THREADS="$NIX_BUILD_CORES"
     export HOME="$TMPDIR/sage_home"
     mkdir -p "$HOME"
 
     # needed to link them in the sage docs using intersphinx
-    export PPLPY_DOCS=${python.pkgs.pplpy.doc}/share/doc/pplpy
+    export PPLPY_DOCS=${python3.pkgs.pplpy.doc}/share/doc/pplpy
+
+    # adapted from src/doc/bootstrap
+    OUTPUT_DIR="$SAGE_DOC_SRC_OVERRIDE/en/reference/repl"
+    mkdir -p "$OUTPUT_DIR"
+    OUTPUT="$OUTPUT_DIR/options.txt"
+    ${sage-with-env}/bin/sage -advanced > "$OUTPUT"
 
     ${sage-with-env}/bin/sage -python -m sage_setup.docbuild \
       --mathjax \
diff --git a/pkgs/applications/science/math/sage/sagelib.nix b/pkgs/applications/science/math/sage/sagelib.nix
index 830d806a8bc..1c2235bf71b 100644
--- a/pkgs/applications/science/math/sage/sagelib.nix
+++ b/pkgs/applications/science/math/sage/sagelib.nix
@@ -15,6 +15,7 @@
 , ecm
 , flint
 , gd
+, giac
 , givaro
 , glpk
 , gsl
@@ -51,6 +52,7 @@
 , libbraiding
 , gmpy2
 , pplpy
+, sqlite
 }:
 
 assert (!blas.isILP64) && (!lapack.isILP64);
@@ -94,6 +96,7 @@ buildPythonPackage rec {
     ecm
     fflas-ffpack
     flint
+    giac
     givaro
     glpk
     gsl
@@ -124,6 +127,7 @@ buildPythonPackage rec {
     libbraiding
     gmpy2
     pplpy
+    sqlite
   ];
 
   buildPhase = ''
diff --git a/pkgs/applications/science/math/sage/sagenb.nix b/pkgs/applications/science/math/sage/sagenb.nix
deleted file mode 100644
index ad5c53b6c11..00000000000
--- a/pkgs/applications/science/math/sage/sagenb.nix
+++ /dev/null
@@ -1,57 +0,0 @@
-{ stdenv
-, python
-, buildPythonPackage
-, fetchFromGitHub
-, mathjax
-, twisted
-, flask
-, flask-oldsessions
-, flask-openid
-, flask-autoindex
-, flask-babel
-}:
-
-# Has a cyclic dependency with sage (not expressed here) and is not useful outside of sage.
-# Deprecated, hopefully soon to be removed. See
-# https://trac.sagemath.org/ticket/25837
-
-buildPythonPackage rec {
-  pname = "sagenb";
-  version = "1.1.2";
-
-  src = fetchFromGitHub {
-    owner = "sagemath";
-    repo = "sagenb";
-    rev = version;
-    sha256 = "0bxvhr03qh2nsjdfc4pyfiqrn9jhp3vf7irsc9gqx0185jlblbxs";
-  };
-
-  patches = [
-    # cmp deprecation in attrs needs to be handled in twisted
-    ./patches/sagenb-cmp-deprecation.patch
-  ];
-
-  propagatedBuildInputs = [
-    twisted
-    flask
-    flask-oldsessions
-    flask-openid
-    flask-autoindex
-    flask-babel
-  ];
-
-  # tests depend on sage
-  doCheck = false;
-
-  meta = with stdenv.lib; {
-    description = "Sage Notebook";
-    license = licenses.gpl3Plus;
-    maintainers = teams.sage.members;
-  };
-
-  # let sagenb use mathjax
-  postInstall = ''
-    mkdir -p "$out/${python.sitePackages}/sagenb/data"
-    ln -s ${mathjax}/lib/node_modules/mathjax "$out/${python.sitePackages}/sagenb/data/mathjax"
-  '';
-}
diff --git a/pkgs/applications/science/misc/simgrid/default.nix b/pkgs/applications/science/misc/simgrid/default.nix
index 0ba1cd0d2fa..11d73095834 100644
--- a/pkgs/applications/science/misc/simgrid/default.nix
+++ b/pkgs/applications/science/misc/simgrid/default.nix
@@ -18,14 +18,14 @@ in
 
 stdenv.mkDerivation rec {
   pname = "simgrid";
-  version = "3.25";
+  version = "3.26";
 
   src = fetchFromGitLab {
     domain = "framagit.org";
     owner = pname;
     repo = pname;
     rev = "v${version}";
-    sha256 = "019fgryfwpcrkv1f3271v7qxk0mfw2w990vgnk1cqhmr9i1f17gs";
+    sha256 = "0kwiggdjqjhjvmwb1m7hb9clvm3xz948fy5ia67dif2pakwad754";
   };
 
   nativeBuildInputs = [ cmake perl python3 boost valgrind ]