dhall-haskell/dhall-nix
Gabriel Gonzalez 4c7b75b503
Version 1.27.0 → 1.28.0 (#1575)
2019-12-05 19:28:39 -08:00
..
exec Handle --version consistently (#1334) 2019-09-22 03:55:26 +00:00
src/Dhall Add `Integer/{clamp,negate}` built-ins (#1486) 2019-10-29 17:21:00 +00:00
.travis.yml Remove support for GHC 7.10 2017-01-21 18:43:02 -08:00
LICENSE Initial commit 2017-01-20 20:33:49 -08:00
README.md Explain use case for `dhall-to-nix` (#913) 2019-04-27 21:10:02 -07:00
Setup.hs Initial commit 2017-01-20 20:33:49 -08:00
default.nix Integrate `dhall-nix` into CI (#887) 2019-04-11 09:16:43 -07:00
dhall-nix.cabal Version 1.27.0 → 1.28.0 (#1575) 2019-12-05 19:28:39 -08:00
release.nix Optionally pass Nixpkgs through entry functions (#1409) 2019-10-17 19:06:21 -07:00
shell.nix Integrate `dhall-nix` into CI (#887) 2019-04-11 09:16:43 -07:00

README.md

dhall-nix

For installation or development instructions, see:

Full documentation here:

Introduction

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.

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.

Quick start

If you have Nix installed then you can build and run this package using:

$ dhall-to-nix <<< "λ(x : Bool) → x == False"
x: x == false
$ dhall-to-nix <<< "{ foo = 1, bar = True }"
{ bar = true; foo = 1; }
$ dhall-to-nix <<< "< Left = 2 | Right : Natural >"
{ 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:

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}";

The above dhallToNix utility is now in nixpkgs so you can use pkgs.dhallToNix to transform Dhall expressions to Nix expressions