aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/hello_world.nix36
-rw-r--r--examples/simple.nix48
2 files changed, 84 insertions, 0 deletions
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/"}
+ '';
+}