From 64f0f7a448ae743b7393a150bdc47553ea75b66c Mon Sep 17 00:00:00 2001 From: Samuel Shuert Date: Fri, 7 Jun 2024 17:15:50 -0400 Subject: [PATCH 1/2] lib.trivial.importTOML: add example Friend came to me with misunderstanding of how this function works. After discussion we came to the conclusion having an example would have prevented this. --- lib/trivial.nix | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lib/trivial.nix b/lib/trivial.nix index dee7eca9699a0b..f4a8f0d9bec57d 100644 --- a/lib/trivial.nix +++ b/lib/trivial.nix @@ -642,6 +642,35 @@ in { /** Reads a TOML file. + # Examples + :::{.example} + ## `lib.trivial.importTOML` usage example + + example.toml + ```toml + title = "TOML Example" + + [hello] + world = "foo" + + [hello.bar] + foobar = true + ``` + + ```nix + importTOML ./example.toml + => { + title = "TOML Example"; + hello = { + world = "foo"; + bar = { + foobar = true; + }; + }; + } + ``` + + ::: # Inputs From cfc6c9b6e433009a3f5c0a4c9cab526e09bd760a Mon Sep 17 00:00:00 2001 From: Samuel Shuert Date: Fri, 7 Jun 2024 17:22:17 -0400 Subject: [PATCH 2/2] lib.trivial.importJSON: add example Add parity with importTOML. --- lib/trivial.nix | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/lib/trivial.nix b/lib/trivial.nix index f4a8f0d9bec57d..3284e3dbe48386 100644 --- a/lib/trivial.nix +++ b/lib/trivial.nix @@ -623,6 +623,37 @@ in { /** Reads a JSON file. + # Examples + :::{.example} + ## `lib.trivial.importJSON` usage example + + example.json + ```json + { + "title": "Example JSON", + "hello": { + "world": "foo", + "bar": { + "foobar": true + } + } + } + ``` + + ```nix + importJSON ./example.json + => { + title = "Example JSON"; + hello = { + world = "foo"; + bar = { + foobar = true; + }; + }; + } + ``` + + ::: # Inputs