@@ -0,0 +1,38 @@
1+/* `dhallToNix` is a utility function to convert expressions in the Dhall
2+ configuration language to their corresponding Nix expressions.
3+
4+ Example:
5+ dhallToNix "{ foo = 1, bar = True }"
6+ => { foo = 1; bar = true; }
7+ dhallToNix "λ(x : Bool) → x == False"
8+ => x : x == false
9+ dhallToNix "λ(x : Bool) → x == False" false
10+ => true
11+
12+ See https://hackage.haskell.org/package/dhall-nix/docs/Dhall-Nix.html for
13+ a longer tutorial
14+
15+ Note that this uses "import from derivation", meaning that Nix will perform
16+ a build during the evaluation phase if you use this `dhallToNix` utility
17+*/
18+{ stdenv, dhall-nix }:
19+
20+let
21+ dhallToNix = code :
22+ let
23+ file = builtins.toFile "dhall-expression" code;
24+
25+ drv = stdenv.mkDerivation {
26+ name = "dhall-compiled.nix";
27+
28+ buildCommand = ''
29+ dhall-to-nix <<< "${file}" > $out
30+ '';
31+
32+ buildInputs = [ dhall-nix ];
33+ };
34+
35+ in
36+ import "${drv}";
37+in
38+ dhallToNix