about summary refs log tree commit diff
path: root/nixpkgs/pkgs/applications/science/math
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2021-01-15 10:30:44 +0000
committerAlyssa Ross <hi@alyssa.is>2021-01-15 10:30:44 +0000
commite0794be8a0d11e90461e5a9c85012a36b93ec976 (patch)
treeefd9cbc55ea3322867bf601c4d536758a3dd5fcc /nixpkgs/pkgs/applications/science/math
parent3538874082ded7647b1ccec0343c7c1e882cfef3 (diff)
parent1a57d96edd156958b12782e8c8b6a374142a7248 (diff)
downloadnixlib-e0794be8a0d11e90461e5a9c85012a36b93ec976.tar
nixlib-e0794be8a0d11e90461e5a9c85012a36b93ec976.tar.gz
nixlib-e0794be8a0d11e90461e5a9c85012a36b93ec976.tar.bz2
nixlib-e0794be8a0d11e90461e5a9c85012a36b93ec976.tar.lz
nixlib-e0794be8a0d11e90461e5a9c85012a36b93ec976.tar.xz
nixlib-e0794be8a0d11e90461e5a9c85012a36b93ec976.tar.zst
nixlib-e0794be8a0d11e90461e5a9c85012a36b93ec976.zip
Merge commit '1a57d96edd156958b12782e8c8b6a374142a7248'
Diffstat (limited to 'nixpkgs/pkgs/applications/science/math')
-rw-r--r--nixpkgs/pkgs/applications/science/math/R/default.nix6
-rw-r--r--nixpkgs/pkgs/applications/science/math/bcal/default.nix9
-rw-r--r--nixpkgs/pkgs/applications/science/math/bliss/default.nix4
-rw-r--r--nixpkgs/pkgs/applications/science/math/calc/default.nix4
-rw-r--r--nixpkgs/pkgs/applications/science/math/geogebra/default.nix94
-rw-r--r--nixpkgs/pkgs/applications/science/math/geogebra/geogebra6.nix92
-rw-r--r--nixpkgs/pkgs/applications/science/math/gfan/default.nix8
-rw-r--r--nixpkgs/pkgs/applications/science/math/gfan/gfan-0.6.2-cddlib-prefix.patch55
-rw-r--r--nixpkgs/pkgs/applications/science/math/giac/default.nix4
-rw-r--r--nixpkgs/pkgs/applications/science/math/ginac/default.nix4
-rw-r--r--nixpkgs/pkgs/applications/science/math/gmsh/default.nix4
-rw-r--r--nixpkgs/pkgs/applications/science/math/gretl/default.nix43
-rw-r--r--nixpkgs/pkgs/applications/science/math/lrcalc/default.nix2
-rw-r--r--nixpkgs/pkgs/applications/science/math/mathematica/default.nix12
-rw-r--r--nixpkgs/pkgs/applications/science/math/mathematica/l10ns.nix16
-rw-r--r--nixpkgs/pkgs/applications/science/math/maxima/5.41.nix102
-rw-r--r--nixpkgs/pkgs/applications/science/math/maxima/default.nix35
-rw-r--r--nixpkgs/pkgs/applications/science/math/maxima/known-ecl-failures.patch21
-rw-r--r--nixpkgs/pkgs/applications/science/math/nauty/default.nix4
-rw-r--r--nixpkgs/pkgs/applications/science/math/palp/default.nix2
-rw-r--r--nixpkgs/pkgs/applications/science/math/pari/default.nix39
-rw-r--r--nixpkgs/pkgs/applications/science/math/pari/gp2c.nix15
-rw-r--r--nixpkgs/pkgs/applications/science/math/pspp/default.nix8
-rw-r--r--nixpkgs/pkgs/applications/science/math/pynac/default.nix18
-rw-r--r--nixpkgs/pkgs/applications/science/math/qalculate-gtk/default.nix16
-rw-r--r--nixpkgs/pkgs/applications/science/math/rofi-calc/default.nix6
-rw-r--r--nixpkgs/pkgs/applications/science/math/sage/default.nix65
-rw-r--r--nixpkgs/pkgs/applications/science/math/sage/env-locations.nix2
-rw-r--r--nixpkgs/pkgs/applications/science/math/sage/flask-oldsessions.nix36
-rw-r--r--nixpkgs/pkgs/applications/science/math/sage/flask-openid.nix28
-rw-r--r--nixpkgs/pkgs/applications/science/math/sage/patches/Only-test-py2-py3-optional-tests-when-all-of-sage-is.patch21
-rw-r--r--nixpkgs/pkgs/applications/science/math/sage/patches/do-not-test-find-library.patch33
-rw-r--r--nixpkgs/pkgs/applications/science/math/sage/patches/docutils-0.15.patch24
-rw-r--r--nixpkgs/pkgs/applications/science/math/sage/patches/ignore-cmp-deprecation.patch30
-rw-r--r--nixpkgs/pkgs/applications/science/math/sage/patches/ignore-werkzeug-immutable-dict-deprecation.patch12
-rw-r--r--nixpkgs/pkgs/applications/science/math/sage/patches/pari-stackwarn.patch20
-rw-r--r--nixpkgs/pkgs/applications/science/math/sage/patches/pillow-update.patch39
-rw-r--r--nixpkgs/pkgs/applications/science/math/sage/patches/python-5755-hotpatch.patch28
-rw-r--r--nixpkgs/pkgs/applications/science/math/sage/patches/register-pretty-printer-earlier.patch36
-rw-r--r--nixpkgs/pkgs/applications/science/math/sage/patches/sagenb-cmp-deprecation.patch13
-rw-r--r--nixpkgs/pkgs/applications/science/math/sage/patches/sagespawn-implicit-casting.patch13
-rw-r--r--nixpkgs/pkgs/applications/science/math/sage/patches/sphinx-docbuild-subprocesses.patch2
-rw-r--r--nixpkgs/pkgs/applications/science/math/sage/patches/sympow-cache.patch14
-rw-r--r--nixpkgs/pkgs/applications/science/math/sage/pybrial.nix25
-rw-r--r--nixpkgs/pkgs/applications/science/math/sage/python-openid.nix40
-rw-r--r--nixpkgs/pkgs/applications/science/math/sage/sage-env.nix25
-rw-r--r--nixpkgs/pkgs/applications/science/math/sage/sage-src.nix136
-rw-r--r--nixpkgs/pkgs/applications/science/math/sage/sage-with-env.nix8
-rw-r--r--nixpkgs/pkgs/applications/science/math/sage/sage.nix2
-rw-r--r--nixpkgs/pkgs/applications/science/math/sage/sagedoc.nix24
-rw-r--r--nixpkgs/pkgs/applications/science/math/sage/sagelib.nix4
-rw-r--r--nixpkgs/pkgs/applications/science/math/sage/sagenb.nix57
-rw-r--r--nixpkgs/pkgs/applications/science/math/singular/default.nix2
-rw-r--r--nixpkgs/pkgs/applications/science/math/symmetrica/default.nix2
-rw-r--r--nixpkgs/pkgs/applications/science/math/zegrapher/default.nix36
55 files changed, 632 insertions, 768 deletions
diff --git a/nixpkgs/pkgs/applications/science/math/R/default.nix b/nixpkgs/pkgs/applications/science/math/R/default.nix
index 717b240c1cce..e4fbe8a7f2de 100644
--- a/nixpkgs/pkgs/applications/science/math/R/default.nix
+++ b/nixpkgs/pkgs/applications/science/math/R/default.nix
@@ -12,11 +12,11 @@
 assert (!blas.isILP64) && (!lapack.isILP64);
 
 stdenv.mkDerivation rec {
-  name = "R-4.0.2";
+  name = "R-4.0.3";
 
   src = fetchurl {
     url = "https://cran.r-project.org/src/base/R-4/${name}.tar.gz";
-    sha256 = "0xdy3dy2bzdiba8z94hjykyra8si8a5q15s0bri7c26scjrymg6k";
+    sha256 = "03cypg2qf7v9mq9mr9alz9w5y9m5kdgwbc97bp26pyymg253m609";
   };
 
   dontUseImakeConfigure = true;
@@ -113,6 +113,6 @@ stdenv.mkDerivation rec {
     platforms = platforms.all;
     hydraPlatforms = platforms.linux;
 
-    maintainers = with maintainers; [ peti timokau ];
+    maintainers = with maintainers; [ peti ] ++ teams.sage.members;
   };
 }
