to-edn/to-edn.nix

22 lines
461 B
Nix
Raw Normal View History

2022-05-30 15:13:25 -07:00
{ lib }:
with lib;
let
join-str = concatStringsSep " ";
toEDN = ds:
if isString ds then
''"${ds}"''
else
(if isInt ds then
ds
else
(if isList ds then
"[ ${join-str (map toEDN ds)} ]"
else
(if isAttrs ds then
"{ ${join-str (mapAttrs (k: v: ":${k} ${toEDN v}") ds)} }"
else
throw "unsupported type: ${builtins.typeOf ds}: ${ds}")));
in { ds }: toEDN ds