about summary refs log tree commit diff
path: root/pkgs/build-support/dhall
diff options
context:
space:
mode:
author(cdep)illabout <cdep.illabout@gmail.com>2021-11-02 15:50:13 +0900
committer(cdep)illabout <cdep.illabout@gmail.com>2021-12-07 13:36:19 +0900
commit32c93844f5c14cf7135f96b27649dc8e36442866 (patch)
tree02f1475b245356b96a10acc5f137dcd502b97b92 /pkgs/build-support/dhall
parentf9e038e2356b9652eab27676bd0c1b31d3a6da9e (diff)
dhallToNix: rename file from build-support/dhall-to-nix.nix to build-support/dhall/to-nix.nix
Diffstat (limited to 'pkgs/build-support/dhall')
-rw-r--r--pkgs/build-support/dhall/to-nix.nix38
1 files changed, 38 insertions, 0 deletions
diff --git a/pkgs/build-support/dhall/to-nix.nix b/pkgs/build-support/dhall/to-nix.nix
new file mode 100644
index 0000000000000..96cc16e16f369
--- /dev/null
+++ b/pkgs/build-support/dhall/to-nix.nix
@@ -0,0 +1,38 @@
+/* `dhallToNix` is a utility function to convert expressions in the Dhall
+    configuration language to their corresponding Nix expressions.
+
+    Example:
+      dhallToNix "{ foo = 1, bar = True }"
+      => { foo = 1; bar = true; }
+      dhallToNix "λ(x : Bool) → x == False"
+      => x : x == false
+      dhallToNix "λ(x : Bool) → x == False" false
+      => true
+
+    See https://hackage.haskell.org/package/dhall-nix/docs/Dhall-Nix.html for
+    a longer tutorial
+
+    Note that this uses "import from derivation", meaning that Nix will perform
+    a build during the evaluation phase if you use this `dhallToNix` utility
+*/
+{ stdenv, dhall-nix, writeText }:
+
+let
+  dhallToNix = code :
+    let
+      file = writeText "dhall-expression" code;
+
+      drv = stdenv.mkDerivation {
+        name = "dhall-compiled.nix";
+
+        buildCommand = ''
+          dhall-to-nix <<< "${file}" > $out
+        '';
+
+        buildInputs = [ dhall-nix ];
+      };
+
+    in
+      import drv;
+in
+  dhallToNix