aboutsummaryrefslogtreecommitdiff
path: root/day2
diff options
context:
space:
mode:
authorJustin Bedo <cu@cua0.org>2022-10-06 10:21:34 +1100
committerJustin Bedo <cu@cua0.org>2022-10-07 14:58:01 +1100
commitdda29ca7685d360d5428dd827d11a9e4139a0872 (patch)
tree0dcc853fd90abf245b6ba0a7506b2e1093bf7800 /day2
init
Diffstat (limited to 'day2')
-rw-r--r--day2/ex1-hello-world/default.nix22
l---------day2/ex1-hello-world/flake.lock1
-rwxr-xr-xday2/ex1-hello-world/flake.nix20
-rw-r--r--day2/ex1-hello-world/solution.nix24
-rw-r--r--day2/ex2-dlrow-olleh/default.nix30
l---------day2/ex2-dlrow-olleh/flake.lock1
-rwxr-xr-xday2/ex2-dlrow-olleh/flake.nix20
-rw-r--r--day2/ex2-dlrow-olleh/solution.nix14
8 files changed, 132 insertions, 0 deletions
diff --git a/day2/ex1-hello-world/default.nix b/day2/ex1-hello-world/default.nix
new file mode 100644
index 0000000..8eaffa7
--- /dev/null
+++ b/day2/ex1-hello-world/default.nix
@@ -0,0 +1,22 @@
+/*
+ This first exercise demonstrates how to define a processing stage,
+which is just instructions on how to compute an output (the
+`buildCommand`) from some inputs (in this case, there are no inputs).
+Each stage must minimally define a `name`, shell code to build the
+output in `buildCommand`, and any software that's required in
+`buildInputs`. Note that `buildInputs = []` if not defined, meaning no
+extra requirements over the standard environment.
+
+Try replacing the echo below with output from the GNU hello program.
+Hint: the GNU hello program is available at `pkgs.hello` and the
+executable is called `hello`.
+*/
+{bionix}:
+with bionix;
+ stage {
+ name = "hello-world";
+
+ buildCommand = ''
+ echo hello world > $out
+ '';
+ }
diff --git a/day2/ex1-hello-world/flake.lock b/day2/ex1-hello-world/flake.lock
new file mode 120000
index 0000000..981422e
--- /dev/null
+++ b/day2/ex1-hello-world/flake.lock
@@ -0,0 +1 @@
+../../common/flake.lock \ No newline at end of file
diff --git a/day2/ex1-hello-world/flake.nix b/day2/ex1-hello-world/flake.nix
new file mode 100755
index 0000000..bfaca96
--- /dev/null
+++ b/day2/ex1-hello-world/flake.nix
@@ -0,0 +1,20 @@
+{
+ inputs = {
+ nixpkgs.url = "github:nixos/nixpkgs";
+ bionix.url = "github:papenfusslab/bionix";
+ flake-utils.url = "github:numtide/flake-utils";
+ };
+
+ outputs = {
+ self,
+ nixpkgs,
+ bionix,
+ flake-utils,
+ }:
+ flake-utils.lib.eachDefaultSystem (system: let
+ pkgs = import nixpkgs {inherit system;};
+ bionix' = import bionix {nixpkgs = pkgs;};
+ in {
+ defaultPackage = bionix'.callBionix ./. {};
+ });
+}
diff --git a/day2/ex1-hello-world/solution.nix b/day2/ex1-hello-world/solution.nix
new file mode 100644
index 0000000..d0531a2
--- /dev/null
+++ b/day2/ex1-hello-world/solution.nix
@@ -0,0 +1,24 @@
+/*
+ This first exercise demonstrates how to define a processing stage,
+which is just instructions on how to compute an output (the
+`buildCommand`) from some inputs (in this case, there are no inputs).
+Each stage must minimally define a `name`, shell code to build the
+output in `buildCommand`, and any software that's required in
+`buildInputs`. Note that `buildInputs = []` if not defined, meaning no
+extra requirements over the standard environment.
+
+Try replacing the echo below with output from the GNU hello program.
+Hint: the GNU hello program is available at `pkgs.hello` and the
+executable is called `hello`.
+*/
+{bionix}:
+with bionix;
+ stage {
+ name = "hello-world";
+
+ buildInputs = [pkgs.hello];
+
+ buildCommand = ''
+ hello > $out
+ '';
+ }
diff --git a/day2/ex2-dlrow-olleh/default.nix b/day2/ex2-dlrow-olleh/default.nix
new file mode 100644
index 0000000..91bbe1f
--- /dev/null
+++ b/day2/ex2-dlrow-olleh/default.nix
@@ -0,0 +1,30 @@
+/*
+This exercise demonstrates the first workflow consisting of multiple
+steps. We will build upon the previous example by using the string
+produced in exercise 1 as input to this workflow. You can see how other
+files can be imported and used in the construction of workflows using
+`callBionix`, which imports a file and passes it `bionix` along with
+potentially some additional arguments.
+
+Goal: fill out the stage here to reverse the string using the `rev`
+program, which reads lines on stdin and writes them to stdout with the
+characters reversed. You will need to choose exactly *which* rev you
+want to use in `buildInputs`: there are three providers available
+(busybox, toybox, utillinux) and you can try them all.
+
+Bonus: change the last line to call rev twice, thereby reversing the
+strings back to the original orientation
+*/
+{bionix}:
+with bionix; let
+ hello-world = callBionix ../ex1-hello-world {};
+
+ rev = input:
+ stage {
+ name = "rev";
+ buildInputs = [];
+ buildCommand = ''
+ '';
+ };
+in
+ rev hello-world
diff --git a/day2/ex2-dlrow-olleh/flake.lock b/day2/ex2-dlrow-olleh/flake.lock
new file mode 120000
index 0000000..981422e
--- /dev/null
+++ b/day2/ex2-dlrow-olleh/flake.lock
@@ -0,0 +1 @@
+../../common/flake.lock \ No newline at end of file
diff --git a/day2/ex2-dlrow-olleh/flake.nix b/day2/ex2-dlrow-olleh/flake.nix
new file mode 100755
index 0000000..bfaca96
--- /dev/null
+++ b/day2/ex2-dlrow-olleh/flake.nix
@@ -0,0 +1,20 @@
+{
+ inputs = {
+ nixpkgs.url = "github:nixos/nixpkgs";
+ bionix.url = "github:papenfusslab/bionix";
+ flake-utils.url = "github:numtide/flake-utils";
+ };
+
+ outputs = {
+ self,
+ nixpkgs,
+ bionix,
+ flake-utils,
+ }:
+ flake-utils.lib.eachDefaultSystem (system: let
+ pkgs = import nixpkgs {inherit system;};
+ bionix' = import bionix {nixpkgs = pkgs;};
+ in {
+ defaultPackage = bionix'.callBionix ./. {};
+ });
+}
diff --git a/day2/ex2-dlrow-olleh/solution.nix b/day2/ex2-dlrow-olleh/solution.nix
new file mode 100644
index 0000000..ab235fe
--- /dev/null
+++ b/day2/ex2-dlrow-olleh/solution.nix
@@ -0,0 +1,14 @@
+{bionix}:
+with bionix; let
+ hello-world = callBionix ../ex1-hello-world {};
+
+ rev = input:
+ stage {
+ name = "rev";
+ buildInputs = [pkgs.toybox];
+ buildCommand = ''
+ rev < ${input} > $out
+ '';
+ };
+in
+ rev (rev hello-world)