summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ci.nix1
-rw-r--r--examples/hello_world.nix3
-rw-r--r--examples/simple.nix6
-rw-r--r--pkgs/default.nix17
4 files changed, 27 insertions, 0 deletions
diff --git a/ci.nix b/ci.nix
index 545121e..902d43c 100644
--- a/ci.nix
+++ b/ci.nix
@@ -18,6 +18,7 @@ in
bash = writeTest "bash features" simples.bash;
dash = writeTest "dash features" simples.dash;
haskell = writeTest "Rolf" simples.haskell;
+ js = writeTest "function add(n,d){return n+d}" simples.js;
perl = writeTest "Howdy!" simples.perl;
python2 = writeTest "['some', 'random', 'variables']" simples.python2;
python3 = writeTest "['some', 'random', 'variables']" simples.python3;
diff --git a/examples/hello_world.nix b/examples/hello_world.nix
index 4944c13..4f9330a 100644
--- a/examples/hello_world.nix
+++ b/examples/hello_world.nix
@@ -18,6 +18,9 @@ in {
main = do
putStrLn "hello world"
'';
+ js = pkgs.writeJS "hello-world" {} ''
+ console.log("hello world")
+ '';
perl = pkgs.writePerl "hello-world" {} ''
print "hello world\n";
'';
diff --git a/examples/simple.nix b/examples/simple.nix
index 0284bf1..55ccedc 100644
--- a/examples/simple.nix
+++ b/examples/simple.nix
@@ -14,6 +14,12 @@ in {
main :: IO ()
main = print Rolf
'';
+ js = pkgs.writeJS "example-js" { deps = [ pkgs.nodePackages.uglify-js ]; } ''
+ var UglifyJS = require("uglify-js");
+ var code = "function add(first, second) { return first + second; }";
+ var result = UglifyJS.minify(code);
+ console.log(result.code);
+ '';
perl = pkgs.writePerl "simple.pl" { deps = [ pkgs.perlPackages.boolean ]; } ''
use boolean;
print "Howdy!\n" if true;
diff --git a/pkgs/default.nix b/pkgs/default.nix
index b7b0dde..10465a6 100644
--- a/pkgs/default.nix
+++ b/pkgs/default.nix
@@ -297,6 +297,23 @@ pkgs: oldpkgs: {
};
};
+ writeJS = name: { deps ? [] }: text:
+ let
+ node-env = pkgs.buildEnv {
+ name = "node";
+ paths = deps;
+ pathsToLink = [
+ "/lib/node_modules"
+ ];
+ };
+ in pkgs.writeDash name ''
+ export NODE_PATH=${node-env}/lib/node_modules
+ exec ${pkgs.nodejs}/bin/node ${pkgs.writeText "js" text}
+ '';
+
+ writeJSBin = name:
+ pkgs.writeJS "/bin/${name}";
+
writeJSON = name: value: pkgs.runCommand name {
json = toJSON value;
passAsFile = [ "json" ];