diff options
author | lucasew <lucas59356@gmail.com> | 2021-08-13 16:31:14 -0300 |
---|---|---|
committer | Robert Helgesson <robert@rycee.net> | 2021-08-25 14:02:59 +0200 |
commit | 83514ae7a9f25023c2bc7bec323e661b7302d61d (patch) | |
tree | e834ae9a1c2304d8016d1d92466ae884d802b8e3 /pkgs/pkgs-lib/formats.nix | |
parent | 346d5ce8a087cdd6a35c1fd34ee33c6bb79f2058 (diff) |
lib.formats.yaml: use well known YAML format
The way `(lib.formats.yaml {}).generate` generates YAML is compliant because on YAML 1.2 spec JSON is a subset of YAML but it bugs people's minds and can lead to problems with software that is not compatible with YAML 1.2. This commit also changes the test of the generation function. Data validation/typing remains the same. See #133802. Signed-off-by: lucasew <lucas59356@gmail.com>
Diffstat (limited to 'pkgs/pkgs-lib/formats.nix')
-rw-r--r-- | pkgs/pkgs-lib/formats.nix | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/pkgs/pkgs-lib/formats.nix b/pkgs/pkgs-lib/formats.nix index 44c8f91354391..5e17519d4ce18 100644 --- a/pkgs/pkgs-lib/formats.nix +++ b/pkgs/pkgs-lib/formats.nix @@ -48,14 +48,31 @@ rec { }; - # YAML has been a strict superset of JSON since 1.2 - yaml = {}: - let jsonSet = json {}; - in jsonSet // { - type = jsonSet.type // { + yaml = {}: { + + generate = name: value: pkgs.runCommand name { + nativeBuildInputs = [ pkgs.remarshal ]; + value = builtins.toJSON value; + passAsFile = [ "value" ]; + } '' + json2yaml "$valuePath" "$out" + ''; + + type = with lib.types; let + valueType = nullOr (oneOf [ + bool + int + float + str + path + (attrsOf valueType) + (listOf valueType) + ]) // { description = "YAML value"; }; - }; + in valueType; + + }; ini = { # Represents lists as duplicate keys |