Skip to content

Commit 007ce6e

Browse files
author
Simon Guest
committed
Initial Nix flake using fork of Rcpp for bugfix
Bug in Rcpp blocked using readonly CPP source from Nix store, fixed in this PR, awaiting merge. RcppCore/Rcpp#1346
1 parent 6bbe079 commit 007ce6e

File tree

4 files changed

+170
-0
lines changed

4 files changed

+170
-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: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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+
# TODO use the main Rcpp repo once this PR is merged:
23+
# https://github.com/RcppCore/Rcpp/pull/1346
24+
Rcpp-tesujimath = pkgs.rPackages.buildRPackage {
25+
name = "Rcpp";
26+
27+
src = pkgs.fetchFromGitHub {
28+
owner = "tesujimath";
29+
repo = "Rcpp";
30+
rev = "readonly-file-io-error";
31+
hash = "sha256-yJcOwOxgy6VMgNa0RBCgWH45iViqHO/RcrZUIaeLON0=";
32+
};
33+
};
34+
35+
# TODO: it should be possible to simply override the Rcpp dependency for RcppArmadillo in nixpkgs,
36+
# but I didn't work out how to do that
37+
RcppArmadillo-with-Rcpp-tesujimath = pkgs.rPackages.buildRPackage {
38+
name = "RcppArmadillo";
39+
40+
version = "0.12.8.1.0";
41+
42+
src = pkgs.fetchFromGitHub {
43+
owner = "RcppCore";
44+
repo = "RcppArmadillo";
45+
rev = "8abe7be9fc4dd7c1d2b02ed200707232d6fd1f09"; # 0.12.8.1.0
46+
hash = "sha256-+Li4ln/4ZyBY+I8S8X4uSmFaG1D3q5UJOJJB5pLRubo=";
47+
};
48+
49+
propagatedBuildInputs = [ Rcpp-tesujimath ];
50+
};
51+
52+
53+
KDG-R = pkgs:
54+
pkgs.rWrapper.override {
55+
packages = with pkgs.rPackages;
56+
[
57+
# languageserver # - for devshell only
58+
RcppArmadillo-with-Rcpp-tesujimath
59+
];
60+
};
61+
62+
KDG-src =
63+
with pkgs;
64+
stdenv.mkDerivation {
65+
pname = "KDG-src";
66+
version = "1.2.2";
67+
68+
src = ./.;
69+
70+
nativeBuildInputs = [ dos2unix ];
71+
72+
installPhase = ''
73+
mkdir $out
74+
runHook preInstall
75+
cp GBS-Chip-Gmatrix.R GBSPedAssign.R GBS-PopGen.R GBSRun.R GBS-Rcpp-functions.cpp $out
76+
chmod 755 $out/GBSRun.R
77+
dos2unix $out/*
78+
runHook postInstall
79+
'';
80+
81+
postFixup = ''
82+
substituteInPlace $out/GBSRun.R --replace '<source directory>' $out
83+
'';
84+
};
85+
86+
KDG-dependencies = pkgs: [
87+
(KDG-R pkgs)
88+
];
89+
in
90+
{
91+
devShells.default = pkgs.mkShell {
92+
buildInputs = (KDG-dependencies pkgs);
93+
94+
shellHook = ''
95+
mkdir -p "$(pwd)/_libs"
96+
export R_LIBS_USER="$(pwd)/_libs"
97+
98+
export NIX_CFLAGS_COMPILE=" -isystem ${pkgs.rPackages.RcppArmadillo}/library/RcppArmadillo/include -isystem ${pkgs.rPackages.Rcpp}/library/Rcpp/include -isystem ${pkgs.R}/lib/R/include "
99+
'';
100+
};
101+
102+
packages = {
103+
src = KDG-src;
104+
dependencies = KDG-dependencies;
105+
};
106+
});
107+
}

0 commit comments

Comments
 (0)