dhall-haskell/dhall-nix
Emery Hemingway 48ca2d2424 Optionally pass Nixpkgs through entry functions (#1409)
The "builtins.fetchTarball" function is not available in some restricted
environments such as build jobs of the latest Hydra. Make it possible to
pass nixpkgs and nixpkgsStaticLinux when evaulating default.nix and
release.nix to avoid importing them internally. This does not change the
result of evaulation if no parameters are passed.
2019-10-17 19:06:21 -07:00
..
exec Handle --version consistently (#1334) 2019-09-22 03:55:26 +00:00
src/Dhall 100% haddock coverage (#1416) 2019-10-13 22:22:39 -07:00
.travis.yml Remove support for GHC 7.10 2017-01-21 18:43:02 -08:00
default.nix Integrate dhall-nix into CI (#887) 2019-04-11 09:16:43 -07:00
dhall-nix.cabal Eta: Remove YAML FFI code and disable dhall-nix build 2019-10-15 06:22:49 -04: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
release.nix Optionally pass Nixpkgs through entry functions (#1409) 2019-10-17 19:06:21 -07:00
Setup.hs Initial commit 2017-01-20 20:33:49 -08:00
shell.nix Integrate dhall-nix into CI (#887) 2019-04-11 09:16:43 -07:00

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