about summary refs log tree commit diff
path: root/users/Profpatsch/importDhall.nix
diff options
context:
space:
mode:
Diffstat (limited to 'users/Profpatsch/importDhall.nix')
-rw-r--r--users/Profpatsch/importDhall.nix19
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;