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.
|
|
|
|
|
2019-04-28 06:10:02 +02:00
|
|
|
Note that this is a proof-of-concept illustration of how Dhall language
|
|
|
|
constructs map onto the Nix language. You might get value out of this on small
|
|
|
|
Nix expressions, but you will likely run into friction using this in a larger
|
|
|
|
scale with Nixpkgs or NixOS, because Dhall cannot encode many common
|
|
|
|
Nixpkgs/NixOS idioms, such as:
|
|
|
|
|
|
|
|
* general recursion (such as `pkgs.callPackages`, the overlay system, and the
|
|
|
|
NixOS module system)
|
|
|
|
* weakly-typed conversions (such as `builtins.listToAttrs`)
|
|
|
|
* row polymorphism (i.e. the `...` in `{ foo, bar, ... }`)
|
|
|
|
|
|
|
|
You can use this project to embed existing Dhall code with Nix, but probably
|
|
|
|
not as a general-purpose Nix replacement.
|
|
|
|
|
2017-01-22 04:13:50 +01:00
|
|
|
## 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
|