2018-04-24 22:53:36 +01:00
|
|
|
{ stdenv
|
|
|
|
, lib
|
|
|
|
, makeWrapper
|
|
|
|
, sage-env
|
2020-03-31 15:47:18 +01:00
|
|
|
, blas
|
|
|
|
, lapack
|
2018-04-24 22:53:36 +01:00
|
|
|
, pkg-config
|
|
|
|
, three
|
|
|
|
, singular
|
2019-01-16 23:28:37 +00:00
|
|
|
, gap
|
2018-04-24 22:53:36 +01:00
|
|
|
, giac
|
2021-11-29 12:43:39 +00:00
|
|
|
, maxima
|
2018-04-24 22:53:36 +01:00
|
|
|
, pari
|
|
|
|
, gmp
|
|
|
|
, gfan
|
2020-10-22 09:20:17 +01:00
|
|
|
, python3
|
2018-04-24 22:53:36 +01:00
|
|
|
, flintqs
|
|
|
|
, eclib
|
|
|
|
, ntl
|
|
|
|
, ecm
|
|
|
|
, pythonEnv
|
|
|
|
}:
|
|
|
|
|
2020-03-31 15:47:18 +01:00
|
|
|
# lots of segfaults with (64 bit) blas
|
2020-04-20 21:50:55 +01:00
|
|
|
assert (!blas.isILP64) && (!lapack.isILP64);
|
2020-03-31 15:47:18 +01:00
|
|
|
|
2018-11-12 22:28:29 +00:00
|
|
|
# Wrapper that combined `sagelib` with `sage-env` to produce an actually
|
|
|
|
# executable sage. No tests are run yet and no documentation is built.
|
|
|
|
|
2018-04-24 22:53:36 +01:00
|
|
|
let
|
2022-09-25 03:49:25 +01:00
|
|
|
nativeBuildInputs = [ pkg-config ];
|
2018-04-24 22:53:36 +01:00
|
|
|
buildInputs = [
|
|
|
|
pythonEnv # for patchShebangs
|
2020-03-31 15:47:18 +01:00
|
|
|
blas lapack
|
2018-04-24 22:53:36 +01:00
|
|
|
singular
|
|
|
|
three
|
|
|
|
giac
|
2019-01-16 23:28:37 +00:00
|
|
|
gap
|
2018-04-24 22:53:36 +01:00
|
|
|
pari
|
|
|
|
gmp
|
|
|
|
gfan
|
2021-11-29 12:43:39 +00:00
|
|
|
maxima
|
2018-04-24 22:53:36 +01:00
|
|
|
eclib
|
|
|
|
flintqs
|
|
|
|
ntl
|
|
|
|
ecm
|
|
|
|
];
|
|
|
|
|
|
|
|
# remove python prefix, replace "-" in the name by "_", apply patch_names
|
2020-11-30 13:09:26 +00:00
|
|
|
# python3.8-some-pkg-1.0 -> some_pkg-1.0
|
2018-04-24 22:53:36 +01:00
|
|
|
pkg_to_spkg_name = pkg: patch_names: let
|
|
|
|
parts = lib.splitString "-" pkg.name;
|
2020-11-30 13:09:26 +00:00
|
|
|
# remove python3.8-
|
2020-10-22 09:20:17 +01:00
|
|
|
stripped_parts = if (builtins.head parts) == python3.libPrefix then builtins.tail parts else parts;
|
2018-04-24 22:53:36 +01:00
|
|
|
version = lib.last stripped_parts;
|
|
|
|
orig_pkgname = lib.init stripped_parts;
|
|
|
|
pkgname = patch_names (lib.concatStringsSep "_" orig_pkgname);
|
|
|
|
in pkgname + "-" + version;
|
|
|
|
|
|
|
|
|
|
|
|
# return the names of all dependencies in the transitive closure
|
|
|
|
transitiveClosure = dep:
|
2019-04-24 04:48:22 +01:00
|
|
|
if dep == null then
|
2018-04-24 22:53:36 +01:00
|
|
|
# propagatedBuildInputs might contain null
|
|
|
|
# (although that might be considered a programming error in the derivation)
|
|
|
|
[]
|
|
|
|
else
|
|
|
|
[ dep ] ++ (
|
|
|
|
if builtins.hasAttr "propagatedBuildInputs" dep then
|
|
|
|
lib.unique (builtins.concatLists (map transitiveClosure dep.propagatedBuildInputs))
|
|
|
|
else
|
|
|
|
[]
|
|
|
|
);
|
|
|
|
|
2022-09-25 03:49:25 +01:00
|
|
|
allInputs = lib.remove null (nativeBuildInputs ++ buildInputs ++ pythonEnv.extraLibs ++ [ makeWrapper ]);
|
2018-04-24 22:53:36 +01:00
|
|
|
transitiveDeps = lib.unique (builtins.concatLists (map transitiveClosure allInputs ));
|
|
|
|
# fix differences between spkg and sage names
|
|
|
|
# (could patch sage instead, but this is more lightweight and also works for packages depending on sage)
|
|
|
|
patch_names = builtins.replaceStrings [
|
|
|
|
"zope.interface"
|
|
|
|
"node_three"
|
|
|
|
] [
|
|
|
|
"zope_interface"
|
|
|
|
"threejs"
|
|
|
|
];
|
|
|
|
# spkg names (this_is_a_package-version) of all transitive deps
|
|
|
|
input_names = map (dep: pkg_to_spkg_name dep patch_names) transitiveDeps;
|
|
|
|
in
|
|
|
|
stdenv.mkDerivation rec {
|
2018-11-12 22:28:29 +00:00
|
|
|
version = src.version;
|
2019-08-15 13:41:18 +01:00
|
|
|
pname = "sage-with-env";
|
2018-11-12 22:28:29 +00:00
|
|
|
src = sage-env.lib.src;
|
2018-04-24 22:53:36 +01:00
|
|
|
|
2022-09-25 03:49:25 +01:00
|
|
|
inherit nativeBuildInputs buildInputs;
|
2018-04-24 22:53:36 +01:00
|
|
|
|
|
|
|
configurePhase = "#do nothing";
|
|
|
|
|
|
|
|
buildPhase = ''
|
|
|
|
mkdir installed
|
|
|
|
for pkg in ${lib.concatStringsSep " " input_names}; do
|
|
|
|
touch "installed/$pkg"
|
|
|
|
done
|
2019-06-20 11:49:20 +01:00
|
|
|
|
|
|
|
# threejs version is in format 0.<version>.minor, but sage currently still
|
|
|
|
# relies on installed_packages for the online version of threejs to work
|
|
|
|
# and expects the format r<version>. This is a hotfix for now.
|
|
|
|
# upstream: https://trac.sagemath.org/ticket/26434
|
|
|
|
rm "installed/threejs"*
|
|
|
|
touch "installed/threejs-r${lib.versions.minor three.version}"
|
2018-04-24 22:53:36 +01:00
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
mkdir -p "$out/var/lib/sage"
|
2018-11-12 22:28:29 +00:00
|
|
|
cp -r installed "$out/var/lib/sage"
|
2018-04-24 22:53:36 +01:00
|
|
|
|
|
|
|
mkdir -p "$out/etc"
|
|
|
|
# sage tests will try to create this file if it doesn't exist
|
|
|
|
touch "$out/etc/sage-started.txt"
|
|
|
|
|
|
|
|
mkdir -p "$out/build"
|
2018-11-12 22:28:29 +00:00
|
|
|
|
|
|
|
# the scripts in src/bin will find the actual sage source files using environment variables set in `sage-env`
|
2018-04-24 22:53:36 +01:00
|
|
|
cp -r src/bin "$out/bin"
|
|
|
|
cp -r build/bin "$out/build/bin"
|
2018-11-12 22:28:29 +00:00
|
|
|
|
2021-09-14 02:56:34 +01:00
|
|
|
# sage assumes the existence of sage-src-env-config.in means it's being executed in-tree. in this case, it
|
|
|
|
# adds SAGE_SRC/bin to PATH, breaking our wrappers
|
|
|
|
rm "$out/bin"/*.in "$out/build/bin"/*.in
|
|
|
|
|
2018-04-24 22:53:36 +01:00
|
|
|
cp -f '${sage-env}/sage-env' "$out/bin/sage-env"
|
|
|
|
substituteInPlace "$out/bin/sage-env" \
|
|
|
|
--subst-var-by sage-local "$out"
|
|
|
|
'';
|
2018-11-12 22:28:29 +00:00
|
|
|
|
|
|
|
passthru = {
|
|
|
|
env = sage-env;
|
|
|
|
};
|
2018-04-24 22:53:36 +01:00
|
|
|
}
|