···1818# - https://git.archlinux.org/svntogit/community.git/tree/trunk?h=packages/sagemath
19192020{ stdenv
2121+, bash
2122, fetchurl
2223, perl
2324, gfortran
···2627, gettext
2728, which
2829, texlive
3030+, texinfo
2931, hevea
3032}:
31333234stdenv.mkDerivation rec {
3333- version = "8.0";
3535+ version = "8.1";
3436 name = "sage-${version}";
35373838+ # Modified version of patchShebangs that patches to the sage-internal version if possible
3939+ # and falls back to the system version if not.
4040+ patchSageShebangs = ./patchSageShebangs.sh;
3641 src = fetchurl {
3742 # Note that the source is *not* fetched from github, since that doesn't
3843 # the upstream folder with all the source tarballs of the spkgs.
···7075 "http://www-ftp.lip6.fr/pub/math/sagemath/src/sage-${version}.tar.gz"
7176 "http://ftp.ntua.gr/pub/sagemath/src/sage-${version}.tar.gz"
7277 ];
7373- sha256 = "1a9rhb8jby6fdqa2s7n2fl9jwqqlsl7qz7dbpbwvg6jwlrvni7fg";
7878+ sha256 = "1cpcs1mr0yii64s152xmxyd450bfzjb22jjj0zh9y3n6g9alzpyq";
7479 };
75807681 postPatch = ''
7782 substituteAllInPlace src/bin/sage-env
8383+ bash=${bash} substituteAllInPlace build/bin/sage-spkg
7884 '';
79858086 installPhase = ''
···8490 outputs = [ "out" "doc" ];
85918692 buildInputs = [
9393+ bash # needed for the build
8794 perl # needed for the build
8895 python # needed for the build
8989- gfortran # needed to build giac
9696+ gfortran # needed to build giac, openblas
9097 autoreconfHook # needed to configure sage with prefix
9198 gettext # needed to build the singular spkg
9299 hevea # needed to build the docs of the giac spkg
93100 which # needed in configure of mpir
94101 # needed to build the docs of the giac spkg
102102+ texinfo # needed to build maxima
95103 (texlive.combine { inherit (texlive)
96104 scheme-basic
97105 collection-pstricks # needed by giac
···102110 })
103111 ];
104112113113+ nativeBuildInputs = [ gfortran perl which ];
114114+105115 patches = [
106116 # fix usages of /bin/rm
107117 ./spkg-singular.patch
108118 # help python find the crypt library
109109- ./spkg-python2.patch
110110- ./spkg-python3.patch
119119+ # patches python3 and indirectly python2, since those installation files are symlinked
120120+ ./spkg-python.patch
111121 # fix usages of /usr/bin/perl
112122 ./spkg-git.patch
113123 # fix usages of /bin/cp and add necessary argument to function call
114124 ./spkg-giac.patch
115125 # environment
116126 ./env.patch
127127+ # adjust wrapper shebang and patch shebangs after each spkg build
128128+ ./shebangs.patch
117129 ];
118130119131 enableParallelBuilding = true;
···144156 preBuild = ''
145157 # TODO do this conditionally
146158 export SAGE_SPKG_INSTALL_DOCS='no'
147147- patchShebangs build
159159+ # symlink python to make sure the shebangs are patched to the sage path
160160+ # while still being able to use python before building it
161161+ # (this is important because otherwise sage will try to install python
162162+ # packages globally later on)
163163+ ln -s "${python}/bin/python2" $out/bin/python2
164164+ ln -s "$out/bin/python2" $out/bin/python
165165+ touch $out/bin/python3
166166+ bash $patchSageShebangs .
148167 '';
149168150169 postBuild = ''
···153172 rm -rf "$out/sage-root/src/.git"
154173 rm -r "$out/sage-root/logs"
155174 # Fix dependency cycle between out and doc
175175+ rm -f "$out/sage-root/config.log"
156176 rm -f "$out/sage-root/config.status"
157177 rm -f "$out/sage-root/build/make/Makefile-auto"
158178 rm -f "$out/sage-home/.sage/gap/libgap-workspace-"*
179179+ # Make sure all shebangs are properly patched
180180+ bash $patchSageShebangs $out
159181 '';
160182161183 # TODO there are some doctest failures, which seem harmless.
···11+# This is a slightly modified version of nix's default patchShebangs
22+33+dir="$1"
44+55+echo "patching sage internal script interpreter paths in $( readlink -f "$dir")"
66+77+find "$dir" -type f -perm -0100 | while read f; do
88+ if [ "$(head -1 "$f" | head -c+2)" != '#!' ]; then
99+ # missing shebang => not a script
1010+ continue
1111+ fi
1212+1313+ oldInterpreterLine=$(head -1 "$f" | tail -c+3)
1414+ read -r oldPath arg0 args <<< "$oldInterpreterLine"
1515+1616+ if $(echo "$oldPath" | grep -q "/bin/env$"); then
1717+ # Check for unsupported 'env' functionality:
1818+ # - options: something starting with a '-'
1919+ # - environment variables: foo=bar
2020+ if $(echo "$arg0" | grep -q -- "^-.*\|.*=.*"); then
2121+ echo "unsupported interpreter directive \"$oldInterpreterLine\" (set dontPatchShebangs=1 and handle shebang patching yourself)"
2222+ exit 1
2323+ fi
2424+ executable="$arg0"
2525+ else
2626+ if [ "$oldPath" = "" ]; then
2727+ # If no interpreter is specified linux will use /bin/sh. Set
2828+ # oldpath="/bin/sh" so that we get /nix/store/.../sh.
2929+ oldPath="/bin/sh"
3030+ fi
3131+ executable="$(basename "$oldPath")"
3232+ args="$arg0 $args"
3333+ fi
3434+3535+ newPath="$(echo "$out/bin/$executable $args" | sed 's/[[:space:]]*$//')"
3636+ if [[ ! -x "$newPath" ]] ; then
3737+ newPath="$(command -v "$executable" || true)"
3838+ fi
3939+4040+ # Strip trailing whitespace introduced when no arguments are present
4141+ newInterpreterLine="$(echo "$newPath $args" | sed 's/[[:space:]]*$//')"
4242+4343+ if [ -n "$oldPath" -a "${oldPath:0:${#NIX_STORE}}" != "$NIX_STORE" ]; then
4444+ if [ -n "$newPath" -a "$newPath" != "$oldPath" ]; then
4545+ echo "$f: sage interpreter directive changed from \"$oldInterpreterLine\" to \"$newInterpreterLine\""
4646+ # escape the escape chars so that sed doesn't interpret them
4747+ escapedInterpreterLine=$(echo "$newInterpreterLine" | sed 's|\\|\\\\|g')
4848+ sed -i -e "1 s|.*|#\!$escapedInterpreterLine|" "$f"
4949+ fi
5050+ fi
5151+done