Search code examples
dhall

Passing filename to read as a parameter


My configuration reads a certificate from a file.

This is a straightforward way:

in { devicesCa = "${/path/to/cert/ca.crt as Text}" }

I haven't found a way of passing /path/to/cert/ca.crt as a parameter. For instance:

let path = "/path/to/cert/ca.crt"
in { devicesCa = "${${path} as Text}" }

Is it possible to do? If not, what known workarounds are?


Solution

  • This is currently not possible to do because the language does not yet support "computed imports" (i.e. imports that depend on a variable).

    The simple explanation is that:

    • Type-checking precedes substitution/normalization

      ... because evaluating an untyped expression could lead to errors or infinite loops

    • Import resolution precedes type-checking

      ... because an expression with unresolved imports cannot be type-checked

    • Therefore, imports cannot depend on substituted variables

      ... because you end up with a chicken-and-egg problem where import resolution depends on normalization and normalization depends on import resolution.

    The longer explanation is that it technically is possible, but would require removing Dhall's phase distinctions. Currently, the import resolution phase precedes the type-checking phase which in turn precedes the normalization phase. Implementing support for computed imports would require safely interleaving these phases, which would require heavy refactors to the language standard and refactors to the APIs of each Dhall implementation.