···18# - https://git.archlinux.org/svntogit/community.git/tree/trunk?h=packages/sagemath
1920{ stdenv
021, fetchurl
22, perl
23, gfortran
···26, gettext
27, which
28, texlive
029, hevea
30}:
3132stdenv.mkDerivation rec {
33- version = "8.0";
34 name = "sage-${version}";
3500036 src = fetchurl {
37 # Note that the source is *not* fetched from github, since that doesn't
38 # the upstream folder with all the source tarballs of the spkgs.
···70 "http://www-ftp.lip6.fr/pub/math/sagemath/src/sage-${version}.tar.gz"
71 "http://ftp.ntua.gr/pub/sagemath/src/sage-${version}.tar.gz"
72 ];
73- sha256 = "1a9rhb8jby6fdqa2s7n2fl9jwqqlsl7qz7dbpbwvg6jwlrvni7fg";
74 };
7576 postPatch = ''
77 substituteAllInPlace src/bin/sage-env
078 '';
7980 installPhase = ''
···84 outputs = [ "out" "doc" ];
8586 buildInputs = [
087 perl # needed for the build
88 python # needed for the build
89- gfortran # needed to build giac
90 autoreconfHook # needed to configure sage with prefix
91 gettext # needed to build the singular spkg
92 hevea # needed to build the docs of the giac spkg
93 which # needed in configure of mpir
94 # needed to build the docs of the giac spkg
095 (texlive.combine { inherit (texlive)
96 scheme-basic
97 collection-pstricks # needed by giac
···102 })
103 ];
10400105 patches = [
106 # fix usages of /bin/rm
107 ./spkg-singular.patch
108 # help python find the crypt library
109- ./spkg-python2.patch
110- ./spkg-python3.patch
111 # fix usages of /usr/bin/perl
112 ./spkg-git.patch
113 # fix usages of /bin/cp and add necessary argument to function call
114 ./spkg-giac.patch
115 # environment
116 ./env.patch
00117 ];
118119 enableParallelBuilding = true;
···144 preBuild = ''
145 # TODO do this conditionally
146 export SAGE_SPKG_INSTALL_DOCS='no'
147- patchShebangs build
0000000148 '';
149150 postBuild = ''
···153 rm -rf "$out/sage-root/src/.git"
154 rm -r "$out/sage-root/logs"
155 # Fix dependency cycle between out and doc
0156 rm -f "$out/sage-root/config.status"
157 rm -f "$out/sage-root/build/make/Makefile-auto"
158 rm -f "$out/sage-home/.sage/gap/libgap-workspace-"*
00159 '';
160161 # TODO there are some doctest failures, which seem harmless.
···18# - https://git.archlinux.org/svntogit/community.git/tree/trunk?h=packages/sagemath
1920{ stdenv
21+, bash
22, fetchurl
23, perl
24, gfortran
···27, gettext
28, which
29, texlive
30+, texinfo
31, hevea
32}:
3334stdenv.mkDerivation rec {
35+ version = "8.1";
36 name = "sage-${version}";
3738+ # Modified version of patchShebangs that patches to the sage-internal version if possible
39+ # and falls back to the system version if not.
40+ patchSageShebangs = ./patchSageShebangs.sh;
41 src = fetchurl {
42 # Note that the source is *not* fetched from github, since that doesn't
43 # the upstream folder with all the source tarballs of the spkgs.
···75 "http://www-ftp.lip6.fr/pub/math/sagemath/src/sage-${version}.tar.gz"
76 "http://ftp.ntua.gr/pub/sagemath/src/sage-${version}.tar.gz"
77 ];
78+ sha256 = "1cpcs1mr0yii64s152xmxyd450bfzjb22jjj0zh9y3n6g9alzpyq";
79 };
8081 postPatch = ''
82 substituteAllInPlace src/bin/sage-env
83+ bash=${bash} substituteAllInPlace build/bin/sage-spkg
84 '';
8586 installPhase = ''
···90 outputs = [ "out" "doc" ];
9192 buildInputs = [
93+ bash # needed for the build
94 perl # needed for the build
95 python # needed for the build
96+ gfortran # needed to build giac, openblas
97 autoreconfHook # needed to configure sage with prefix
98 gettext # needed to build the singular spkg
99 hevea # needed to build the docs of the giac spkg
100 which # needed in configure of mpir
101 # needed to build the docs of the giac spkg
102+ texinfo # needed to build maxima
103 (texlive.combine { inherit (texlive)
104 scheme-basic
105 collection-pstricks # needed by giac
···110 })
111 ];
112113+ nativeBuildInputs = [ gfortran perl which ];
114+115 patches = [
116 # fix usages of /bin/rm
117 ./spkg-singular.patch
118 # help python find the crypt library
119+ # patches python3 and indirectly python2, since those installation files are symlinked
120+ ./spkg-python.patch
121 # fix usages of /usr/bin/perl
122 ./spkg-git.patch
123 # fix usages of /bin/cp and add necessary argument to function call
124 ./spkg-giac.patch
125 # environment
126 ./env.patch
127+ # adjust wrapper shebang and patch shebangs after each spkg build
128+ ./shebangs.patch
129 ];
130131 enableParallelBuilding = true;
···156 preBuild = ''
157 # TODO do this conditionally
158 export SAGE_SPKG_INSTALL_DOCS='no'
159+ # symlink python to make sure the shebangs are patched to the sage path
160+ # while still being able to use python before building it
161+ # (this is important because otherwise sage will try to install python
162+ # packages globally later on)
163+ ln -s "${python}/bin/python2" $out/bin/python2
164+ ln -s "$out/bin/python2" $out/bin/python
165+ touch $out/bin/python3
166+ bash $patchSageShebangs .
167 '';
168169 postBuild = ''
···172 rm -rf "$out/sage-root/src/.git"
173 rm -r "$out/sage-root/logs"
174 # Fix dependency cycle between out and doc
175+ rm -f "$out/sage-root/config.log"
176 rm -f "$out/sage-root/config.status"
177 rm -f "$out/sage-root/build/make/Makefile-auto"
178 rm -f "$out/sage-home/.sage/gap/libgap-workspace-"*
179+ # Make sure all shebangs are properly patched
180+ bash $patchSageShebangs $out
181 '';
182183 # TODO there are some doctest failures, which seem harmless.
···1+# This is a slightly modified version of nix's default patchShebangs
2+3+dir="$1"
4+5+echo "patching sage internal script interpreter paths in $( readlink -f "$dir")"
6+7+find "$dir" -type f -perm -0100 | while read f; do
8+ if [ "$(head -1 "$f" | head -c+2)" != '#!' ]; then
9+ # missing shebang => not a script
10+ continue
11+ fi
12+13+ oldInterpreterLine=$(head -1 "$f" | tail -c+3)
14+ read -r oldPath arg0 args <<< "$oldInterpreterLine"
15+16+ if $(echo "$oldPath" | grep -q "/bin/env$"); then
17+ # Check for unsupported 'env' functionality:
18+ # - options: something starting with a '-'
19+ # - environment variables: foo=bar
20+ if $(echo "$arg0" | grep -q -- "^-.*\|.*=.*"); then
21+ echo "unsupported interpreter directive \"$oldInterpreterLine\" (set dontPatchShebangs=1 and handle shebang patching yourself)"
22+ exit 1
23+ fi
24+ executable="$arg0"
25+ else
26+ if [ "$oldPath" = "" ]; then
27+ # If no interpreter is specified linux will use /bin/sh. Set
28+ # oldpath="/bin/sh" so that we get /nix/store/.../sh.
29+ oldPath="/bin/sh"
30+ fi
31+ executable="$(basename "$oldPath")"
32+ args="$arg0 $args"
33+ fi
34+35+ newPath="$(echo "$out/bin/$executable $args" | sed 's/[[:space:]]*$//')"
36+ if [[ ! -x "$newPath" ]] ; then
37+ newPath="$(command -v "$executable" || true)"
38+ fi
39+40+ # Strip trailing whitespace introduced when no arguments are present
41+ newInterpreterLine="$(echo "$newPath $args" | sed 's/[[:space:]]*$//')"
42+43+ if [ -n "$oldPath" -a "${oldPath:0:${#NIX_STORE}}" != "$NIX_STORE" ]; then
44+ if [ -n "$newPath" -a "$newPath" != "$oldPath" ]; then
45+ echo "$f: sage interpreter directive changed from \"$oldInterpreterLine\" to \"$newInterpreterLine\""
46+ # escape the escape chars so that sed doesn't interpret them
47+ escapedInterpreterLine=$(echo "$newInterpreterLine" | sed 's|\\|\\\\|g')
48+ sed -i -e "1 s|.*|#\!$escapedInterpreterLine|" "$f"
49+ fi
50+ fi
51+done