summaryrefslogtreecommitdiffstats
path: root/pkgs/build-support
diff options
context:
space:
mode:
authorGabriel Gonzalez <gabriel@awakenetworks.com>2017-01-26 20:11:49 -0800
committerGabriel Gonzalez <gabriel@awakenetworks.com>2017-01-26 20:11:49 -0800
commitc791c0fd16abea669d3aaa082a9174d6d3ad77f4 (patch)
tree8e1c06da3c362e3e083ee61fb9cf69173b8bc837 /pkgs/build-support
parent2f367e0af714bb6e7abcd3b79d7bd31bd946a3d3 (diff)
Add a `pkgs.dhallToNix` utility
This adds a `dhallToNix` utility which compiles expression from the Dhall configuration language to Nix using Nix's support for "import from derivation". The main motivation of this compiler is to allow users to carve out small typed subsets of Nix projects. Everything in the Dhall language (except `Double`s) can be translated to Nix in this way, including functions.
Diffstat (limited to 'pkgs/build-support')
-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 000000000000..c563b34ff3bc
--- /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 }:
+
+let
+ dhallToNix = code :
+ let
+ file = builtins.toFile "dhall-expression" code;
+
+ drv = stdenv.mkDerivation {
+ name = "dhall-compiled.nix";
+
+ buildCommand = ''
+ dhall-to-nix <<< "${file}" > $out
+ '';
+
+ buildInputs = [ dhall-nix ];
+ };
+
+ in
+ import "${drv}";
+in
+ dhallToNix