nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 stdenv,
3 lib,
4 sage-env,
5 blas,
6 lapack,
7 pkg-config,
8 three,
9 singular,
10 gap,
11 giac,
12 maxima,
13 pari,
14 gmp,
15 gfan,
16 python3,
17 eclib,
18 ntl,
19 ecm,
20 pythonEnv,
21}:
22
23# lots of segfaults with (64 bit) blas
24assert (!blas.isILP64) && (!lapack.isILP64);
25
26# Wrapper that combined `sagelib` with `sage-env` to produce an actually
27# executable sage. No tests are run yet and no documentation is built.
28
29let
30 nativeBuildInputs = [ pkg-config ];
31 buildInputs = [
32 pythonEnv # for patchShebangs
33 blas
34 lapack
35 singular
36 three
37 giac
38 gap
39 pari
40 gmp
41 gfan
42 maxima
43 eclib
44 ntl
45 ecm
46 ];
47
48 # remove python prefix, replace "-" in the name by "_", apply patch_names
49 # python3.8-some-pkg-1.0 -> some_pkg-1.0
50 pkg_to_spkg_name =
51 pkg: patch_names:
52 let
53 parts = lib.splitString "-" pkg.name;
54 # remove python3.8-
55 stripped_parts = if (builtins.head parts) == python3.libPrefix then builtins.tail parts else parts;
56 version = lib.last stripped_parts;
57 orig_pkgname = lib.init stripped_parts;
58 pkgname = patch_names (lib.concatStringsSep "_" orig_pkgname);
59 in
60 pkgname + "-" + version;
61
62 # return the names of all dependencies in the transitive closure
63 transitiveClosure =
64 dep:
65 if dep == null then
66 # propagatedBuildInputs might contain null
67 # (although that might be considered a programming error in the derivation)
68 [ ]
69 else
70 [ dep ]
71 ++ (
72 if builtins.hasAttr "propagatedBuildInputs" dep then
73 lib.unique (builtins.concatLists (map transitiveClosure dep.propagatedBuildInputs))
74 else
75 [ ]
76 );
77
78 allInputs = lib.remove null (nativeBuildInputs ++ buildInputs ++ pythonEnv.extraLibs);
79 transitiveDeps = lib.unique (builtins.concatLists (map transitiveClosure allInputs));
80 # fix differences between spkg and sage names
81 # (could patch sage instead, but this is more lightweight and also works for packages depending on sage)
82 patch_names =
83 builtins.replaceStrings
84 [
85 "zope.interface"
86 "node_three"
87 ]
88 [
89 "zope-interface"
90 "threejs"
91 ];
92 # spkg names (this_is_a_package-version) of all transitive deps
93 input_names = map (dep: pkg_to_spkg_name dep patch_names) transitiveDeps;
94in
95stdenv.mkDerivation rec {
96 version = src.version;
97 pname = "sage-with-env";
98 src = sage-env.lib.src;
99
100 inherit nativeBuildInputs buildInputs;
101
102 configurePhase = "#do nothing";
103
104 buildPhase = ''
105 mkdir installed
106 for pkg in ${lib.concatStringsSep " " input_names}; do
107 touch "installed/$pkg"
108 done
109
110 # threejs version is in format 0.<version>.minor, but sage currently still
111 # relies on installed_packages for the online version of threejs to work
112 # and expects the format r<version>. This is a hotfix for now.
113 # upstream: https://trac.sagemath.org/ticket/26434
114 rm "installed/threejs"*
115 touch "installed/threejs-r${lib.versions.minor three.version}"
116 '';
117
118 installPhase = ''
119 mkdir -p "$out/var/lib/sage"
120 cp -r installed "$out/var/lib/sage"
121
122 mkdir -p "$out/etc"
123 # sage tests will try to create this file if it doesn't exist
124 touch "$out/etc/sage-started.txt"
125
126 mkdir -p "$out/build"
127
128 # the scripts in src/bin will find the actual sage source files using environment variables set in `sage-env`
129 cp -r src/bin "$out/bin"
130 cp -r build/bin "$out/build/bin"
131
132 # sage assumes the existence of sage-src-env-config.in means it's being executed in-tree. in this case, it
133 # adds SAGE_SRC/bin to PATH, breaking our wrappers
134 rm "$out/bin"/*.in "$out/build/bin"/*.in
135
136 cp -f '${sage-env}/sage-env' "$out/bin/sage-env"
137 substituteInPlace "$out/bin/sage-env" \
138 --subst-var-by sage-local "$out"
139 '';
140
141 passthru = {
142 env = sage-env;
143 };
144}