Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ stdenv, lib, R, libcxx, xvfb-run, util-linux, Cocoa, Foundation, gettext, gfortran, libiconv }:
2
3{ name, buildInputs ? [], requireX ? false, ... } @ attrs:
4
5stdenv.mkDerivation ({
6 buildInputs = buildInputs ++ [R gettext] ++
7 lib.optionals requireX [util-linux xvfb-run] ++
8 lib.optionals stdenv.isDarwin [Cocoa Foundation gfortran libiconv];
9
10 env.NIX_CFLAGS_COMPILE =
11 lib.optionalString stdenv.isDarwin "-I${lib.getDev libcxx}/include/c++/v1";
12
13 configurePhase = ''
14 runHook preConfigure
15 export R_LIBS_SITE="$R_LIBS_SITE''${R_LIBS_SITE:+:}$out/library"
16 runHook postConfigure
17 '';
18
19 buildPhase = ''
20 runHook preBuild
21 runHook postBuild
22 '';
23
24 installFlags = if attrs.doCheck or true then
25 []
26 else
27 [ "--no-test-load" ];
28
29 rCommand = if requireX then
30 # Unfortunately, xvfb-run has a race condition even with -a option, so that
31 # we acquire a lock explicitly.
32 "flock ${xvfb-run} xvfb-run -a -e xvfb-error R"
33 else
34 "R";
35
36 installPhase = ''
37 runHook preInstall
38 mkdir -p $out/library
39 $rCommand CMD INSTALL --built-timestamp='1970-01-01 00:00:00 UTC' $installFlags --configure-args="$configureFlags" -l $out/library .
40 runHook postInstall
41 '';
42
43 postFixup = ''
44 if test -e $out/nix-support/propagated-build-inputs; then
45 ln -s $out/nix-support/propagated-build-inputs $out/nix-support/propagated-user-env-packages
46 fi
47 '';
48
49 checkPhase = ''
50 # noop since R CMD INSTALL tests packages
51 '';
52} // attrs // {
53 name = "r-" + name;
54})