1 { lib, stdenv, fetchurl, bzip2, gfortran, libX11, libXmu, libXt, libjpeg, libpng
2 , libtiff, ncurses, pango, pcre2, perl, readline, tcl, texlive, texliveSmall, tk, xz, zlib
3 , less, texinfo, graphviz, icu, pkg-config, bison, imake, which, jdk, blas, lapack
4 , curl, Cocoa, Foundation, libobjc, libcxx, tzdata
5 , withRecommendedPackages ? true
6 , enableStrictBarrier ? false
7 , enableMemoryProfiling ? false
8 # R as of writing does not support outputting both .so and .a files; it outputs:
9 # --enable-R-static-lib conflicts with --enable-R-shlib and will be ignored
14 assert (!blas.isILP64) && (!lapack.isILP64);
16 stdenv.mkDerivation (finalAttrs: {
21 inherit (finalAttrs) pname version;
23 url = "https://cran.r-project.org/src/base/R-${lib.versions.major version}/${pname}-${version}.tar.gz";
24 sha256 = "sha256-FXjNYD6NhmtYdD5J2L+ZxWnoEHm2pgzzPN973/64F+w=";
27 outputs = [ "out" "tex" ];
29 dontUseImakeConfigure = true;
31 nativeBuildInputs = [ pkg-config ];
33 bzip2 gfortran libX11 libXmu libXt libXt libjpeg libpng libtiff ncurses
34 pango pcre2 perl readline (texliveSmall.withPackages (ps: with ps; [ inconsolata helvetic ps.texinfo fancyvrb cm-super rsfs ])) xz zlib less texinfo graphviz icu
35 bison imake which blas lapack curl tcl tk jdk tzdata
36 ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ Cocoa Foundation libobjc libcxx ];
39 ./no-usr-local-search-paths.patch
42 # Test of the examples for package 'tcltk' fails in Darwin sandbox. See:
43 # https://github.com/NixOS/nixpkgs/issues/146131
44 postPatch = lib.optionalString stdenv.hostPlatform.isDarwin ''
45 substituteInPlace configure \
46 --replace "-install_name libRblas.dylib" "-install_name $out/lib/R/lib/libRblas.dylib" \
47 --replace "-install_name libRlapack.dylib" "-install_name $out/lib/R/lib/libRlapack.dylib" \
48 --replace "-install_name libR.dylib" "-install_name $out/lib/R/lib/libR.dylib"
49 substituteInPlace tests/Examples/Makefile.in \
50 --replace "test-Examples: test-Examples-Base" "test-Examples:" # do not test the examples
53 dontDisableStatic = static;
58 --with${lib.optionalString (!withRecommendedPackages) "out"}-recommended-packages
59 --with-blas="-L${blas}/lib -lblas"
60 --with-lapack="-L${lapack}/lib -llapack"
62 --with-tcltk --with-tcl-config="${tcl}/lib/tclConfig.sh" --with-tk-config="${tk}/lib/tkConfig.sh"
68 ${lib.optionalString enableStrictBarrier "--enable-strict-barrier"}
69 ${lib.optionalString enableMemoryProfiling "--enable-memory-profiling"}
70 ${if static then "--enable-R-static-lib" else "--enable-R-shlib"}
75 FC="${gfortran}/bin/gfortran" F77="${gfortran}/bin/gfortran"
77 RANLIB=$(type -p ranlib)
79 R_SHELL="${stdenv.shell}"
80 '' + lib.optionalString stdenv.hostPlatform.isDarwin ''
84 CPPFLAGS="-isystem ${lib.getDev libcxx}/include/c++/v1"
85 LDFLAGS="-L${lib.getLib libcxx}/lib"
88 echo >>etc/Renviron.in "TCLLIBPATH=${tk}/lib"
89 echo >>etc/Renviron.in "TZDIR=${tzdata}/share/zoneinfo"
92 installTargets = [ "install" "install-info" "install-pdf" ];
94 # move tex files to $tex for use with texlive.combine
95 # add link in $out since ${R_SHARE_DIR}/texmf is hardcoded in several places
97 mv -T "$out/lib/R/share/texmf" "$tex"
98 ln -s "$tex" "$out/lib/R/share/texmf"
101 # The store path to "which" is baked into src/library/base/R/unix/system.unix.R,
102 # but Nix cannot detect it as a run-time dependency because the installed file
103 # is compiled and compressed, which hides the store path.
105 echo ${which} > $out/nix-support/undetected-runtime-dependencies
106 ${lib.optionalString stdenv.hostPlatform.isLinux ''find $out -name "*.so" -exec patchelf {} --add-rpath $out/lib/R/lib \;''}
110 preCheck = "export HOME=$TMPDIR; export TZ=CET; bin/Rscript -e 'sessionInfo()'";
112 enableParallelBuilding = true;
114 setupHook = ./setup-hook.sh;
116 passthru.tests.pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage;
118 # make tex output available to texlive.combine
119 passthru.pkgs = [ finalAttrs.finalPackage.tex ];
120 passthru.tlType = "run";
121 # dependencies (based on \RequirePackage in jss.cls, Rd.sty, Sweave.sty)
122 passthru.tlDeps = with texlive; [ amsfonts amsmath fancyvrb graphics hyperref iftex jknapltx latex lm tools upquote url ];
125 homepage = "http://www.r-project.org/";
126 description = "Free software environment for statistical computing and graphics";
127 license = licenses.gpl2Plus;
130 GNU R is a language and environment for statistical computing and
131 graphics that provides a wide variety of statistical (linear and
132 nonlinear modelling, classical statistical tests, time-series
133 analysis, classification, clustering, ...) and graphical
134 techniques, and is highly extensible. One of R's strengths is the
135 ease with which well-designed publication-quality plots can be
136 produced, including mathematical symbols and formulae where
137 needed. R is an integrated suite of software facilities for data
138 manipulation, calculation and graphical display. It includes an
139 effective data handling and storage facility, a suite of operators
140 for calculations on arrays, in particular matrices, a large,
141 coherent, integrated collection of intermediate tools for data
142 analysis, graphical facilities for data analysis and display
143 either on-screen or on hardcopy, and a well-developed, simple and
144 effective programming language which includes conditionals, loops,
145 user-defined recursive functions and input and output facilities.
148 pkgConfigModules = [ "libR" ];
149 platforms = platforms.all;
151 maintainers = with maintainers; [ jbedo ] ++ teams.sage.members;