diff options
author | tv <tv@krebsco.de> | 2018-09-25 20:38:14 +0200 |
---|---|---|
committer | tv <tv@krebsco.de> | 2018-09-25 20:38:14 +0200 |
commit | 0660cc1a1169e799bda356c6fadb245a96345816 (patch) | |
tree | 74e5443bd152333b50c2d5619926eb31b69513ec | |
parent | c27a9416e8ee04d708b11b48f8cf1a055c0cc079 (diff) | |
parent | 79ab2c27f9d7903ff3ed9bcd8de493b1191bbc12 (diff) |
Merge remote-tracking branch 'lass/master'
-rw-r--r-- | ci.nix | 27 | ||||
-rw-r--r-- | examples/hello_world.nix | 36 | ||||
-rw-r--r-- | examples/simple.nix | 48 | ||||
-rw-r--r-- | pkgs/default.nix | 34 |
4 files changed, 145 insertions, 0 deletions
@@ -0,0 +1,27 @@ +let + pkgs = import <nixpkgs> {}; + + hello_worlds = import examples/hello_world.nix; + simples = import examples/simple.nix; + + writeTest = expectedValue: test: pkgs.writeScript "test" '' + #!/bin/sh + if test "$(${test})" != "${expectedValue}"; then + echo 'test ${test} failed' + exit 1 + fi + ''; + +in + pkgs.lib.mapAttrs' (n: v: pkgs.lib.nameValuePair "hello_${n}" (writeTest "hello world" v)) hello_worlds // + pkgs.lib.mapAttrs' (n: v: pkgs.lib.nameValuePair "simple_${n}" v) { + 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; + sed = writeTest "hello world" simples.sed; + } + diff --git a/examples/hello_world.nix b/examples/hello_world.nix new file mode 100644 index 0000000..4f9330a --- /dev/null +++ b/examples/hello_world.nix @@ -0,0 +1,36 @@ +let + pkgs = import <nixpkgs> { overlays = [ (import ../pkgs) ]; }; +in { + bash = pkgs.writeBash "hello-world" '' + echo 'hello world' + ''; + c = pkgs.writeC "hello-world" {} '' + #include <stdio.h> + int main() { + printf("hello world\n"); + return 0; + } + ''; + dash = pkgs.writeDash "hello-world" '' + echo 'hello world' + ''; + haskell = pkgs.writeHaskell "hello-world" [] '' + main = do + putStrLn "hello world" + ''; + js = pkgs.writeJS "hello-world" {} '' + console.log("hello world") + ''; + perl = pkgs.writePerl "hello-world" {} '' + print "hello world\n"; + ''; + python2 = pkgs.writePython2 "hello-world" {} '' + print "hello world" + ''; + python3 = pkgs.writePython3 "hello-world" {} '' + print("hello world") + ''; + sed = pkgs.writeDash "sed-example" '' + echo xxx | ${pkgs.writeSed "hello-world" "s/xxx/hello world/"} + ''; +} diff --git a/examples/simple.nix b/examples/simple.nix new file mode 100644 index 0000000..55ccedc --- /dev/null +++ b/examples/simple.nix @@ -0,0 +1,48 @@ +let + pkgs = import <nixpkgs> { overlays = [ (import ../pkgs) ]; }; +in { + bash = pkgs.writeBash "simple.sh" '' + if [[ "test" == "test" ]]; then echo "bash features"; fi + ''; + # cc -L/nix/store/...blah/lib -I/nix/store/...blah/include + dash = pkgs.writeDash "simple" '' + test '~' = '~' && echo 'dash features' + ''; + haskell = pkgs.writeHaskell "simple" [ "acme-cuteboy" ] '' + import Acme.CuteBoy + + 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; + ''; + python2 = pkgs.writePython2 "simple.py" { deps = [ pkgs.python2Packages.pyyaml ]; } '' + import yaml + + print yaml.load(""" + - some + - random + - variables + """) + ''; + python3 = pkgs.writePython3 "simple.py" { deps = [ pkgs.python3Packages.pyyaml ]; } '' + import yaml + + print(yaml.load(""" + - some + - random + - variables + """)) + ''; + sed = pkgs.writeDash "sed-example" '' + echo hello | ${pkgs.writeSed "hello-world" "s/hello/& world/"} + ''; +} diff --git a/pkgs/default.nix b/pkgs/default.nix index a5582f3..ea3421b 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -303,6 +303,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" ]; @@ -319,6 +336,23 @@ pkgs: oldpkgs: { ${pkgs.cabal2nix}/bin/cabal2nix ${path} > $out ''); + writePerl = name: { deps ? [] }: + let + perl-env = pkgs.buildEnv { + name = "perl-environment"; + paths = deps; + pathsToLink = [ + "/lib/perl5/site_perl" + ]; + }; + in + pkgs.makeScriptWriter { + interpreter = "${pkgs.perl}/bin/perl -I ${perl-env}/lib/perl5/site_perl"; + } name; + + writePerlBin = name: + pkgs.writePerl "/bin/${name}"; + writePython2 = name: { deps ? [], flakeIgnore ? [] }: let py = pkgs.python2.withPackages (ps: deps); |