core/pkgs/build-support/dhall/to-nix.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

45 lines
989 B
Nix
Raw Normal View History

2024-05-02 00:46:19 +00:00
/*
`dhallToNix` is a utility function to convert expressions in the Dhall
configuration language to their corresponding Nix expressions.
2024-06-30 08:16:52 +00:00
2024-05-02 00:46:19 +00:00
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
2024-06-30 08:16:52 +00:00
2024-05-02 00:46:19 +00:00
See https://hackage.haskell.org/package/dhall-nix/docs/Dhall-Nix.html for
a longer tutorial
2024-06-30 08:16:52 +00:00
2024-05-02 00:46:19 +00:00
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