lol
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

lucasew and committed by
Robert Helgesson
83514ae7 346d5ce8

+43 -21
+7
nixos/doc/manual/from_md/release-notes/rl-2111.section.xml
··· 1058 1058 sign OCSP responses and server certificates. 1059 1059 </para> 1060 1060 </listitem> 1061 + <listitem> 1062 + <para> 1063 + <literal>lib.formats.yaml</literal>’s 1064 + <literal>generate</literal> will not generate JSON anymore, 1065 + but instead use more of the YAML-specific syntax. 1066 + </para> 1067 + </listitem> 1061 1068 </itemizedlist> 1062 1069 </section> 1063 1070 </section>
+2
nixos/doc/manual/release-notes/rl-2111.section.md
··· 302 302 - Zfs: `latestCompatibleLinuxPackages` is now exported on the zfs package. One can use `boot.kernelPackages = config.boot.zfs.package.latestCompatibleLinuxPackages;` to always track the latest compatible kernel with a given version of zfs. 303 303 304 304 - Nginx will use the value of `sslTrustedCertificate` if provided for a virtual host, even if `enableACME` is set. This is useful for providers not using the same certificate to sign OCSP responses and server certificates. 305 + 306 + - `lib.formats.yaml`'s `generate` will not generate JSON anymore, but instead use more of the YAML-specific syntax.
+23 -6
pkgs/pkgs-lib/formats.nix
··· 48 48 49 49 }; 50 50 51 - # YAML has been a strict superset of JSON since 1.2 52 - yaml = {}: 53 - let jsonSet = json {}; 54 - in jsonSet // { 55 - type = jsonSet.type // { 51 + yaml = {}: { 52 + 53 + generate = name: value: pkgs.runCommand name { 54 + nativeBuildInputs = [ pkgs.remarshal ]; 55 + value = builtins.toJSON value; 56 + passAsFile = [ "value" ]; 57 + } '' 58 + json2yaml "$valuePath" "$out" 59 + ''; 60 + 61 + type = with lib.types; let 62 + valueType = nullOr (oneOf [ 63 + bool 64 + int 65 + float 66 + str 67 + path 68 + (attrsOf valueType) 69 + (listOf valueType) 70 + ]) // { 56 71 description = "YAML value"; 57 72 }; 58 - }; 73 + in valueType; 74 + 75 + }; 59 76 60 77 ini = { 61 78 # Represents lists as duplicate keys
+11 -15
pkgs/pkgs-lib/tests/formats.nix
··· 72 72 path = ./formats.nix; 73 73 }; 74 74 expected = '' 75 - { 76 - "attrs": { 77 - "foo": null 78 - }, 79 - "false": false, 80 - "float": 3.141, 81 - "list": [ 82 - null, 83 - null 84 - ], 85 - "null": null, 86 - "path": "${./formats.nix}", 87 - "str": "foo", 88 - "true": true 89 - } 75 + attrs: 76 + foo: null 77 + 'false': false 78 + float: 3.141 79 + list: 80 + - null 81 + - null 82 + 'null': null 83 + path: ${./formats.nix} 84 + str: foo 85 + 'true': true 90 86 ''; 91 87 }; 92 88