lol
1{ stdenv, R, xvfb_run, utillinux }:
2
3{ name, buildInputs ? [], ... } @ attrs:
4
5stdenv.mkDerivation ({
6 buildInputs = buildInputs ++ [R] ++
7 stdenv.lib.optionals attrs.requireX [utillinux xvfb_run];
8
9 configurePhase = ''
10 runHook preConfigure
11 export R_LIBS_SITE="$R_LIBS_SITE''${R_LIBS_SITE:+:}$out/library"
12 runHook postConfigure
13 '';
14
15 buildPhase = ''
16 runHook preBuild
17 runHook postBuild
18 '';
19
20 installFlags = if attrs.doCheck or true then
21 []
22 else
23 [ "--no-test-load" ];
24
25 rCommand = if attrs.requireX or false then
26 # Unfortunately, xvfb-run has a race condition even with -a option, so that
27 # we acquire a lock explicitly.
28 "flock ${xvfb_run} xvfb-run -a -e xvfb-error R"
29 else
30 "R";
31
32 installPhase = ''
33 runHook preInstall
34 mkdir -p $out/library
35 $rCommand CMD INSTALL $installFlags --configure-args="$configureFlags" -l $out/library .
36 runHook postInstall
37 '';
38
39 postFixup = ''
40 if test -e $out/nix-support/propagated-native-build-inputs; then
41 ln -s $out/nix-support/propagated-native-build-inputs $out/nix-support/propagated-user-env-packages
42 fi
43 '';
44
45 checkPhase = ''
46 # noop since R CMD INSTALL tests packages
47 '';
48} // attrs // {
49 name = "r-" + name;
50})