diff options
author | Profpatsch <mail@profpatsch.de> | 2022-05-05T19·08+0200 |
---|---|---|
committer | Profpatsch <mail@profpatsch.de> | 2022-05-05T20·18+0000 |
commit | f0e52f31cd33fd321f71eda0bc1d6cd965b5997c (patch) | |
tree | afaa3c871c66d71a5e4979cb48222096ede047e4 | |
parent | 9dd77432384b1b1e85edc481a37a1473fe63ae6a (diff) |
feat(users/Profpatsch/importDhall): print type annotation r/4008
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>
-rw-r--r-- | users/Profpatsch/importDhall.nix | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/users/Profpatsch/importDhall.nix b/users/Profpatsch/importDhall.nix index 9713b2cfb8d3..bddfcc5b072e 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; |