nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 stdenv,
3 lib,
4 R,
5 xvfb-run,
6 util-linux,
7 gettext,
8 gfortran,
9 libiconv,
10}:
11
12{
13 buildInputs ? [ ],
14 requireX ? false,
15 ...
16}@attrs:
17
18stdenv.mkDerivation (
19 {
20 buildInputs =
21 buildInputs
22 ++ [
23 R
24 gettext
25 ]
26 ++ lib.optionals requireX [
27 util-linux
28 xvfb-run
29 ]
30 ++ lib.optionals stdenv.hostPlatform.isDarwin [
31 gfortran
32 libiconv
33 ];
34
35 env.NIX_CFLAGS_COMPILE = lib.optionalString stdenv.hostPlatform.isDarwin "-I${lib.getInclude stdenv.cc.libcxx}/include/c++/v1";
36
37 enableParallelBuilding = true;
38
39 configurePhase = ''
40 runHook preConfigure
41 export MAKEFLAGS+="''${enableParallelBuilding:+-j$NIX_BUILD_CORES}"
42 export R_LIBS_SITE="$R_LIBS_SITE''${R_LIBS_SITE:+:}$out/library"
43 runHook postConfigure
44 '';
45
46 buildPhase = ''
47 runHook preBuild
48 runHook postBuild
49 '';
50
51 installFlags = if attrs.doCheck or true then [ ] else [ "--no-test-load" ];
52
53 rCommand =
54 if requireX then
55 # Unfortunately, xvfb-run has a race condition even with -a option, so that
56 # we acquire a lock explicitly.
57 "flock ${xvfb-run} xvfb-run -a -e xvfb-error R"
58 else
59 "R";
60
61 installPhase = ''
62 runHook preInstall
63 mkdir -p $out/library
64 $rCommand CMD INSTALL --built-timestamp='1970-01-01 00:00:00 UTC' $installFlags --configure-args="$configureFlags" -l $out/library .
65 runHook postInstall
66 '';
67
68 postFixup = ''
69 if test -e $out/nix-support/propagated-build-inputs; then
70 ln -s $out/nix-support/propagated-build-inputs $out/nix-support/propagated-user-env-packages
71 fi
72 '';
73
74 checkPhase = ''
75 # noop since R CMD INSTALL tests packages
76 '';
77 }
78 // attrs
79 // {
80 name = "r-${attrs.name or "${attrs.pname}-${attrs.version}"}";
81 }
82)