From a8c23ecd99800e0b185cb0346cee543ab906bff2 Mon Sep 17 00:00:00 2001 From: Dan Vargas Date: Sun, 6 Feb 2022 18:38:30 -0700 Subject: [PATCH] migrate rscript to nix --- packages/rscript/4.1.1/build.sh | 16 -------- packages/rscript/4.1.1/environment | 1 - packages/rscript/4.1.1/metadata.json | 5 --- packages/rscript/4.1.1/run | 2 - packages/rscript/4.1.1/test.r | 1 - runtimes/default.nix | 1 + runtimes/rscript.nix | 59 ++++++++++++++++++++++++++++ 7 files changed, 60 insertions(+), 25 deletions(-) delete mode 100755 packages/rscript/4.1.1/build.sh delete mode 100644 packages/rscript/4.1.1/environment delete mode 100644 packages/rscript/4.1.1/metadata.json delete mode 100644 packages/rscript/4.1.1/run delete mode 100644 packages/rscript/4.1.1/test.r create mode 100644 runtimes/rscript.nix diff --git a/packages/rscript/4.1.1/build.sh b/packages/rscript/4.1.1/build.sh deleted file mode 100755 index 9837c22..0000000 --- a/packages/rscript/4.1.1/build.sh +++ /dev/null @@ -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 diff --git a/packages/rscript/4.1.1/environment b/packages/rscript/4.1.1/environment deleted file mode 100644 index 977a5e8..0000000 --- a/packages/rscript/4.1.1/environment +++ /dev/null @@ -1 +0,0 @@ -export PATH=$PWD/bin:$PATH diff --git a/packages/rscript/4.1.1/metadata.json b/packages/rscript/4.1.1/metadata.json deleted file mode 100644 index db16a76..0000000 --- a/packages/rscript/4.1.1/metadata.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "language": "rscript", - "version": "4.1.1", - "aliases": ["r"] -} diff --git a/packages/rscript/4.1.1/run b/packages/rscript/4.1.1/run deleted file mode 100644 index d122eb8..0000000 --- a/packages/rscript/4.1.1/run +++ /dev/null @@ -1,2 +0,0 @@ -#/bin/bash -Rscript "$@" diff --git a/packages/rscript/4.1.1/test.r b/packages/rscript/4.1.1/test.r deleted file mode 100644 index 9273f27..0000000 --- a/packages/rscript/4.1.1/test.r +++ /dev/null @@ -1 +0,0 @@ -cat('OK') diff --git a/runtimes/default.nix b/runtimes/default.nix index 9e817a6..9aad700 100644 --- a/runtimes/default.nix +++ b/runtimes/default.nix @@ -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; } diff --git a/runtimes/rscript.nix b/runtimes/rscript.nix new file mode 100644 index 0000000..b1ae034 --- /dev/null +++ b/runtimes/rscript.nix @@ -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"; + }) + ]; +} \ No newline at end of file