diff --git a/nixpkgs/pkgs/applications/science/math/bcal/default.nix b/nixpkgs/pkgs/applications/science/math/bcal/default.nix
index 18b6e051b3f2..5df2d20549c2 100644
--- a/nixpkgs/pkgs/applications/science/math/bcal/default.nix
+++ b/nixpkgs/pkgs/applications/science/math/bcal/default.nix
@@ -1,16 +1,16 @@
-{ stdenv, fetchFromGitHub, python3Packages, readline }:
+{ stdenv, fetchFromGitHub, python3Packages, readline, bc }:
 
 with stdenv.lib;
 
 stdenv.mkDerivation rec {
   pname = "bcal";
-  version = "1.9";
+  version = "2.2";
 
   src = fetchFromGitHub {
     owner = "jarun";
     repo = "bcal";
     rev = "v${version}";
-    sha256 = "0h6qi5rvzl6c6fsfdpdb3l4jcgip03l18i0b1x08z1y89i56y8mm";
+    sha256 = "4vR5rcbNkoEdSRNoMH9qMHP3iWFxejkVfXNiYfwbo/A=";
   };
 
   nativeBuildInputs = [ python3Packages.pytest ];
@@ -18,6 +18,7 @@ stdenv.mkDerivation rec {
   buildInputs = [ readline ];
 
   doCheck = true;
+  checkInputs = [ bc ];
   checkPhase = ''
     python3 -m pytest test.py
   '';
@@ -27,7 +28,7 @@ stdenv.mkDerivation rec {
   meta = {
     description = "Storage conversion and expression calculator";
     homepage = "https://github.com/jarun/bcal";
-    license = licenses.gpl3;
+    license = licenses.gpl3Only;
     platforms = [ "aarch64-linux" "x86_64-darwin" "x86_64-linux" ];
     maintainers = with maintainers; [ jfrankenau ];
   };
diff --git a/nixpkgs/pkgs/applications/science/math/bliss/default.nix b/nixpkgs/pkgs/applications/science/math/bliss/default.nix
index 361b08846626..9ab90134aad4 100644
--- a/nixpkgs/pkgs/applications/science/math/bliss/default.nix
+++ b/nixpkgs/pkgs/applications/science/math/bliss/default.nix
@@ -22,14 +22,14 @@ stdenv.mkDerivation rec {
 
   installPhase = ''
     mkdir -p $out/bin $out/share/doc/bliss $out/lib $out/include/bliss
-    mv bliss $out/bin 
+    mv bliss $out/bin
     mv html/* COPYING* $out/share/doc/bliss
     mv *.a $out/lib
     mv *.h *.hh $out/include/bliss
   '';
 
   meta = with stdenv.lib; {
-    description = "bliss is an open source tool for computing automorphism groups and canonical forms of graphs. It has both a command line user interface as well as C++ and C programming language APIs.";
+    description = "An open source tool for computing automorphism groups and canonical forms of graphs. It has both a command line user interface as well as C++ and C programming language APIs";
     homepage = "http://www.tcs.hut.fi/Software/bliss/";
     license = licenses.lgpl3;
     platforms = [ "i686-linux" "x86_64-linux" ];
diff --git a/nixpkgs/pkgs/applications/science/math/calc/default.nix b/nixpkgs/pkgs/applications/science/math/calc/default.nix
index 8e50f48b286b..e770cff2da9c 100644
--- a/nixpkgs/pkgs/applications/science/math/calc/default.nix
+++ b/nixpkgs/pkgs/applications/science/math/calc/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, lib, fetchurl, utillinux, makeWrapper
+{ stdenv, lib, fetchurl, util-linux, makeWrapper
 , enableReadline ? true, readline, ncurses }:
 
 stdenv.mkDerivation rec {
@@ -19,7 +19,7 @@ stdenv.mkDerivation rec {
       --replace '-install_name ''${LIBDIR}/libcustcalc''${LIB_EXT_VERSION}' '-install_name ''${T}''${LIBDIR}/libcustcalc''${LIB_EXT_VERSION}'
   '';
 
-  buildInputs = [ utillinux makeWrapper ]
+  buildInputs = [ util-linux makeWrapper ]
              ++ lib.optionals enableReadline [ readline ncurses ];
 
   makeFlags = [
diff --git a/nixpkgs/pkgs/applications/science/math/geogebra/default.nix b/nixpkgs/pkgs/applications/science/math/geogebra/default.nix
index 5cebef83a4a9..a0548ffb232b 100644
--- a/nixpkgs/pkgs/applications/science/math/geogebra/default.nix
+++ b/nixpkgs/pkgs/applications/science/math/geogebra/default.nix
@@ -1,18 +1,7 @@
-{ stdenv, fetchurl, jre, makeDesktopItem, makeWrapper, language ? "en_US" }:
-
-stdenv.mkDerivation rec {
+{ stdenv, fetchurl, jre, makeDesktopItem, makeWrapper, unzip, language ? "en_US" }:
+let
   pname = "geogebra";
-  version = "5-0-593-0";
-
-  preferLocalBuild = true;
-
-  src = fetchurl {
-    urls = [
-      "https://download.geogebra.org/installers/5.0/GeoGebra-Linux-Portable-${version}.tar.bz2"
-      "http://web.archive.org/https://download.geogebra.org/installers/5.0/GeoGebra-Linux-Portable-${version}.tar.bz2"
-    ];
-    sha256 = "d84c27a3299e6df08881733d22215a18decedcba4c2d97a9e5424c39cd57db35";
-  };
+  version = "5-0-609-0";
 
   srcIcon = fetchurl {
     url = "http://static.geogebra.org/images/geogebra-logo.svg";
@@ -30,23 +19,6 @@ stdenv.mkDerivation rec {
     mimeType = "application/vnd.geogebra.file;application/vnd.geogebra.tool;";
   };
 
-  buildInputs = [ makeWrapper ];
-
-  installPhase = ''
-    install -D geogebra/* -t "$out/libexec/geogebra/"
-
-    makeWrapper "$out/libexec/geogebra/geogebra" "$out/bin/geogebra" \
-      --set JAVACMD "${jre}/bin/java" \
-      --set GG_PATH "$out/libexec/geogebra" \
-      --add-flags "--language=${language}"
-
-    install -Dm644 "${desktopItem}/share/applications/"* \
-      -t $out/share/applications/
-
-    install -Dm644 "${srcIcon}" \
-      "$out/share/icons/hicolor/scalable/apps/geogebra.svg"
-  '';
-
   meta = with stdenv.lib; {
     description = "Dynamic mathematics software with graphics, algebra and spreadsheets";
     longDescription = ''
@@ -55,9 +27,63 @@ stdenv.mkDerivation rec {
       calculus in one easy-to-use package.
     '';
     homepage = "https://www.geogebra.org/";
-    maintainers = with maintainers; [ ma27 ];
+    maintainers = with maintainers; [ ];
     license = with licenses; [ gpl3 cc-by-nc-sa-30 geogebra ];
-    platforms = platforms.all;
+    platforms = with platforms; linux ++ darwin;
     hydraPlatforms = [];
   };
-}
+
+  linuxPkg = stdenv.mkDerivation {
+    inherit pname version meta srcIcon desktopItem;
+
+    preferLocalBuild = true;
+
+    src = fetchurl {
+      urls = [
+        "https://download.geogebra.org/installers/5.0/GeoGebra-Linux-Portable-${version}.tar.bz2"
+        "http://web.archive.org/web/20201022200454/https://download.geogebra.org/installers/5.0/GeoGebra-Linux-Portable-${version}.tar.bz2"
+      ];
+      sha256 = "0xbhg8hm3dqm3qkraj48pqwslrnjyxpq9mcgylr2m8i1gmqw7xwf";
+    };
+
+    nativeBuildInputs = [ makeWrapper ];
+
+    installPhase = ''
+      install -D geogebra/* -t "$out/libexec/geogebra/"
+
+      makeWrapper "$out/libexec/geogebra/geogebra" "$out/bin/geogebra" \
+        --set JAVACMD "${jre}/bin/java" \
+        --set GG_PATH "$out/libexec/geogebra" \
+        --add-flags "--language=${language}"
+
+      install -Dm644 "${desktopItem}/share/applications/"* \
+        -t $out/share/applications/
+
+      install -Dm644 "${srcIcon}" \
+        "$out/share/icons/hicolor/scalable/apps/geogebra.svg"
+    '';
+  };
+
+  darwinPkg = stdenv.mkDerivation {
+    inherit pname version meta;
+
+    preferLocalBuild = true;
+
+    src = fetchurl {
+      url = "https://download.geogebra.org/installers/5.0/GeoGebra-MacOS-Installer-withJava-${version}.zip";
+      sha256 = "16fgqwxz31cfmia0pyzpk05aqzrqr11sjbw37q9zb3xfh3p1r4gz";
+    };
+
+    dontUnpack = true;
+
+    nativeBuildInputs = [ unzip ];
+
+    installPhase = ''
+      install -dm755 $out/Applications
+      unzip $src -d $out/Applications
+    '';
+  };
+in
+if stdenv.isDarwin
+then darwinPkg
+else linuxPkg
diff --git a/nixpkgs/pkgs/applications/science/math/geogebra/geogebra6.nix b/nixpkgs/pkgs/applications/science/math/geogebra/geogebra6.nix
index 65caff82ead1..7bd582648937 100644
--- a/nixpkgs/pkgs/applications/science/math/geogebra/geogebra6.nix
+++ b/nixpkgs/pkgs/applications/science/math/geogebra/geogebra6.nix
@@ -1,46 +1,70 @@
 { stdenv, unzip, fetchurl, electron_6, makeWrapper, geogebra }:
-stdenv.mkDerivation rec{
+let
+  pname = "geogebra";
+  version = "6-0-609-0";
 
-  name = "geogebra-${version}";
-  version = "6-0-600-0";
+  srcIcon = geogebra.srcIcon;
+  desktopItem = geogebra.desktopItem;
 
-  src = fetchurl {
-    urls = [
-        "https://download.geogebra.org/installers/6.0/GeoGebra-Linux64-Portable-${version}.zip"
-        "https://web.archive.org/web/20200904093945/https://download.geogebra.org/installers/6.0/GeoGebra-Linux64-Portable-${version}.zip"
-      ];
-    sha256 = "1l49rvfkil2cz6r7sa2mi0p6hvb6p66jv3x6xj8hjqls4l3sfhkm";
+  meta = with stdenv.lib; geogebra.meta // {
+    license = licenses.geogebra;
+    maintainers = with maintainers; [ voidless ];
+    platforms = with platforms; linux ++ darwin;
   };
 
-  dontConfigure = true;
-  dontBuild = true;
+  linuxPkg = stdenv.mkDerivation {
+    inherit pname version meta;
 
-  nativeBuildInputs = [
-    unzip
-    makeWrapper
-  ];
+    src = fetchurl {
+      urls = [
+          "https://download.geogebra.org/installers/6.0/GeoGebra-Linux64-Portable-${version}.zip"
+          "https://web.archive.org/web/20201022200156/https://download.geogebra.org/installers/6.0/GeoGebra-Linux64-Portable-${version}.zip"
+        ];
+      sha256 = "0rzcbq587x8827g9v03awa9hz27vyfjc0cz45ymbchqp31lsx49b";
+    };
 
-  unpackPhase = ''
-    unzip $src
-  '';
+    dontConfigure = true;
+    dontBuild = true;
 
-  installPhase = ''
-    mkdir -p $out/libexec/geogebra/ $out/bin
-    cp -r GeoGebra-linux-x64/{resources,locales} "$out/"
-    makeWrapper ${stdenv.lib.getBin electron_6}/bin/electron $out/bin/geogebra --add-flags "$out/resources/app"
-    install -Dm644 "${desktopItem}/share/applications/"* \
-      -t $out/share/applications/
+    nativeBuildInputs = [
+      unzip
+      makeWrapper
+    ];
 
-    install -Dm644 "${srcIcon}" \
-      "$out/share/icons/hicolor/scalable/apps/geogebra.svg"
-  '';
+    unpackPhase = ''
+      unzip $src
+    '';
 
-  srcIcon = geogebra.srcIcon;
+    installPhase = ''
+      mkdir -p $out/libexec/geogebra/ $out/bin
+      cp -r GeoGebra-linux-x64/{resources,locales} "$out/"
+      makeWrapper ${stdenv.lib.getBin electron_6}/bin/electron $out/bin/geogebra --add-flags "$out/resources/app"
+      install -Dm644 "${desktopItem}/share/applications/"* \
+        -t $out/share/applications/
 
-  desktopItem = geogebra.desktopItem;
-  meta = with stdenv.lib; geogebra.meta // {
-    license = licenses.geogebra;
-    maintainers = with maintainers; [ voidless ];
-    platforms = platforms.linux;
+      install -Dm644 "${srcIcon}" \
+        "$out/share/icons/hicolor/scalable/apps/geogebra.svg"
+    '';
+  };
+
+  darwinPkg = stdenv.mkDerivation {
+    inherit pname version meta;
+
+    src = fetchurl {
+      url = "https://download.geogebra.org/installers/6.0/GeoGebra-Classic-6-MacOS-Portable-${version}.zip";
+      sha256 = "0275869zgwbl1qjj593q6629hnxbwk9c15rkm29a3lh10pinb099";
+    };
+
+    dontUnpack = true;
+
+    nativeBuildInputs = [ unzip ];
+
+    installPhase = ''
+      install -dm755 $out/Applications
+      unzip $src -d $out/Applications
+    '';
   };
-}
+in
+if stdenv.isDarwin
+then darwinPkg
+else linuxPkg
diff --git a/nixpkgs/pkgs/applications/science/math/gfan/default.nix b/nixpkgs/pkgs/applications/science/math/gfan/default.nix
index adac92f376c8..7e2a4625d301 100644
--- a/nixpkgs/pkgs/applications/science/math/gfan/default.nix
+++ b/nixpkgs/pkgs/applications/science/math/gfan/default.nix
@@ -8,11 +8,15 @@ stdenv.mkDerivation rec {
     sha256 = "02pihqb1lb76a0xbfwjzs1cd6ay3ldfxsm8dvsbl6qs3vkjxax56";
   };
 
-  patchPhase = stdenv.lib.optionalString stdenv.cc.isClang ''
+  patches = [
+    ./gfan-0.6.2-cddlib-prefix.patch
+  ];
+
+  postPatch = stdenv.lib.optionalString stdenv.cc.isClang ''
     substituteInPlace Makefile --replace "-fno-guess-branch-probability" ""
   '';
 
-  buildFlags = [ "CC=cc" "CXX=c++" "cddnoprefix=1" ];
+  buildFlags = [ "CC=cc" "CXX=c++" ];
   installFlags = [ ''PREFIX=$(out)'' ];
   buildInputs = [ gmp mpir cddlib ];
 
diff --git a/nixpkgs/pkgs/applications/science/math/gfan/gfan-0.6.2-cddlib-prefix.patch b/nixpkgs/pkgs/applications/science/math/gfan/gfan-0.6.2-cddlib-prefix.patch
new file mode 100644
index 000000000000..8a96a991cf75
--- /dev/null
+++ b/nixpkgs/pkgs/applications/science/math/gfan/gfan-0.6.2-cddlib-prefix.patch
@@ -0,0 +1,55 @@
+diff -ru gfan0.6.2.orig/src/app_librarytest.cpp gfan0.6.2/src/app_librarytest.cpp
+--- gfan0.6.2.orig/src/app_librarytest.cpp	2020-10-19 08:41:27.981863500 +0900
++++ gfan0.6.2/src/app_librarytest.cpp	2020-10-19 08:42:44.551863500 +0900
+@@ -12,8 +12,8 @@
+ #include "setoper.h"
+ #include "cdd.h"
+ #else
+-#include "cdd/setoper.h"
+-#include "cdd/cdd.h"
++#include "cddlib/setoper.h"
++#include "cddlib/cdd.h"
+ #endif
+ #include <iostream>
+ #include <fstream>
+diff -ru gfan0.6.2.orig/src/gfanlib_zcone.cpp gfan0.6.2/src/gfanlib_zcone.cpp
+--- gfan0.6.2.orig/src/gfanlib_zcone.cpp	2020-10-19 08:41:27.981863500 +0900
++++ gfan0.6.2/src/gfanlib_zcone.cpp	2020-10-19 08:42:44.571863500 +0900
+@@ -16,8 +16,8 @@
+ #include "setoper.h"
+ #include "cdd.h"
+ #else
+-#include "cdd/setoper.h"
+-#include "cdd/cdd.h"
++#include "cddlib/setoper.h"
++#include "cddlib/cdd.h"
+ #endif
+ //}
+ 
+@@ -52,8 +52,8 @@
+ 				  "dd_free_global_constants()\n"
+ 				  "in your deinitialisation code (only available for cddlib version>=094d).\n"
+ 				  "This requires the header includes:\n"
+-				  "#include \"cdd/setoper.h\"\n"
+-				  "#include \"cdd/cdd.h\"\n"
++				  "#include \"cddlib/setoper.h\"\n"
++				  "#include \"cddlib/cdd.h\"\n"
+ 				  "\n"
+ 				  "Alternatively, you may call gfan:initializeCddlibIfRequired() and deinitializeCddlibIfRequired()\n"
+ 				  "if gfanlib is the only code using cddlib. If at some point cddlib is no longer required by gfanlib\n"
+diff -ru gfan0.6.2.orig/src/lp_cdd.cpp gfan0.6.2/src/lp_cdd.cpp
+--- gfan0.6.2.orig/src/lp_cdd.cpp	2020-10-19 08:41:27.991863500 +0900
++++ gfan0.6.2/src/lp_cdd.cpp	2020-10-19 08:42:44.571863500 +0900
+@@ -5,9 +5,9 @@
+ #include "cdd.h"
+ #include "cdd_f.h"
+ #else
+-#include "cdd/setoper.h"
+-#include "cdd/cdd.h"
+-#include "cdd/cdd_f.h"
++#include "cddlib/setoper.h"
++#include "cddlib/cdd.h"
++#include "cddlib/cdd_f.h"
+ #endif
+ //}
+ #include "termorder.h"
diff --git a/nixpkgs/pkgs/applications/science/math/giac/default.nix b/nixpkgs/pkgs/applications/science/math/giac/default.nix
index ea9c921f19e1..b090274919bd 100644
--- a/nixpkgs/pkgs/applications/science/math/giac/default.nix
+++ b/nixpkgs/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/nixpkgs/pkgs/applications/science/math/ginac/default.nix b/nixpkgs/pkgs/applications/science/math/ginac/default.nix
index 701445f90100..3c129e8033bd 100644
--- a/nixpkgs/pkgs/applications/science/math/ginac/default.nix
+++ b/nixpkgs/pkgs/applications/science/math/ginac/default.nix
@@ -1,11 +1,11 @@
 { stdenv, fetchurl, cln, pkgconfig, readline, gmp, python }:
 
 stdenv.mkDerivation rec {
-  name = "ginac-1.7.9";
+  name = "ginac-1.8.0";
 
   src = fetchurl {
     url    = "${meta.homepage}/${name}.tar.bz2";
-    sha256 = "08cqc87qq4w6z3l053x5gfqsa4zkgkicq8skxsbsj39nli1zzkb7";
+    sha256 = "0l9byzfxq3f9az5pcdldnl95ws8mpirkqky46f973mvxi5541d24";
   };
 
   propagatedBuildInputs = [ cln ];
diff --git a/nixpkgs/pkgs/applications/science/math/gmsh/default.nix b/nixpkgs/pkgs/applications/science/math/gmsh/default.nix
index db7e238e8ded..1b6dc2ae0076 100644
--- a/nixpkgs/pkgs/applications/science/math/gmsh/default.nix
+++ b/nixpkgs/pkgs/applications/science/math/gmsh/default.nix
@@ -5,11 +5,11 @@ assert (!blas.isILP64) && (!lapack.isILP64);
 
 stdenv.mkDerivation rec {
   pname = "gmsh";
-  version = "4.6.0";
+  version = "4.7.1";
 
   src = fetchurl {
     url = "http://gmsh.info/src/gmsh-${version}-source.tgz";
-    sha256 = "075dyblmlfdlhgbb1dwk6jzlqx93q90n6zwpr3mpii5n1zjmab0g";
+    sha256 = "0shwi41van3k0z6rnpl3sz5nh46xbyyljwfpcp8pwxbc26aw5169";
   };
 
   buildInputs = [ blas lapack gmm fltk libjpeg zlib libGLU libGL
diff --git a/nixpkgs/pkgs/applications/science/math/gretl/default.nix b/nixpkgs/pkgs/applications/science/math/gretl/default.nix
new file mode 100644
index 000000000000..7d77453cbab0
--- /dev/null
+++ b/nixpkgs/pkgs/applications/science/math/gretl/default.nix
@@ -0,0 +1,43 @@
+{ stdenv, fetchurl, curl, fftw, gmp, gnuplot, gtk3, gtksourceview3, json-glib
+, lapack, libxml2, mpfr, openblas, pkg-config, readline }:
+
+stdenv.mkDerivation rec {
+  pname = "gretl";
+  version = "2020e";
+
+  src = fetchurl {
+    url = "mirror://sourceforge/gretl/${pname}-${version}.tar.xz";
+    sha256 = "105y5hkzgyvad6wc3y7nn327bvrsch6jp03ckkn0w0hpnhiywzx7";
+  };
+
+  buildInputs = [
+    curl
+    fftw
+    gmp
+    gnuplot
+    gtk3
+    gtksourceview3
+    json-glib
+    lapack
+    libxml2
+    mpfr
+    openblas
+    readline
+  ];
+
+  nativeBuildInputs = [ pkg-config ];
+
+  enableParallelBuilding = true;
+
+  meta = with stdenv.lib; {
+    description = "A software package for econometric analysis";
+    longDescription = ''
+      gretl is a cross-platform software package for econometric analysis,
+      written in the C programming language.
+    '';
+    homepage = "http://gretl.sourceforge.net";
+    license = licenses.gpl3;
+    maintainers = with maintainers; [ dmrauh ];
+    platforms = with platforms; all;
+  };
+}
diff --git a/nixpkgs/pkgs/applications/science/math/lrcalc/default.nix b/nixpkgs/pkgs/applications/science/math/lrcalc/default.nix
index 438a84c0e0be..ddd470e621a0 100644
--- a/nixpkgs/pkgs/applications/science/math/lrcalc/default.nix
+++ b/nixpkgs/pkgs/applications/science/math/lrcalc/default.nix
@@ -34,7 +34,7 @@ stdenv.mkDerivation rec {
     description = "Littlewood-Richardson calculator";
     homepage = "http://math.rutgers.edu/~asbuch/lrcalc/";
     license = licenses.gpl2Plus;
-    maintainers = with maintainers; [ timokau ];
+    maintainers = teams.sage.members;
     platforms = platforms.unix;
   };
 }
diff --git a/nixpkgs/pkgs/applications/science/math/mathematica/default.nix b/nixpkgs/pkgs/applications/science/math/mathematica/default.nix
index 94d72eec6ae4..ea9a9c1b7554 100644
--- a/nixpkgs/pkgs/applications/science/math/mathematica/default.nix
+++ b/nixpkgs/pkgs/applications/science/math/mathematica/default.nix
@@ -3,6 +3,7 @@
 , patchelf
 , requireFile
 , callPackage
+, makeWrapper
 , alsaLib
 , dbus
 , fontconfig
@@ -11,7 +12,7 @@
 , glib
 , libssh2
 , ncurses
-, opencv2
+, opencv4
 , openssl
 , unixODBC
 , xkeyboard_config
@@ -37,6 +38,7 @@ stdenv.mkDerivation rec {
   buildInputs = [
     coreutils
     patchelf
+    makeWrapper
     alsaLib
     coreutils
     dbus
@@ -47,7 +49,7 @@ stdenv.mkDerivation rec {
     glib
     libssh2
     ncurses
-    opencv2
+    opencv4
     openssl
     stdenv.cc.cc.lib
     unixODBC
@@ -106,6 +108,9 @@ stdenv.mkDerivation rec {
 
     # Remove some broken libraries
     rm -f $out/libexec/Mathematica/SystemFiles/Libraries/Linux-x86-64/libz.so*
+
+    # Set environment variable to fix libQt errors - see https://github.com/NixOS/nixpkgs/issues/96490
+    wrapProgram $out/bin/mathematica --set USE_WOLFRAM_LD_LIBRARY_PATH 1
   '';
 
   preFixup = ''
@@ -139,6 +144,9 @@ stdenv.mkDerivation rec {
   '';
 
   dontBuild = true;
+  
+  # This is primarily an IO bound build; there's little benefit to building remotely.
+  preferLocalBuild = true;
 
   # all binaries are already stripped
   dontStrip = true;
diff --git a/nixpkgs/pkgs/applications/science/math/mathematica/l10ns.nix b/nixpkgs/pkgs/applications/science/math/mathematica/l10ns.nix
index 8ec6ac5048d5..896983ce1563 100644
--- a/nixpkgs/pkgs/applications/science/math/mathematica/l10ns.nix
+++ b/nixpkgs/pkgs/applications/science/math/mathematica/l10ns.nix
@@ -8,22 +8,10 @@ let allVersions = with lib; flip map
   # N.B. Versions in this list should be ordered from newest to oldest.
   [
     {
-      version = "12.1.1";
+      version = "12.2.0";
       lang = "en";
       language = "English";
-      sha256 = "02mk8gmv8idnakva1nc7r7mx8ld02lk7jgsj1zbn962aps3bhixd";
-    }
-    {
-      version = "12.1.0";
-      lang = "en";
-      language = "English";
-      sha256 = "15m9l20jvkxh5w6mbp81ys7mx2lx5j8acw5gz0il89lklclgb8z7";
-    }
-    {
-      version = "12.0.0";
-      lang = "en";
-      language = "English";
-      sha256 = "b9fb71e1afcc1d72c200196ffa434512d208fa2920e207878433f504e58ae9d7";
+      sha256 = "3b6676a203c6adb7e9c418a5484b037974287b5be09c64e7dfea74ddc0e400d7";
     }
     {
       version = "11.3.0";
diff --git a/nixpkgs/pkgs/applications/science/math/maxima/5.41.nix b/nixpkgs/pkgs/applications/science/math/maxima/5.41.nix
deleted file mode 100644
index 829dffc6116e..000000000000
--- a/nixpkgs/pkgs/applications/science/math/maxima/5.41.nix
+++ /dev/null
@@ -1,102 +0,0 @@
-{ stdenv, fetchurl, fetchpatch, sbcl, texinfo, perl, python, makeWrapper, rlwrap ? null
-, tk ? null, gnuplot ? null, ecl ? null, ecl-fasl ? false
-}:
-
-let
-  name    = "maxima";
-  # old version temporarily kept for sage, see discussion at
-  # https://github.com/NixOS/nixpkgs/commit/82254747af35f3e0e0d6f78023ded3a81e25331b
-  version = "5.41.0";
-
-  searchPath =
-    stdenv.lib.makeBinPath
-      (stdenv.lib.filter (x: x != null) [ sbcl ecl rlwrap tk gnuplot ]);
-in
-stdenv.mkDerivation ({
-  inherit version;
-  name = "${name}-${version}";
-
-  src = fetchurl {
-    url = "mirror://sourceforge/${name}/${name}-${version}.tar.gz";
-    sha256 = "0x0n81z0s4pl8nwpf7ivlsbvsdphm9w42250g7qdkizl0132by6s";
-  };
-
-  buildInputs = stdenv.lib.filter (x: x != null) [
-    sbcl ecl texinfo perl python makeWrapper
-  ];
-
-  postInstall = ''
-    # Make sure that maxima can find its runtime dependencies.
-    for prog in "$out/bin/"*; do
-      wrapProgram "$prog" --prefix PATH ":" "$out/bin:${searchPath}"
-    done
-    # Move emacs modules and documentation into the right place.
-    mkdir -p $out/share/emacs $out/share/doc
-    ln -s ../maxima/${version}/emacs $out/share/emacs/site-lisp
-    ln -s ../maxima/${version}/doc $out/share/doc/maxima
-  ''
-   + (stdenv.lib.optionalString ecl-fasl ''
-     cp src/binary-ecl/maxima.fas* "$out/lib/maxima/${version}/binary-ecl/"
-   '')
-  ;
-
-  patches = [
-    # fix path to info dir (see https://trac.sagemath.org/ticket/11348)
-    (fetchpatch {
-      url = "https://git.sagemath.org/sage.git/plain/build/pkgs/maxima/patches/infodir.patch?id=07d6c37d18811e2b377a9689790a7c5e24da16ba";
-      sha256 = "09v64n60f7i6frzryrj0zd056lvdpms3ajky4f9p6kankhbiv21x";
-    })
-
-    # fix https://sourceforge.net/p/maxima/bugs/2596/
-    (fetchpatch {
-      url = "https://git.sagemath.org/sage.git/plain/build/pkgs/maxima/patches/matrixexp.patch?id=07d6c37d18811e2b377a9689790a7c5e24da16ba";
-      sha256 = "06961hn66rhjijfvyym21h39wk98sfxhp051da6gz0n9byhwc6zg";
-    })
-
-    # undo https://sourceforge.net/p/maxima/code/ci/f5e9b0f7eb122c4e48ea9df144dd57221e5ea0ca, see see https://trac.sagemath.org/ticket/13364#comment:93
-    (fetchpatch {
-      url = "https://git.sagemath.org/sage.git/plain/build/pkgs/maxima/patches/undoing_true_false_printing_patch.patch?id=07d6c37d18811e2b377a9689790a7c5e24da16ba";
-      sha256 = "0fvi3rcjv6743sqsbgdzazy9jb6r1p1yq63zyj9fx42wd1hgf7yx";
-    })
-
-    # upstream bug https://sourceforge.net/p/maxima/bugs/2520/ (not fixed)
-    # introduced in https://trac.sagemath.org/ticket/13364
-    (fetchpatch {
-      url = "https://git.sagemath.org/sage.git/plain/build/pkgs/maxima/patches/0001-taylor2-Avoid-blowing-the-stack-when-diff-expand-isn.patch?id=07d6c37d18811e2b377a9689790a7c5e24da16ba";
-      sha256 = "0xa0b6cr458zp7lc7qi0flv5ar0r3ivsqhjl0c3clv86di2y522d";
-    })
-  ] ++ stdenv.lib.optionals ecl-fasl [
-    # build fasl, needed for ECL support
-    (fetchpatch {
-      url = "https://git.sagemath.org/sage.git/plain/build/pkgs/maxima/patches/maxima.system.patch?id=07d6c37d18811e2b377a9689790a7c5e24da16ba";
-      sha256 = "18zafig8vflhkr80jq2ivk46k92dkszqlyq8cfmj0b2vcfjwwbar";
-    })
-    # There are some transient test failures. I hope this disables all those tests.
-    # If those test failures ever happen in the non-ecl version, that should be
-    # reportetd upstream.
-    ./known-ecl-failures.patch
-  ];
-
-  # Failures in the regression test suite won't abort the build process. We run
-  # the suite only so that potential errors show up in the build log. See also:
-  # https://sourceforge.net/tracker/?func=detail&aid=3365831&group_id=4933&atid=104933.
-  doCheck = true;
-
-  enableParallelBuilding = true;
-
-  meta = {
-    description = "Computer algebra system";
-    homepage = "http://maxima.sourceforge.net";
-    license = stdenv.lib.licenses.gpl2;
-
-    longDescription = ''
-      Maxima is a fairly complete computer algebra system written in
-      lisp with an emphasis on symbolic computation. It is based on
-      DOE-MACSYMA and licensed under the GPL. Its abilities include
-      symbolic integration, 3D plotting, and an ODE solver.
-    '';
-
-    platforms = stdenv.lib.platforms.unix;
-    maintainers = [ stdenv.lib.maintainers.peti ];
-  };
-})
diff --git a/nixpkgs/pkgs/applications/science/math/maxima/default.nix b/nixpkgs/pkgs/applications/science/math/maxima/default.nix
index 49ff0d5d5a05..cdc81a876465 100644
--- a/nixpkgs/pkgs/applications/science/math/maxima/default.nix
+++ b/nixpkgs/pkgs/applications/science/math/maxima/default.nix
@@ -1,10 +1,10 @@
-{ stdenv, fetchurl, fetchpatch, sbcl, texinfo, perl, python, makeWrapper, rlwrap ? null
-, tk ? null, gnuplot ? null, ecl ? null, ecl-fasl ? false
+{ stdenv, fetchurl, fetchpatch, sbcl, texinfo, perl, python, makeWrapper, autoreconfHook
+, rlwrap ? null, tk ? null, gnuplot ? null, ecl ? null, ecl-fasl ? false
 }:
 
 let
   name    = "maxima";
-  version = "5.42.2";
+  version = "5.44.0";
 
   searchPath =
     stdenv.lib.makeBinPath
@@ -16,14 +16,20 @@ stdenv.mkDerivation ({
 
   src = fetchurl {
     url = "mirror://sourceforge/${name}/${name}-${version}.tar.gz";
-    sha256 = "0kdncy6137sg3rradirxzj10mkcvafxd892zlclwhr9sa7b12zhn";
+    sha256 = "1v6jr5s6hhj6r18gfk6hgxk2qd6z1dxkrjq9ss2z1y6sqi45wgyr";
   };
 
+  nativeBuildInputs = [ autoreconfHook ];
+
   buildInputs = stdenv.lib.filter (x: x != null) [
     sbcl ecl texinfo perl python makeWrapper
     gnuplot   # required in the test suite
   ];
 
+  postPatch = ''
+    substituteInPlace doc/info/Makefile.am --replace "/usr/bin/env perl" "${perl}/bin/perl"
+  '';
+
   postInstall = ''
     # Make sure that maxima can find its runtime dependencies.
     for prog in "$out/bin/"*; do
@@ -57,13 +63,6 @@ stdenv.mkDerivation ({
       url = "https://git.sagemath.org/sage.git/plain/build/pkgs/maxima/patches/undoing_true_false_printing_patch.patch?id=07d6c37d18811e2b377a9689790a7c5e24da16ba";
       sha256 = "0fvi3rcjv6743sqsbgdzazy9jb6r1p1yq63zyj9fx42wd1hgf7yx";
     })
-
-    # upstream bug https://sourceforge.net/p/maxima/bugs/2520/ (not fixed)
-    # introduced in https://trac.sagemath.org/ticket/13364
-    (fetchpatch {
-      url = "https://git.sagemath.org/sage.git/plain/build/pkgs/maxima/patches/0001-taylor2-Avoid-blowing-the-stack-when-diff-expand-isn.patch?id=07d6c37d18811e2b377a9689790a7c5e24da16ba";
-      sha256 = "0xa0b6cr458zp7lc7qi0flv5ar0r3ivsqhjl0c3clv86di2y522d";
-    })
   ] ++ stdenv.lib.optionals ecl-fasl [
     # build fasl, needed for ECL support
     (fetchpatch {
@@ -74,11 +73,13 @@ stdenv.mkDerivation ({
 
   # The test suite is disabled since 5.42.2 because of the following issues:
   #
-  #   Errors found in /build/maxima-5.42.2/share/linearalgebra/rtest_matrixexp.mac, problems:
+  #   Error(s) found:
+  #   /build/maxima-5.44.0/share/linearalgebra/rtest_matrixexp.mac problems:
   #   (20 21 22)
-  #   Error found in rtest_arag, problem:
-  #   (error break)
-  #   3 tests failed out of 3,881 total tests.
+  #   Tests that were expected to fail but passed:
+  #   /build/maxima-5.44.0/share/vector/rtest_vect.mac problem:
+  #   (19)
+  #   3 tests failed out of 16,184 total tests.
   #
   # These failures don't look serious. It would be nice to fix them, but I
   # don't know how and probably won't have the time to find out.
@@ -86,6 +87,10 @@ stdenv.mkDerivation ({
 
   enableParallelBuilding = true;
 
+  passthru = {
+    ecl = ecl;
+  };
+
   meta = {
     description = "Computer algebra system";
     homepage = "http://maxima.sourceforge.net";
diff --git a/nixpkgs/pkgs/applications/science/math/maxima/known-ecl-failures.patch b/nixpkgs/pkgs/applications/science/math/maxima/known-ecl-failures.patch
deleted file mode 100644
index f1d612d993e6..000000000000
--- a/nixpkgs/pkgs/applications/science/math/maxima/known-ecl-failures.patch
+++ /dev/null
@@ -1,21 +0,0 @@
-diff --git a/tests/testsuite.lisp b/tests/testsuite.lisp
-index 45a81f4..36c35b8 100644
---- a/tests/testsuite.lisp
-+++ b/tests/testsuite.lisp
-@@ -25,13 +25,14 @@
-         ((mlist simp) "rtest10" 24 25)
-         ((mlist) "rtest11" #+(or gcl cmucl ccl64) 158 #+(or gcl cmucl ccl64) 174 #+gcl 175)
-         "rtest13" "rtest13s"
--        "rtest14"
-+        ;; "rtest14" ;; some tests sometimes fail with ecl, hard to reproduce. Observed failing: 250, 267, 297, 307, 310, 312, 315, 319
-         "rtest15"
- 	;; ccl versions 1.11 and earlier fail test 50.  Mark it as a
- 	;; known failure.  Presumably 1.12 will have this fixed.
-         ((mlist simp) "rtest16" #+ccl 50)
-         "rtestode" "rtestode_zp"
--        "rtest3" "rtest8"
-+        "rtest3"
-+        ((mlist simp) "rtest8" 104) ;; fails with ecl
-         ((mlist simp) "rtest12" 76 78)
-         "rexamples"
-         ((mlist simp) "rtesthyp" 105 112 113 123 124 128)
diff --git a/nixpkgs/pkgs/applications/science/math/nauty/default.nix b/nixpkgs/pkgs/applications/science/math/nauty/default.nix
index d75fc9731cdf..94b7ad266c45 100644
--- a/nixpkgs/pkgs/applications/science/math/nauty/default.nix
+++ b/nixpkgs/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 = [
@@ -33,7 +33,7 @@ stdenv.mkDerivation rec {
     inherit version;
     description = ''Programs for computing automorphism groups of graphs and digraphs'';
     license = licenses.asl20;
-    maintainers = with maintainers; [ raskin timokau ];
+    maintainers = teams.sage.members;
     platforms = platforms.unix;
     # I'm not sure if the filename will remain the same for future changelog or
     # if it will track changes to minor releases. Lets see. Better than nothing
diff --git a/nixpkgs/pkgs/applications/science/math/palp/default.nix b/nixpkgs/pkgs/applications/science/math/palp/default.nix
index c383438002f4..9ae4fe1ba920 100644
--- a/nixpkgs/pkgs/applications/science/math/palp/default.nix
+++ b/nixpkgs/pkgs/applications/science/math/palp/default.nix
@@ -84,7 +84,7 @@ stdenv.mkDerivation rec {
     # version was released that pointed to gplv2 however, so thats probably
     # the right license.
     license = licenses.gpl2;
-    maintainers = with maintainers; [ timokau ];
+    maintainers = teams.sage.members;
     platforms = platforms.unix;
   };
 }
diff --git a/nixpkgs/pkgs/applications/science/math/pari/default.nix b/nixpkgs/pkgs/applications/science/math/pari/default.nix
index 8b5176c94f69..7ec42d11ab14 100644
--- a/nixpkgs/pkgs/applications/science/math/pari/default.nix
+++ b/nixpkgs/pkgs/applications/science/math/pari/default.nix
@@ -1,6 +1,5 @@
 { stdenv
 , fetchurl
-, fetchpatch
 , gmp
 , readline
 , libX11
@@ -13,22 +12,14 @@ assert withThread -> libpthreadstubs != null;
 
 stdenv.mkDerivation rec {
   pname = "pari";
-  version = "2.11.3";
+  version = "2.11.4";
 
   src = fetchurl {
-    url = "https://pari.math.u-bordeaux.fr/pub/pari/unix/${pname}-${version}.tar.gz";
-    sha256 = "1jd65h2psrmba2dx7rkf5qidf9ka0cwbsg20pd18k45ggr30l467";
+    # 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=";
   };
 
-  patches = [
-    # https://trac.sagemath.org/ticket/29313#comment:1
-    (fetchpatch {
-      name = "backport-bug-fix.patch";
-      url = "https://git.archlinux.org/svntogit/community.git/plain/repos/community-x86_64/c7a1d35f.patch?h=packages/pari&id=27893d227290dc3821d68aa25877d9765c204dad";
-      sha256 = "0vm0fwyzj66cr32imip6srksd47s2s2sjl1rb26ph8gpfi3nalii";
-    })
-  ];
-
   buildInputs = [
     gmp
     readline
@@ -72,20 +63,20 @@ stdenv.mkDerivation rec {
        Belabas with the help of many volunteer contributors.
 
        - PARI is a C library, allowing fast computations.
-       - gp is an easy-to-use interactive shell giving access to the
-          PARI functions.
+       - gp is an easy-to-use interactive shell giving access to the PARI
+         functions.
        - GP is the name of gp's scripting language.
-       - gp2c, the GP-to-C compiler, combines the best of both worlds
-          by compiling GP scripts to the C language and transparently loading
-          the resulting functions into gp. (gp2c-compiled scripts will typically
-          run 3 or 4 times faster.) gp2c currently only understands a subset
-           of the GP language.
+       - gp2c, the GP-to-C compiler, combines the best of both worlds by
+         compiling GP scripts to the C language and transparently loading the
+         resulting functions into gp. (gp2c-compiled scripts will typically run
+         3 or 4 times faster.) gp2c currently only understands a subset of the
+         GP language.
     '';
-    homepage    = "http://pari.math.u-bordeaux.fr";
+    homepage = "http://pari.math.u-bordeaux.fr";
     downloadPage = "http://pari.math.u-bordeaux.fr/download.html";
-    license     = licenses.gpl2Plus;
-    maintainers = with maintainers; [ ertes raskin AndersonTorres timokau ];
-    platforms   = platforms.linux ++ platforms.darwin;
+    license = licenses.gpl2Plus;
+    maintainers = with maintainers; [ ertes AndersonTorres ] ++ teams.sage.members;
+    platforms = platforms.linux ++ platforms.darwin;
     updateWalker = true;
   };
 }
diff --git a/nixpkgs/pkgs/applications/science/math/pari/gp2c.nix b/nixpkgs/pkgs/applications/science/math/pari/gp2c.nix
index 4fa63e8edabd..082ff60c3e8d 100644
--- a/nixpkgs/pkgs/applications/science/math/pari/gp2c.nix
+++ b/nixpkgs/pkgs/applications/science/math/pari/gp2c.nix
@@ -1,14 +1,15 @@
-{ stdenv, fetchurl
-, pari, perl }:
+{ stdenv
+, pari
+, fetchurl
+, perl }:
 
 stdenv.mkDerivation rec {
-
   pname = "gp2c";
-  version = "0.0.11pl3";
+  version = "0.0.12";
 
   src = fetchurl {
     url = "https://pari.math.u-bordeaux.fr/pub/pari/GP2C/${pname}-${version}.tar.gz";
-    sha256 = "0yymbrgyjw500hqgmkj5m4nmscd7c9rs9w2c96lxgrcyab8krhrm";
+    sha256 = "039ip7qkwwv46wrcdrz7y12m30kazzkjr44kqbc0h137g4wzd7zf";
   };
 
   buildInputs = [ pari perl ];
@@ -19,9 +20,9 @@ stdenv.mkDerivation rec {
 
   meta = with stdenv.lib; {
     description =  "A compiler to translate GP scripts to PARI programs";
-    homepage    = "http://pari.math.u-bordeaux.fr/";
+    homepage = "http://pari.math.u-bordeaux.fr/";
     downloadPage = "http://pari.math.u-bordeaux.fr/download.html";
-    license     = licenses.gpl2Plus;
+    license = licenses.gpl2Plus;
     maintainers = with maintainers; [ AndersonTorres ];
   };
 }
diff --git a/nixpkgs/pkgs/applications/science/math/pspp/default.nix b/nixpkgs/pkgs/applications/science/math/pspp/default.nix
index 95c2c3931b3c..d6c5b58f0d56 100644
--- a/nixpkgs/pkgs/applications/science/math/pspp/default.nix
+++ b/nixpkgs/pkgs/applications/science/math/pspp/default.nix
@@ -1,19 +1,19 @@
 { stdenv, fetchurl, libxml2, readline, zlib, perl, cairo, gtk3, gsl
 , pkgconfig, gtksourceview, pango, gettext, dconf
 , makeWrapper, gsettings-desktop-schemas, hicolor-icon-theme
-, texinfo, ssw
+, texinfo, ssw, python3
 }:
 
 stdenv.mkDerivation rec {
   pname = "pspp";
-  version = "1.2.0";
+  version = "1.4.1";
 
   src = fetchurl {
     url = "mirror://gnu/pspp/${pname}-${version}.tar.gz";
-    sha256 = "07pp27zycrb5x927jwaj9r3q7hy915jh51xs85zxby6gfiwl63m5";
+    sha256 = "0lqrash677b09zxdlxp89z6k02y4i23mbqg83956dwl69wc53dan";
   };
 
-  nativeBuildInputs = [ pkgconfig texinfo ];
+  nativeBuildInputs = [ pkgconfig texinfo python3 ];
   buildInputs = [ libxml2 readline zlib perl cairo gtk3 gsl
     gtksourceview pango gettext
     makeWrapper gsettings-desktop-schemas hicolor-icon-theme ssw
diff --git a/nixpkgs/pkgs/applications/science/math/pynac/default.nix b/nixpkgs/pkgs/applications/science/math/pynac/default.nix
index 82e331216712..e3474d865e2d 100644
--- a/nixpkgs/pkgs/applications/science/math/pynac/default.nix
+++ b/nixpkgs/pkgs/applications/science/math/pynac/default.nix
@@ -1,11 +1,13 @@
 { stdenv
 , fetchFromGitHub
+, fetchurl
 , autoreconfHook
 , pkgconfig
 , flint
 , gmp
-, python2
+, python3
 , singular
+, ncurses
 }:
 
 stdenv.mkDerivation rec {
@@ -23,8 +25,8 @@ stdenv.mkDerivation rec {
     flint
     gmp
     singular
-    singular
-    python2
+    python3
+    ncurses
   ];
 
   nativeBuildInputs = [
@@ -32,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 = ''
@@ -42,7 +52,7 @@ stdenv.mkDerivation rec {
     '';
     homepage    = "http://pynac.org";
     license = licenses.gpl3;
-    maintainers = with maintainers; [ timokau ];
+    maintainers = teams.sage.members;
     platforms   = platforms.unix;
   };
 }
diff --git a/nixpkgs/pkgs/applications/science/math/qalculate-gtk/default.nix b/nixpkgs/pkgs/applications/science/math/qalculate-gtk/default.nix
index df622e7303d4..09ead07dc09d 100644
--- a/nixpkgs/pkgs/applications/science/math/qalculate-gtk/default.nix
+++ b/nixpkgs/pkgs/applications/science/math/qalculate-gtk/default.nix
@@ -2,27 +2,15 @@
 
 stdenv.mkDerivation rec {
   pname = "qalculate-gtk";
-  version = "3.12.1";
+  version = "3.15.0";
 
   src = fetchFromGitHub {
     owner = "qalculate";
     repo = "qalculate-gtk";
     rev = "v${version}";
-    sha256 = "0ylsxj9rn3dc1grn9w6jisci3ak0hxgbwzqp54azs3aj5cmvkfgg";
+    sha256 = "1w0r9vv1h3zbfdvk8965g5plfkz5clf81riil5b394ms9vsw0bx5";
   };
 
-  patchPhase = ''
-    # The gnome-search-provider2.c file generated by gdbus-codegen depends
-    # on gio-unix-2.0, which is a Requires.private of gtk+-3.0,
-    # and private dependencies are dropped in our default patched pkg-config.
-    # https://github.com/Qalculate/qalculate-gtk/pull/178
-    # https://github.com/NixOS/nixpkgs/issues/292
-    substituteInPlace configure.ac --replace 'libxml-2.0' 'libxml-2.0 gio-unix-2.0'
-
-    # https://github.com/Qalculate/qalculate-gtk/pull/179
-    echo searchprovider.o: gnome-search-provider2.c >>src/Makefile.am
-  '';
-
   hardeningDisable = [ "format" ];
 
   nativeBuildInputs = [ intltool pkgconfig autoreconfHook wrapGAppsHook ];
diff --git a/nixpkgs/pkgs/applications/science/math/rofi-calc/default.nix b/nixpkgs/pkgs/applications/science/math/rofi-calc/default.nix
index 40b2711ff65a..ebf2d2f0475d 100644
--- a/nixpkgs/pkgs/applications/science/math/rofi-calc/default.nix
+++ b/nixpkgs/pkgs/applications/science/math/rofi-calc/default.nix
@@ -12,13 +12,13 @@
 
 stdenv.mkDerivation rec {
   pname = "rofi-calc";
-  version = "1.8";
+  version = "1.9";
 
   src = fetchFromGitHub {
     owner = "svenstaro";
     repo = pname;
     rev = "v${version}";
-    sha256 = "0vwb9c3xvd2cms6cw8j8parg7w4bsxvvrd1wgggr8sz2p8rrvy5p";
+    sha256 = "ZGY4ZtAG/ZnEnC80modZBV4RdRQElbkjeoKCEFVrncE=";
   };
 
   nativeBuildInputs = [
@@ -48,7 +48,7 @@ stdenv.mkDerivation rec {
     homepage = "https://github.com/svenstaro/rofi-calc";
     license = licenses.mit;
     maintainers = with maintainers; [ luc65r albakham ];
-    platforms = [ "x86_64-linux" "x86_64-darwin" ];
+    platforms = with platforms; linux;
   };
 }
 
diff --git a/nixpkgs/pkgs/applications/science/math/sage/default.nix b/nixpkgs/pkgs/applications/science/math/sage/default.nix
index caf51c3da251..416f2b957b7b 100644
--- a/nixpkgs/pkgs/applications/science/math/sage/default.nix
+++ b/nixpkgs/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/nixpkgs/pkgs/applications/science/math/sage/env-locations.nix b/nixpkgs/pkgs/applications/science/math/sage/env-locations.nix
index bda2d23b9e52..b1ad0aad9c76 100644
--- a/nixpkgs/pkgs/applications/science/math/sage/env-locations.nix
+++ b/nixpkgs/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/nixpkgs/pkgs/applications/science/math/sage/flask-oldsessions.nix b/nixpkgs/pkgs/applications/science/math/sage/flask-oldsessions.nix
deleted file mode 100644
index 403dc8708fab..000000000000
--- a/nixpkgs/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 = with maintainers; [ timokau ];
-    homepage = "https://github.com/mitsuhiko/flask-oldsessions";
-  };
-}
diff --git a/nixpkgs/pkgs/applications/science/math/sage/flask-openid.nix b/nixpkgs/pkgs/applications/science/math/sage/flask-openid.nix
deleted file mode 100644
index 527173dec80a..000000000000
--- a/nixpkgs/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 = with maintainers; [ timokau ];
-    homepage = "https://pythonhosted.org/Flask-OpenID/";
-  };
-}
diff --git a/nixpkgs/pkgs/applications/science/math/sage/patches/Only-test-py2-py3-optional-tests-when-all-of-sage-is.patch b/nixpkgs/pkgs/applications/science/math/sage/patches/Only-test-py2-py3-optional-tests-when-all-of-sage-is.patch
index 8cd80281d0e4..d5c19a54fd96 100644
--- a/nixpkgs/pkgs/applications/science/math/sage/patches/Only-test-py2-py3-optional-tests-when-all-of-sage-is.patch
+++ b/nixpkgs/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/nixpkgs/pkgs/applications/science/math/sage/patches/do-not-test-find-library.patch b/nixpkgs/pkgs/applications/science/math/sage/patches/do-not-test-find-library.patch
index 3f844e1b1ef5..981759202386 100644
--- a/nixpkgs/pkgs/applications/science/math/sage/patches/do-not-test-find-library.patch
+++ b/nixpkgs/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/nixpkgs/pkgs/applications/science/math/sage/patches/docutils-0.15.patch b/nixpkgs/pkgs/applications/science/math/sage/patches/docutils-0.15.patch
deleted file mode 100644
index 63f5d2e146dd..000000000000
--- a/nixpkgs/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/nixpkgs/pkgs/applications/science/math/sage/patches/ignore-cmp-deprecation.patch b/nixpkgs/pkgs/applications/science/math/sage/patches/ignore-cmp-deprecation.patch
index 11ca74819615..a91ee319b8f0 100644
--- a/nixpkgs/pkgs/applications/science/math/sage/patches/ignore-cmp-deprecation.patch
+++ b/nixpkgs/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/nixpkgs/pkgs/applications/science/math/sage/patches/ignore-werkzeug-immutable-dict-deprecation.patch b/nixpkgs/pkgs/applications/science/math/sage/patches/ignore-werkzeug-immutable-dict-deprecation.patch
deleted file mode 100644
index c5f95b498d53..000000000000
--- a/nixpkgs/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/nixpkgs/pkgs/applications/science/math/sage/patches/pari-stackwarn.patch b/nixpkgs/pkgs/applications/science/math/sage/patches/pari-stackwarn.patch
deleted file mode 100644
index 49cdfd189b92..000000000000
--- a/nixpkgs/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/nixpkgs/pkgs/applications/science/math/sage/patches/pillow-update.patch b/nixpkgs/pkgs/applications/science/math/sage/patches/pillow-update.patch
new file mode 100644
index 000000000000..19d615522626
--- /dev/null
+++ b/nixpkgs/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/nixpkgs/pkgs/applications/science/math/sage/patches/python-5755-hotpatch.patch b/nixpkgs/pkgs/applications/science/math/sage/patches/python-5755-hotpatch.patch
deleted file mode 100644
index 1b64f39fe60f..000000000000
--- a/nixpkgs/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/nixpkgs/pkgs/applications/science/math/sage/patches/register-pretty-printer-earlier.patch b/nixpkgs/pkgs/applications/science/math/sage/patches/register-pretty-printer-earlier.patch
new file mode 100644
index 000000000000..83bd83a6d33b
--- /dev/null
+++ b/nixpkgs/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/nixpkgs/pkgs/applications/science/math/sage/patches/sagenb-cmp-deprecation.patch b/nixpkgs/pkgs/applications/science/math/sage/patches/sagenb-cmp-deprecation.patch
deleted file mode 100644
index 9f502a669517..000000000000
--- a/nixpkgs/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/nixpkgs/pkgs/applications/science/math/sage/patches/sagespawn-implicit-casting.patch b/nixpkgs/pkgs/applications/science/math/sage/patches/sagespawn-implicit-casting.patch
new file mode 100644
index 000000000000..2ee5db3e29c0
--- /dev/null
+++ b/nixpkgs/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/nixpkgs/pkgs/applications/science/math/sage/patches/sphinx-docbuild-subprocesses.patch b/nixpkgs/pkgs/applications/science/math/sage/patches/sphinx-docbuild-subprocesses.patch
index 56f092796229..661077cfa8cd 100644
--- a/nixpkgs/pkgs/applications/science/math/sage/patches/sphinx-docbuild-subprocesses.patch
+++ b/nixpkgs/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/nixpkgs/pkgs/applications/science/math/sage/patches/sympow-cache.patch b/nixpkgs/pkgs/applications/science/math/sage/patches/sympow-cache.patch
index 20020d610f80..d71f3acbc706 100644
--- a/nixpkgs/pkgs/applications/science/math/sage/patches/sympow-cache.patch
+++ b/nixpkgs/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/nixpkgs/pkgs/applications/science/math/sage/pybrial.nix b/nixpkgs/pkgs/applications/science/math/sage/pybrial.nix
deleted file mode 100644
index 718414126ae8..000000000000
--- a/nixpkgs/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 = with maintainers; [ timokau ];
-    };
-}
diff --git a/nixpkgs/pkgs/applications/science/math/sage/python-openid.nix b/nixpkgs/pkgs/applications/science/math/sage/python-openid.nix
deleted file mode 100644
index 4c7fdadadaf0..000000000000
--- a/nixpkgs/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 = with maintainers; [ timokau ];
-    homepage = "https://github.com/openid/python-openid/";
-  };
-}
diff --git a/nixpkgs/pkgs/applications/science/math/sage/sage-env.nix b/nixpkgs/pkgs/applications/science/math/sage/sage-env.nix
index ba7f6ccd18b5..568a4a39f393 100644
--- a/nixpkgs/pkgs/applications/science/math/sage/sage-env.nix
+++ b/nixpkgs/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/nixpkgs/pkgs/applications/science/math/sage/sage-src.nix b/nixpkgs/pkgs/applications/science/math/sage/sage-src.nix
index 4791d12450a9..8948621a025a 100644
--- a/nixpkgs/pkgs/applications/science/math/sage/sage-src.nix
+++ b/nixpkgs/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/nixpkgs/pkgs/applications/science/math/sage/sage-with-env.nix b/nixpkgs/pkgs/applications/science/math/sage/sage-with-env.nix
index 87c1e07f5307..f204d97961b6 100644
--- a/nixpkgs/pkgs/applications/science/math/sage/sage-with-env.nix
+++ b/nixpkgs/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/nixpkgs/pkgs/applications/science/math/sage/sage.nix b/nixpkgs/pkgs/applications/science/math/sage/sage.nix
index 4fa8ae6270ba..e2acef7b8eb5 100644
--- a/nixpkgs/pkgs/applications/science/math/sage/sage.nix
+++ b/nixpkgs/pkgs/applications/science/math/sage/sage.nix
@@ -63,6 +63,6 @@ stdenv.mkDerivation rec {
   meta = with stdenv.lib; {
     description = "Open Source Mathematics Software, free alternative to Magma, Maple, Mathematica, and Matlab";
     license = licenses.gpl2;
-    maintainers = with maintainers; [ timokau ];
+    maintainers = teams.sage.members;
   };
 }
diff --git a/nixpkgs/pkgs/applications/science/math/sage/sagedoc.nix b/nixpkgs/pkgs/applications/science/math/sage/sagedoc.nix
index bf618fe64f45..a10672f3a092 100644
--- a/nixpkgs/pkgs/applications/science/math/sage/sagedoc.nix
+++ b/nixpkgs/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/nixpkgs/pkgs/applications/science/math/sage/sagelib.nix b/nixpkgs/pkgs/applications/science/math/sage/sagelib.nix
index 830d806a8bcd..1c2235bf71b4 100644
--- a/nixpkgs/pkgs/applications/science/math/sage/sagelib.nix
+++ b/nixpkgs/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/nixpkgs/pkgs/applications/science/math/sage/sagenb.nix b/nixpkgs/pkgs/applications/science/math/sage/sagenb.nix
deleted file mode 100644
index 77b2168ad974..000000000000
--- a/nixpkgs/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 = with maintainers; [ timokau ];
-  };
-
-  # 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/nixpkgs/pkgs/applications/science/math/singular/default.nix b/nixpkgs/pkgs/applications/science/math/singular/default.nix
index a8c4f6bb9a09..8c5eac2c06d2 100644
--- a/nixpkgs/pkgs/applications/science/math/singular/default.nix
+++ b/nixpkgs/pkgs/applications/science/math/singular/default.nix
@@ -108,7 +108,7 @@ stdenv.mkDerivation rec {
 
   meta = with lib; {
     description = "A CAS for polynomial computations";
-    maintainers = with maintainers; [ raskin timokau ];
+    maintainers = teams.sage.members;
     # 32 bit x86 fails with some link error: `undefined reference to `__divmoddi4@GCC_7.0.0'`
     platforms = subtractLists platforms.i686 platforms.unix;
     license = licenses.gpl3; # Or GPLv2 at your option - but not GPLv4
diff --git a/nixpkgs/pkgs/applications/science/math/symmetrica/default.nix b/nixpkgs/pkgs/applications/science/math/symmetrica/default.nix
index b363137fb99c..ca752259797f 100644
--- a/nixpkgs/pkgs/applications/science/math/symmetrica/default.nix
+++ b/nixpkgs/pkgs/applications/science/math/symmetrica/default.nix
@@ -29,7 +29,7 @@ stdenv.mkDerivation rec {
   meta = with lib; {
     description = ''A collection of routines for representation theory and combinatorics'';
     license = licenses.isc;
-    maintainers = with maintainers; [raskin timokau];
+    maintainers = teams.sage.members;
     platforms = platforms.unix;
     homepage = "https://gitlab.com/sagemath/symmetrica";
   };
diff --git a/nixpkgs/pkgs/applications/science/math/zegrapher/default.nix b/nixpkgs/pkgs/applications/science/math/zegrapher/default.nix
new file mode 100644
index 000000000000..c9eb72cca433
--- /dev/null
+++ b/nixpkgs/pkgs/applications/science/math/zegrapher/default.nix
@@ -0,0 +1,36 @@
+{ stdenv
+, fetchFromGitHub
+, qmake
+, wrapQtAppsHook
+, boost }:
+
+stdenv.mkDerivation rec {
+  pname = "zegrapher";
+  version = "3.1.1";
+
+  src = fetchFromGitHub {
+    owner = "AdelKS";
+    repo = "ZeGrapher";
+    rev = "v${version}";
+    sha256 = "sha256-OSQXm0gDI1zM2MBM4iiY43dthJcAZJkprklolsNMEvk=";
+  };
+
+  nativeBuildInputs = [
+    qmake
+    wrapQtAppsHook
+  ];
+  buildInputs = [
+    boost
+  ];
+
+  meta = with stdenv.lib; {
+    homepage = "https://zegrapher.com/";
+    description = "An open source math plotter";
+    longDescription = ''
+      An open source, free and easy to use math plotter. It can plot functions,
+      sequences, parametric equations and data on the plane.
+    '';
+    license = licenses.gpl3Plus;
+    maintainers = with maintainers; [ AndersonTorres ];
+  };
+}