Initial checkin

This commit is contained in:
niten 2022-05-30 15:13:25 -07:00
commit 815750e93e
2 changed files with 30 additions and 0 deletions

9
flake.nix Normal file
View File

@ -0,0 +1,9 @@
{
description = "Nix-to-EDN converter.";
input = { nixpkgs.url = "nixpkgs/nixos-21.05"; };
outputs = { self, nixpkgs }: {
lib = { toEDN = import ./to-edn.nix { inherit (nixpkgs) lib; }; };
};
}

21
to-edn.nix Normal file
View File

@ -0,0 +1,21 @@
{ 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