1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
{ stdenv
, lib
, writeTextFile
, sagelib
, sage-docbuild
, env-locations
, gfortran
, bash
, coreutils
, gnused
, gnugrep
, binutils
, pythonEnv
, python3
, pkg-config
, pari
, gap
, maxima
, singular
, fflas-ffpack
, givaro
, gd
, libpng
, linbox
, m4ri
, giac
, palp
, rWrapper
, gfan
, cddlib
, jmol
, tachyon
, glpk
, eclib
, sympow
, nauty
, sqlite
, ppl
, ecm
, lcalc
, rubiks
, flintqs
, blas
, lapack
, flint3
, gmp
, mpfr
, zlib
, gsl
, ntl
, jdk
, less
}:
assert (!blas.isILP64) && (!lapack.isILP64);
# This generates a `sage-env` shell file that will be sourced by sage on startup.
# It sets up various environment variables, telling sage where to find its
# dependencies.
let
runtimepath = (lib.makeBinPath ([
"@sage-local@"
"@sage-local@/build"
pythonEnv
gfortran # for inline fortran
stdenv.cc # for cython
bash
coreutils
gnused
gnugrep
binutils.bintools
pkg-config
pari
gap
maxima.lisp-compiler
maxima
singular
giac
palp
# needs to be rWrapper since the default `R` doesn't include R's default libraries
rWrapper
gfan
cddlib
jmol
tachyon
glpk
eclib
sympow
nauty
sqlite
ppl
ecm
lcalc
rubiks
flintqs
jdk # only needed for `jmol` which may be replaced in the future
less # needed to prevent transient test errors until https://github.com/ipython/ipython/pull/11864 is resolved
]
));
in
writeTextFile rec {
name = "sage-env";
destination = "/${name}";
text = ''
export PKG_CONFIG_PATH='${lib.makeSearchPathOutput "dev" "lib/pkgconfig" [
# This should only be needed during build. However, since the doctests
# also test the cython build (for example in src/sage/misc/cython.py),
# it is also needed for the testsuite to pass. We could fix the
# testsuite instead, but since all the packages are also runtime
# dependencies it doesn't really hurt to include them here.
singular
blas lapack
fflas-ffpack givaro
gd
libpng zlib
gsl
linbox
m4ri
]
}'
export SAGE_ROOT='${sagelib.src}'
'' +
# TODO: is using pythonEnv instead of @sage-local@ here a good
# idea? there is a test in src/sage/env.py that checks if the values
# SAGE_ROOT and SAGE_LOCAL set here match the ones set in env.py.
# we fix up env.py's SAGE_ROOT in sage-src.nix (which does not
# have access to sage-with-env), but env.py autodetects
# SAGE_LOCAL to be pythonEnv.
# setting SAGE_LOCAL to pythonEnv also avoids having to create
# python3, ipython, ipython3 and jupyter symlinks in
# sage-with-env.nix.
''
export SAGE_LOCAL='${pythonEnv}'
export SAGE_SHARE='${sagelib}/share'
export SAGE_ENV_CONFIG_SOURCED=1 # sage-env complains if sage-env-config is not sourced beforehand
orig_path="$PATH"
export PATH='${runtimepath}'
# set dependent vars, like JUPYTER_CONFIG_DIR
source "${sagelib.src}/src/bin/sage-env"
export PATH="$RUNTIMEPATH_PREFIX:${runtimepath}:$orig_path" # sage-env messes with PATH
export SAGE_LOGS="$TMPDIR/sage-logs"
export SAGE_DOC="''${SAGE_DOC_OVERRIDE:-doc-placeholder}"
export SAGE_DOC_SRC="''${SAGE_DOC_SRC_OVERRIDE:-${sagelib.src}/src/doc}"
# set locations of dependencies
. ${env-locations}/sage-env-locations
# needed for cython
export CC='${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc'
export CXX='${stdenv.cc}/bin/${stdenv.cc.targetPrefix}c++'
# cython needs to find these libraries, otherwise will fail with `ld: cannot find -lflint` or similar
export LDFLAGS='${
lib.concatStringsSep " " (map (pkg: "-L${pkg}/lib") [
flint3
gap
glpk
gmp
mpfr
pari
zlib
eclib
gsl
ntl
jmol
sympow
])
}'
export CFLAGS='${
lib.concatStringsSep " " (map (pkg: "-isystem ${pkg}/include") [
singular
gmp.dev
glpk
flint3
gap
mpfr.dev
])
}'
export CXXFLAGS=$CFLAGS
export SAGE_LIB='${sagelib}/${python3.sitePackages}'
export SAGE_EXTCODE='${sagelib.src}/src/sage/ext_data'
# for find_library
export DYLD_LIBRARY_PATH="${lib.makeLibraryPath [stdenv.cc.libc singular giac]}''${DYLD_LIBRARY_PATH:+:}$DYLD_LIBRARY_PATH"
'';
} // { # equivalent of `passthru`, which `writeTextFile` doesn't support
lib = sagelib;
docbuild = sage-docbuild;
}
|