-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathflake.nix
101 lines (89 loc) · 2.81 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
{
description = "smd R package";
nixConfig = {
bash-prompt = "smd> ";
};
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
flake-utils.url = "github:numtide/flake-utils";
gitignore = {
url = "github:hercules-ci/gitignore.nix";
# Use the same nixpkgs
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, flake-utils, gitignore }:
flake-utils.lib.eachDefaultSystem (system: let
package = "smd";
version = "0.7.0";
pkgs = nixpkgs.legacyPackages.${system};
inherit (gitignore.lib) gitignoreSource;
smdImports = with pkgs.rPackages; [
MASS
];
smdSuggests = with pkgs.rPackages; [
testthat
stddiff
tableone
knitr
dplyr
purrr
markdown
rmarkdown
];
in {
packages.${package} = pkgs.rPackages.buildRPackage {
name = "smd";
src = gitignoreSource ./.;
propagatedBuildInputs = smdImports;
};
# Run with
# nix build .#cran
packages.cran = pkgs.stdenv.mkDerivation {
name = "cran";
version = version;
src = gitignoreSource ./.;
buildInputs = [
pkgs.R
pkgs.pandoc
pkgs.rPackages.devtools
pkgs.qpdf
pkgs.texlive.combined.scheme-full
] ++ smdSuggests ++ smdImports ;
doCheck = true;
buildPhase = ''
${pkgs.R}/bin/Rscript -e 'devtools::document()'
${pkgs.R}/bin/R CMD build .
'';
# NOTE:
# Not all checks will pass because R CMD check does stuff
# This one gives warning:
# * checking R files for syntax errors ... WARNING
# OS reports request to set locale to "en_US.UTF-8" cannot be honored
# I don't know how to set the locale in a derivation
# (or if that's even possible)
# Others are notes (e.g.):
# * Found the following (possibly) invalid URLs:
# R CMD check wants to access the interwebs but nix no like that.
checkPhase = ''
${pkgs.R}/bin/R CMD check $(ls -t . | head -n1) --as-cran
'';
installPhase = ''
mkdir -p $out
cp ${package}_${version}.tar.gz $out
cp -r ${package}.Rcheck/ $out/logs
'';
};
packages.default = self.packages.${system}.${package};
devShells.default = pkgs.mkShell {
nativeBuildInputs = [ pkgs.bashInteractive ];
buildInputs = [
pkgs.R
pkgs.rPackages.devtools
pkgs.rPackages.usethis
pkgs.rPackages.styler
pkgs.rPackages.lintr
] ++ smdImports ++ smdSuggests ;
};
});
}