From f0e52f31cd33fd321f71eda0bc1d6cd965b5997c Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Thu, 5 May 2022 21:08:54 +0200 Subject: feat(users/Profpatsch/importDhall): print type annotation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If no type annotation is given, debugging errors gets a lot harder because there is nothing to compare it against. But we can tell dhall to print the type first (this means double evaluation, but that’s an optimization problem to be solved later). Change-Id: Icf793828070cd6bb8daeb4c07de3162a5e064653 Reviewed-on: https://cl.tvl.fyi/c/depot/+/5525 Tested-by: BuildkiteCI Reviewed-by: Profpatsch --- users/Profpatsch/importDhall.nix | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'users/Profpatsch') diff --git a/users/Profpatsch/importDhall.nix b/users/Profpatsch/importDhall.nix index 9713b2cfb8..bddfcc5b07 100644 --- a/users/Profpatsch/importDhall.nix +++ b/users/Profpatsch/importDhall.nix @@ -37,7 +37,8 @@ let cache = ".cache"; cacheDhall = "${cache}/dhall"; - typeAnnot = if type == null then "" else ": ${type}"; + hadTypeAnnot = type != null; + typeAnnot = lib.optionalString hadTypeAnnot ": ${type}"; convert = pkgs.runCommandLocal "dhall-to-nix" { inherit deps; } '' mkdir -p ${cacheDhall} @@ -49,9 +50,19 @@ let # go into the source directory, so that the type can import files. # TODO: This is a bit of a hack hrm. cd "${src}" - printf '%s' ${lib.escapeShellArg "${src}/${main} ${typeAnnot}"} \ - | ${pkgs.dhall-nix}/bin/dhall-to-nix \ - > $out + ${if hadTypeAnnot then '' + printf '%s' ${lib.escapeShellArg "${src}/${main} ${typeAnnot}"} \ + | ${pkgs.dhall-nix}/bin/dhall-to-nix \ + > $out + '' + else '' + printf 'No type annotation given, the dhall expression type was:\n' + ${pkgs.dhall}/bin/dhall type --file "${src}/${main}" + printf '%s' ${lib.escapeShellArg "${src}/${main}"} \ + | ${pkgs.dhall-nix}/bin/dhall-to-nix \ + > $out + ''} + ''; in import convert; -- cgit 1.4.1