Skip to content

Commit ea5d7b0

Browse files
author
Simon Guest
committed
Source-level packaging using a Nix flake
Enables running a defined version of KGD from the Nix store, which required a recent version of Rcpp with this bugfix: RcppCore/Rcpp#1346 For example usage see gbs_prism eri-dev branch.
1 parent 6bbe079 commit ea5d7b0

File tree

4 files changed

+174
-0
lines changed

4 files changed

+174
-0
lines changed

.envrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
*.$$$
2+
/.direnv/

flake.lock

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
{
2+
description = "Naive Nix packaging for KGD";
3+
inputs = {
4+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
5+
6+
flake-utils.url = "github:numtide/flake-utils";
7+
};
8+
9+
# KGD is not a first-class R package, merely a collection of R source files
10+
# to be source'd into the caller's environment.
11+
#
12+
# The Nix package enables these R sources to be used directly from the Nix store.
13+
14+
outputs = { self, nixpkgs, flake-utils }:
15+
flake-utils.lib.eachDefaultSystem
16+
(system:
17+
let
18+
pkgs = import nixpkgs {
19+
inherit system;
20+
};
21+
22+
# we need a recent Rcpp with this fix:
23+
# https://github.com/RcppCore/Rcpp/pull/1346
24+
recent-Rcpp = pkgs.rPackages.buildRPackage {
25+
name = "Rcpp";
26+
27+
version = "1.0.13.6";
28+
29+
src = pkgs.fetchFromGitHub {
30+
owner = "RcppCore";
31+
repo = "Rcpp";
32+
rev = "83e640b55aeaeba8a746d0da6152cabe8af41154";
33+
hash = "sha256-x0s9BRIAxxZmNFXRYwtpmT5asD4+mhIUTqwYsaPOgi4=";
34+
};
35+
};
36+
37+
# TODO: it should be possible to simply override the Rcpp dependency for RcppArmadillo in nixpkgs,
38+
# but I didn't work out how to do that
39+
RcppArmadillo-with-recent-Rcpp = pkgs.rPackages.buildRPackage {
40+
name = "RcppArmadillo";
41+
42+
version = "0.12.8.1.0";
43+
44+
src = pkgs.fetchFromGitHub {
45+
owner = "RcppCore";
46+
repo = "RcppArmadillo";
47+
rev = "8abe7be9fc4dd7c1d2b02ed200707232d6fd1f09"; # 0.12.8.1.0
48+
hash = "sha256-+Li4ln/4ZyBY+I8S8X4uSmFaG1D3q5UJOJJB5pLRubo=";
49+
};
50+
51+
propagatedBuildInputs = [ recent-Rcpp ];
52+
};
53+
54+
55+
KDG-R = pkgs.rWrapper.override
56+
{
57+
packages = with pkgs.rPackages; [
58+
RcppArmadillo-with-recent-Rcpp
59+
data_table
60+
R_utils
61+
plotly
62+
heatmaply
63+
parallelDist
64+
MethComp
65+
MASS
66+
];
67+
};
68+
69+
KDG-src = pkgs.stdenv.mkDerivation {
70+
pname = "KDG-src";
71+
version = "1.2.2";
72+
73+
src = ./.;
74+
75+
buildInputs = [ KDG-R ];
76+
77+
propagatedBuildInputs = [ KDG-R ];
78+
79+
nativeBuildInputs = [ pkgs.dos2unix ];
80+
81+
installPhase = ''
82+
mkdir $out
83+
runHook preInstall
84+
cp GBS-Chip-Gmatrix.R GBSPedAssign.R GBS-PopGen.R GBSRun.R GBS-Rcpp-functions.cpp $out
85+
chmod 755 $out/GBSRun.R
86+
dos2unix $out/*
87+
runHook postInstall
88+
'';
89+
90+
postFixup = ''
91+
substituteInPlace $out/GBSRun.R --replace '<source directory>' $out
92+
'';
93+
};
94+
in
95+
{
96+
devShells.default = pkgs.mkShell {
97+
buildInputs = [ KDG-R ];
98+
99+
shellHook = ''
100+
mkdir -p "$(pwd)/_libs"
101+
export R_LIBS_USER="$(pwd)/_libs"
102+
103+
export NIX_CFLAGS_COMPILE=" -isystem ${pkgs.rPackages.RcppArmadillo}/library/RcppArmadillo/include -isystem ${pkgs.rPackages.Rcpp}/library/Rcpp/include -isystem ${pkgs.R}/lib/R/include "
104+
'';
105+
};
106+
107+
packages = {
108+
src = KDG-src;
109+
};
110+
});
111+
}

0 commit comments

Comments
 (0)