diff options
author | tv <tv@krebsco.de> | 2018-09-18 19:29:19 +0200 |
---|---|---|
committer | tv <tv@krebsco.de> | 2018-09-18 19:29:19 +0200 |
commit | cf9ac094e0f6d9649f050452c0df539281237e54 (patch) | |
tree | a4ffecdc2b856198c777ec8d951227af8466a53a | |
parent | c27a9416e8ee04d708b11b48f8cf1a055c0cc079 (diff) | |
parent | 16b43f218d142de49fbd8fae77e6e2c057bfb9d6 (diff) |
Merge remote-tracking branch 'lass/master'derp
-rw-r--r-- | ci.nix | 26 | ||||
-rw-r--r-- | examples/hello_world.nix | 33 | ||||
-rw-r--r-- | examples/simple.nix | 42 | ||||
-rw-r--r-- | pkgs/default.nix | 17 |
4 files changed, 118 insertions, 0 deletions
@@ -0,0 +1,26 @@ +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; + 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..4944c13 --- /dev/null +++ b/examples/hello_world.nix @@ -0,0 +1,33 @@ +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" + ''; + 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..ad62b84 --- /dev/null +++ b/examples/simple.nix @@ -0,0 +1,42 @@ +let + pkgs = import <nixpkgs> { overlays = [ (import ../pkgs) ]; }; +in { + bash = pkgs.writeBash "hello-world" '' + if [[ "test" == "test" ]]; then echo "bash features"; fi + ''; + # cc -L/nix/store/...blah/lib -I/nix/store/...blah/include + dash = pkgs.writeDash "hello-world" '' + test '~' = '~' && echo 'dash features' + ''; + haskell = pkgs.writeHaskell "hello-world" [ "acme-cuteboy" ] '' + import Acme.CuteBoy + + main :: IO () + main = print Rolf + ''; + perl = pkgs.writePerl "simple.pl" { deps = [ pkgs.perlPackages.boolean ]; } '' + use boolean; + print "Howdy!\n" if true; + ''; + python2 = pkgs.writePython2 "hello-world" { deps = [ pkgs.python2Packages.pyyaml ]; } '' + import yaml + + print yaml.load(""" + - some + - random + - variables + """) + ''; + python3 = pkgs.writePython3 "hello-world" { 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..c374124 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -319,6 +319,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); |