From 1bd3c1d8514039f45772972b2bbc9c7f22877af2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Kr=C3=BCger?= Date: Thu, 12 Dec 2019 22:14:15 +0100 Subject: [PATCH] wip toml --- toTOML.nix | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 toTOML.nix diff --git a/toTOML.nix b/toTOML.nix new file mode 100644 index 0000000000000..ad69c577a1523 --- /dev/null +++ b/toTOML.nix @@ -0,0 +1,38 @@ +let + toTOMLInner = { data, path }: + if builtins.isAttrs data then + builtins.concatMap iter (builtins.attrNames set) + else if builtins.isFloat then + builtins.toString data + else if builtins.isInt then + builtins.toString data + else if builtins.isNull then + "null" + else if builtins.isString then + data # TODO: escape + else if builtins.isBool then + if data then "true" else "false" + else if builtins.isFunction then + builtins.throw "Can't convert a function to a string" + else if builtins.isList then + else if builtins.isPath then + builtins.toString data # TODO: escape + else builtins.throw "Not any valid data-type"; + + toTOML = data: + if builtins.isAttrs data then + toTOMLInner { inherit data; path = []; } + else + builtins.throw "Must be of type attrs"; +in +{ + testData = { + sub = { + sub2 = { + e = true; + }; + }; + + e = true; + }; +}