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