nixpkgs/pkgs/applications/science/math/sage/sage-src.nix
2024-01-25 19:06:47 +01:00

98 lines
3.9 KiB
Nix

{ stdenv
, fetchFromGitHub
, fetchpatch
, fetchurl
}:
# This file is responsible for fetching the sage source and adding necessary patches.
# It does not actually build anything, it just copies the patched sources to $out.
# This is done because multiple derivations rely on these sources and they should
# all get the same sources with the same patches applied.
stdenv.mkDerivation rec {
version = "10.2";
pname = "sage-src";
src = fetchFromGitHub {
owner = "sagemath";
repo = "sage";
rev = version;
sha256 = "sha256-VXnPdJhtw5Y/anecrVpevJDCyBVfnjksyuuZslNipm4=";
};
# contains essential files (e.g., setup.cfg) generated by the bootstrap script.
# TODO: investigate https://github.com/sagemath/sage/pull/35950
configure-src = fetchurl {
# the hash below is the tagged commit's _parent_. it can also be found by looking for
# the "configure" asset at https://github.com/sagemath/sage/releases/tag/${version}
url = "mirror://sageupstream/configure/configure-b2813506039143e6f0abe859ab67a343abf72c2e.tar.gz";
sha256 = "sha256-a1v0XyoKI+zO6Sjm8DzEwItRHbIgRDbpj4UfwVH+/hw=";
};
# 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 = [
# Parallelize docubuild using subprocesses, fixing an isolation issue. See
# https://groups.google.com/forum/#!topic/sage-packaging/YGOm8tkADrE
./patches/sphinx-docbuild-subprocesses.patch
# After updating smypow to (https://github.com/sagemath/sage/issues/3360)
# we can now set the cache dir to be within the .sage directory. This is
# not strictly necessary, but keeps us from littering in the user's HOME.
./patches/sympow-cache.patch
];
# Since sage unfortunately does not release bugfix releases, packagers must
# fix those bugs themselves. This is for critical bugfixes, where "critical"
# == "causes (transient) doctest failures / somebody complained".
bugfixPatches = [
# Sage uses mixed integer programs (MIPs) to find edge disjoint
# spanning trees. For some reason, aarch64 glpk takes much longer
# than x86_64 glpk to solve such MIPs. Since the MIP formulation
# has "numerous problems" and will be replaced by a polynomial
# algorithm soon, disable this test for now.
# https://github.com/sagemath/sage/issues/34575
./patches/disable-slow-glpk-test.patch
];
# Patches needed because of package updates. We could just pin the versions of
# dependencies, but that would lead to rebuilds, confusion and the burdons of
# maintaining multiple versions of dependencies. Instead we try to make sage
# compatible with never dependency versions when possible. All these changes
# should come from or be proposed to upstream. This list will probably never
# be empty since dependencies update all the time.
packageUpgradePatches = [
# https://github.com/sagemath/sage/pull/37123, to land in 10.3.beta7
(fetchpatch {
name = "scipy-1.12-upgrade.patch";
url = "https://github.com/sagemath/sage/commit/54eec464e9fdf18b411d9148aecb918178e95909.diff";
sha256 = "sha256-9wyNrcSfF6mYFTIV4ev2OdD7igb0AeyZZYWSc/+JrIU=";
})
];
patches = nixPatches ++ bugfixPatches ++ packageUpgradePatches;
# do not create .orig backup files if patch applies with fuzz
patchFlags = [ "--no-backup-if-mismatch" "-p1" ];
postPatch = ''
# 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_ROOT\".*|var(\"SAGE_ROOT\", \"$out\")|" \
src/sage/env.py
# sage --docbuild unsets JUPYTER_PATH, which breaks our docbuilding
# https://trac.sagemath.org/ticket/33650#comment:32
sed -i "/export JUPYTER_PATH/d" src/bin/sage
'';
buildPhase = "# do nothing";
installPhase = ''
cp -r . "$out"
tar xkzf ${configure-src} -C "$out"
rm "$out/configure"
'';
}