1{
2 lib,
3 stdenv,
4 fetchurl,
5 bzip2,
6 gfortran,
7 libX11,
8 libXmu,
9 libXt,
10 libjpeg,
11 libpng,
12 libtiff,
13 ncurses,
14 pango,
15 pcre2,
16 perl,
17 readline,
18 tcl,
19 texlive,
20 texliveSmall,
21 tk,
22 xz,
23 zlib,
24 less,
25 texinfo,
26 graphviz,
27 icu,
28 pkg-config,
29 bison,
30 which,
31 jdk,
32 blas,
33 lapack,
34 curl,
35 tzdata,
36 withRecommendedPackages ? true,
37 enableStrictBarrier ? false,
38 enableMemoryProfiling ? false,
39 # R as of writing does not support outputting both .so and .a files; it outputs:
40 # --enable-R-static-lib conflicts with --enable-R-shlib and will be ignored
41 static ? false,
42 testers,
43}:
44
45assert (!blas.isILP64) && (!lapack.isILP64);
46
47stdenv.mkDerivation (finalAttrs: {
48 pname = "R";
49 version = "4.5.1";
50
51 src =
52 let
53 inherit (finalAttrs) pname version;
54 in
55 fetchurl {
56 url = "https://cran.r-project.org/src/base/R-${lib.versions.major version}/${pname}-${version}.tar.gz";
57 hash = "sha256-tCp5IUADhmRbEBBbkcaHKHh9tcTIPJ9sMKzc5jLhu3A=";
58 };
59
60 outputs = [
61 "out"
62 "tex"
63 ];
64
65 nativeBuildInputs = [
66 bison
67 perl
68 pkg-config
69 tzdata
70 which
71 ];
72 buildInputs = [
73 bzip2
74 gfortran
75 libX11
76 libXmu
77 libXt
78 libXt
79 libjpeg
80 libpng
81 libtiff
82 ncurses
83 pango
84 pcre2
85 readline
86 (texliveSmall.withPackages (
87 ps: with ps; [
88 inconsolata
89 helvetic
90 ps.texinfo
91 fancyvrb
92 cm-super
93 rsfs
94 ]
95 ))
96 xz
97 zlib
98 less
99 texinfo
100 graphviz
101 icu
102 which
103 blas
104 lapack
105 curl
106 tcl
107 tk
108 jdk
109 ];
110 strictDeps = true;
111
112 patches = [
113 ./no-usr-local-search-paths.patch
114 ];
115
116 # Test of the examples for package 'tcltk' fails in Darwin sandbox. See:
117 # https://github.com/NixOS/nixpkgs/issues/146131
118 postPatch = lib.optionalString stdenv.hostPlatform.isDarwin ''
119 substituteInPlace configure \
120 --replace "-install_name libRblas.dylib" "-install_name $out/lib/R/lib/libRblas.dylib" \
121 --replace "-install_name libRlapack.dylib" "-install_name $out/lib/R/lib/libRlapack.dylib" \
122 --replace "-install_name libR.dylib" "-install_name $out/lib/R/lib/libR.dylib"
123 substituteInPlace tests/Examples/Makefile.in \
124 --replace "test-Examples: test-Examples-Base" "test-Examples:" # do not test the examples
125 '';
126
127 dontDisableStatic = static;
128
129 preConfigure = ''
130 configureFlagsArray=(
131 --disable-lto
132 --with${lib.optionalString (!withRecommendedPackages) "out"}-recommended-packages
133 --with-blas="-L${blas}/lib -lblas"
134 --with-lapack="-L${lapack}/lib -llapack"
135 --with-readline
136 --with-tcltk --with-tcl-config="${tcl}/lib/tclConfig.sh" --with-tk-config="${tk}/lib/tkConfig.sh"
137 --with-cairo
138 --with-libpng
139 --with-jpeglib
140 --with-libtiff
141 --with-ICU
142 ${lib.optionalString enableStrictBarrier "--enable-strict-barrier"}
143 ${lib.optionalString enableMemoryProfiling "--enable-memory-profiling"}
144 ${if static then "--enable-R-static-lib" else "--enable-R-shlib"}
145 AR=$(type -p ar)
146 AWK=$(type -p gawk)
147 CC=$(type -p cc)
148 CXX=$(type -p c++)
149 FC="${gfortran}/bin/gfortran" F77="${gfortran}/bin/gfortran"
150 JAVA_HOME="${jdk}"
151 RANLIB=$(type -p ranlib)
152 CURL_CONFIG="${lib.getExe' (lib.getDev curl) "curl-config"}"
153 r_cv_have_curl728=yes
154 R_SHELL="${stdenv.shell}"
155 ''
156 + lib.optionalString stdenv.hostPlatform.isDarwin ''
157 --disable-R-framework
158 --without-x
159 OBJC="clang"
160 CPPFLAGS="-isystem ${lib.getInclude stdenv.cc.libcxx}/include/c++/v1"
161 LDFLAGS="-L${lib.getLib stdenv.cc.libcxx}/lib"
162 ''
163 + ''
164 )
165 echo >>etc/Renviron.in "TCLLIBPATH=${tk}/lib"
166 echo >>etc/Renviron.in "TZDIR=${tzdata}/share/zoneinfo"
167 '';
168
169 installTargets = [
170 "install"
171 "install-info"
172 "install-pdf"
173 ];
174
175 # move tex files to $tex for use with texlive.combine
176 # add link in $out since ${R_SHARE_DIR}/texmf is hardcoded in several places
177 postInstall = ''
178 mv -T "$out/lib/R/share/texmf" "$tex"
179 ln -s "$tex" "$out/lib/R/share/texmf"
180 '';
181
182 # The store path to "which" is baked into src/library/base/R/unix/system.unix.R,
183 # but Nix cannot detect it as a run-time dependency because the installed file
184 # is compiled and compressed, which hides the store path.
185 postFixup = ''
186 echo ${which} > $out/nix-support/undetected-runtime-dependencies
187 ${lib.optionalString stdenv.hostPlatform.isLinux ''find $out -name "*.so" -exec patchelf {} --add-rpath $out/lib/R/lib \;''}
188 '';
189
190 doCheck = true;
191 preCheck = "export HOME=$TMPDIR; export TZ=CET; bin/Rscript -e 'sessionInfo()'";
192
193 enableParallelBuilding = true;
194
195 setupHook = ./setup-hook.sh;
196
197 passthru.tests.pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage;
198
199 # make tex output available to texlive.combine
200 passthru.pkgs = [ finalAttrs.finalPackage.tex ];
201 passthru.tlType = "run";
202 # dependencies (based on \RequirePackage in jss.cls, Rd.sty, Sweave.sty)
203 passthru.tlDeps = with texlive; [
204 amsfonts
205 amsmath
206 fancyvrb
207 graphics
208 hyperref
209 iftex
210 jknapltx
211 latex
212 lm
213 tools
214 upquote
215 url
216 ];
217
218 meta = with lib; {
219 homepage = "http://www.r-project.org/";
220 description = "Free software environment for statistical computing and graphics";
221 license = licenses.gpl2Plus;
222
223 longDescription = ''
224 GNU R is a language and environment for statistical computing and
225 graphics that provides a wide variety of statistical (linear and
226 nonlinear modelling, classical statistical tests, time-series
227 analysis, classification, clustering, ...) and graphical
228 techniques, and is highly extensible. One of R's strengths is the
229 ease with which well-designed publication-quality plots can be
230 produced, including mathematical symbols and formulae where
231 needed. R is an integrated suite of software facilities for data
232 manipulation, calculation and graphical display. It includes an
233 effective data handling and storage facility, a suite of operators
234 for calculations on arrays, in particular matrices, a large,
235 coherent, integrated collection of intermediate tools for data
236 analysis, graphical facilities for data analysis and display
237 either on-screen or on hardcopy, and a well-developed, simple and
238 effective programming language which includes conditionals, loops,
239 user-defined recursive functions and input and output facilities.
240 '';
241
242 pkgConfigModules = [ "libR" ];
243 platforms = platforms.all;
244
245 maintainers = with maintainers; [ jbedo ];
246 teams = [ teams.sage ];
247 };
248})