about summary refs log tree commit diff
path: root/tvix/serde/examples/foods.nix
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2023-01-28T10·45+0300
committertazjin <tazjin@tvl.su>2023-01-31T13·11+0000
commit4da1e64c030fc9b1bb23f1ef90546a531b5f760e (patch)
tree2a5d85f927faa4e1dc3909d88a0f9719a26e6429 /tvix/serde/examples/foods.nix
parent7702941dd9f561cb1f90ada28aa7401ea54a86db (diff)
feat(tvix/serde): add an example application to the project r/5785
This shows how people can use tvix_serde to deserialise configuration
structs for their programs from Nix code.

Change-Id: I71bf4e03dce19dddafe67dd729b4e4b10719a739
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7945
Reviewed-by: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/serde/examples/foods.nix')
-rw-r--r--tvix/serde/examples/foods.nix22
1 files changed, 22 insertions, 0 deletions
diff --git a/tvix/serde/examples/foods.nix b/tvix/serde/examples/foods.nix
new file mode 100644
index 000000000000..c8733cd3efec
--- /dev/null
+++ b/tvix/serde/examples/foods.nix
@@ -0,0 +1,22 @@
+# This is content for the `Data` struct, written in intentionally
+# convoluted Nix code.
+let
+  mkFlavour = flavour: name: {
+    inherit name;
+    value = flavour;
+  };
+
+  tasty = mkFlavour "Tasty";
+  okay = mkFlavour "Okay";
+  eww = mkFlavour "Eww";
+in
+{
+  name = "exhaustive list of foods";
+
+  foods = builtins.listToAttrs [
+    (tasty "beef")
+    (okay "tomatoes")
+    (eww "olives")
+    (tasty "coffee")
+  ];
+}