diff --git a/pkgs/applications/science/math/sage/default.nix b/pkgs/applications/science/math/sage/default.nix
index 92ec32d5cc525d..5f0b242a9c5c04 100644
--- a/pkgs/applications/science/math/sage/default.nix
+++ b/pkgs/applications/science/math/sage/default.nix
@@ -33,7 +33,7 @@ let
# `sagelib`, i.e. all of sage except some wrappers and runtime dependencies
sagelib = self.callPackage ./sagelib.nix {
inherit flint ecl arb;
- inherit sage-src pynac singular;
+ inherit sage-src env-locations pynac singular;
linbox = pkgs.linbox.override { withSage = true; };
pkg-config = pkgs.pkgconfig; # not to confuse with pythonPackages.pkgconfig
};
diff --git a/pkgs/applications/science/math/sage/patches/threejs-offline.patch b/pkgs/applications/science/math/sage/patches/threejs-offline.patch
new file mode 100644
index 00000000000000..62b2f114bd62c7
--- /dev/null
+++ b/pkgs/applications/science/math/sage/patches/threejs-offline.patch
@@ -0,0 +1,64 @@
+diff --git a/build/pkgs/threejs/spkg-src b/build/pkgs/threejs/spkg-src
+index 91780d813c..254b850a24 100755
+--- a/build/pkgs/threejs/spkg-src
++++ b/build/pkgs/threejs/spkg-src
+@@ -20,9 +20,17 @@ URL3="https://raw.githubusercontent.com/mrdoob/three.js/${GIT_VERSION}/LICENSE"
+ echo "Downloading $URL3"
+ curl -OL "$URL3"
+
++# Set up directory structure
++
++mkdir build
++mv three.min.js build
++
++mkdir -p examples/js/controls
++mv OrbitControls.js examples/js/controls
++
+ # Package
+-tar czf "$SAGE_ROOT/upstream/threejs-${GIT_VERSION}.tar.gz" 'three.min.js' 'OrbitControls.js' 'LICENSE'
+-rm -rf 'three.min.js' 'OrbitControls.js' 'LICENSE'
++tar czf "$SAGE_ROOT/upstream/threejs-${GIT_VERSION}.tar.gz" build examples 'LICENSE'
++rm -rf 'build' 'examples' 'LICENSE'
+
+ # Update package info
+ echo "${GIT_VERSION}" > 'package-version.txt'
+diff --git a/src/sage/repl/rich_output/backend_ipython.py b/src/sage/repl/rich_output/backend_ipython.py
+index 7c27d48a21..8bf4861a35 100644
+--- a/src/sage/repl/rich_output/backend_ipython.py
++++ b/src/sage/repl/rich_output/backend_ipython.py
+@@ -411,10 +411,15 @@ class BackendIPythonCommandline(BackendIPython):
+ sage: backend.threejs_offline_scripts()
+ '...
+-
++
++
+
diff --git a/pkgs/applications/science/math/sage/sage-src.nix b/pkgs/applications/science/math/sage/sage-src.nix
index 56d8082d2f557d..e0050efe6bdd3f 100644
--- a/pkgs/applications/science/math/sage/sage-src.nix
+++ b/pkgs/applications/science/math/sage/sage-src.nix
@@ -68,6 +68,9 @@ stdenv.mkDerivation rec {
url = "https://git.sagemath.org/sage.git/patch/?h=c4d966e7cb0c7b87c55d52dc6f46518433a2a0a2";
sha256 = "0pqbbsx8mriwny422s9mp3z5d095cnam32sm62q4mxk8g8jb9vm9";
})
+
+ # https://trac.sagemath.org/ticket/28007
+ ./patches/threejs-offline.patch
];
# Since sage unfortunately does not release bugfix releases, packagers must
diff --git a/pkgs/applications/science/math/sage/sagelib.nix b/pkgs/applications/science/math/sage/sagelib.nix
index d745532d5d701f..1040d6d4ba15a7 100644
--- a/pkgs/applications/science/math/sage/sagelib.nix
+++ b/pkgs/applications/science/math/sage/sagelib.nix
@@ -1,4 +1,5 @@
{ sage-src
+, env-locations
, perl
, buildPythonPackage
, arb
@@ -125,8 +126,11 @@ buildPythonPackage rec {
export SAGE_ROOT="$PWD"
export SAGE_LOCAL="$SAGE_ROOT"
export SAGE_SHARE="$SAGE_LOCAL/share"
- export JUPYTER_PATH="$SAGE_LOCAL/jupyter"
+ # set locations of dependencies (needed for nbextensions like threejs)
+ . ${env-locations}/sage-env-locations
+
+ export JUPYTER_PATH="$SAGE_LOCAL/jupyter"
export PATH="$SAGE_ROOT/build/bin:$SAGE_ROOT/src/bin:$PATH"
export SAGE_NUM_THREADS="$NIX_BUILD_CORES"