migrate rscript to nix

This commit is contained in:
Dan Vargas 2022-02-06 18:38:30 -07:00
parent 2758f95228
commit a8c23ecd99
7 changed files with 60 additions and 25 deletions

View File

@ -1,16 +0,0 @@
#!/bin/bash
PREFIX=$(realpath $(dirname $0))
mkdir build
cd build
curl https://cloud.r-project.org/src/base/R-4/R-4.1.1.tar.gz -o R.tar.gz
tar xzf R.tar.gz --strip-components 1
./configure --prefix="$PREFIX" --with-x=no
make -j$(nproc)
make install -j$(nproc)
cd ../
rm -rf build

View File

@ -1 +0,0 @@
export PATH=$PWD/bin:$PATH

View File

@ -1,5 +0,0 @@
{
"language": "rscript",
"version": "4.1.1",
"aliases": ["r"]
}

View File

@ -1,2 +0,0 @@
#/bin/bash
Rscript "$@"

View File

@ -1 +0,0 @@
cat('OK')

View File

@ -20,4 +20,5 @@ args: {
"swift" = import ./swift.nix args;
"node-typescript" = import ./node-typescript.nix args;
"sqlite3" = import ./sqlite3.nix args;
"rscript" = import ./rscript.nix args;
}

59
runtimes/rscript.nix Normal file
View File

@ -0,0 +1,59 @@
{pkgs, piston, ...}:
let
pkg = pkgs.rWrapper;
in piston.mkRuntime {
language = "rscript";
version = "4.1.2-wrapper";
aliases = [
"r"
];
run = ''
${pkg}/bin/Rscript "$@"
'';
tests = [
# test different extension
(piston.mkTest {
files = {
"file.code" = ''
cat('OK')
'';
};
args = [];
stdin = "";
packages = [];
main = "file.code";
})
# test argv
(piston.mkTest {
files = {
"test.r" = ''
cat(commandArgs(trailingOnly=TRUE))
'';
};
args = ["OK"];
stdin = "";
packages = [];
main = "test.r";
})
# test stdin
(piston.mkTest {
files = {
"test.r" = ''
f <- file("stdin")
open(f)
while(length(line <- readLines(f,n=1)) > 0) {
write(line, stderr())
cat(line)
}
'';
};
args = [];
stdin = "OK";
packages = [];
main = "test.r";
})
];
}