feat(users/Profpatsch/importDhall): print type annotation

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 <mail@profpatsch.de>
This commit is contained in:
Profpatsch 2022-05-05 21:08:54 +02:00
parent 9dd7743238
commit f0e52f31cd

View file

@ -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;