commit 815750e93e2e5bde39057503a5990783c96eff59 Author: niten Date: Mon May 30 15:13:25 2022 -0700 Initial checkin diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..251fdce --- /dev/null +++ b/flake.nix @@ -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; }; }; + }; +} diff --git a/to-edn.nix b/to-edn.nix new file mode 100644 index 0000000..738e675 --- /dev/null +++ b/to-edn.nix @@ -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