toDhall
lib.generators.toDhall
Docs pulled from | This Revision | 10 minutes ago
Translate a simple Nix expression to Dhall notation.
Note that integers are translated to Integer and never the Natural type.
Inputs
- Options
-
Empty set, there may be configuration options in the future
- Value
-
The value to be converted to Dhall
Noogle detected
Implementation
The following is the current implementation of this function.
toDhall =
{ }@args:
v:
let
concatItems = concatStringsSep ", ";
in
if isAttrs v then
"{ ${concatItems (mapAttrsToList (key: value: "${key} = ${toDhall args value}") v)} }"
else if isList v then
"[ ${concatItems (map (toDhall args) v)} ]"
else if isInt v then
"${if v < 0 then "" else "+"}${toString v}"
else if isBool v then
(if v then "True" else "False")
else if isFunction v then
abort "generators.toDhall: cannot convert a function to Dhall"
else if v == null then
abort "generators.toDhall: cannot convert a null to Dhall"
else
toJSON v;