dhall-haskell/dhall-nix/README.md

54 lines
1.4 KiB
Markdown
Raw Normal View History

2019-04-11 18:16:43 +02:00
# `dhall-nix`
For installation or development instructions, see:
* [`dhall-haskell` - `README`](https://github.com/dhall-lang/dhall-haskell/blob/master/README.md)
Full documentation here:
* [`dhall-nix` instructions](https://hackage.haskell.org/package/dhall-nix/docs/Dhall-Nix.html)
## Introduction
2017-01-22 04:13:50 +01:00
This `dhall-nix` package provides a Dhall to Nix compiler. You can use this
compiler to program Nix using the Dhall language. This package targets people
who wish Nix had a type system.
## Quick start
If you have Nix installed then you can build and run this package using:
```bash
2019-04-11 18:16:43 +02:00
$ dhall-to-nix <<< "λ(x : Bool) → x == False"
2017-01-22 04:13:50 +01:00
x: x == false
2019-04-11 18:16:43 +02:00
$ dhall-to-nix <<< "{ foo = 1, bar = True }"
2017-01-22 04:13:50 +01:00
{ bar = true; foo = 1; }
2019-04-11 18:16:43 +02:00
$ dhall-to-nix <<< "< Left = 2 | Right : Natural >"
2017-01-22 04:13:50 +01:00
{ Left, Right }: Left 2
```
However, this package is also designed to be used directly from Nix. You can
use the following `dhallToNix` utility to translate Dhall source code to the
corresponding Nix expression directly within Nix:
```nix
dhallToNix = code :
let
file = builtins.toFile "dhall-expr" code;
drv = pkgs.stdenv.mkDerivation {
name = "dhall-expr-as-nix";
buildCommand = ''
dhall-to-nix <<< "${file}" > $out
'';
buildInputs = [ pkgs.haskellPackages.dhall-nix ];
};
in
import "${drv}";
```
2019-04-11 18:16:43 +02:00
The above `dhallToNix` utility is now in `nixpkgs` so you can use
`pkgs.dhallToNix` to transform Dhall expressions to Nix expressions