pkgs.formats.yaml_1_2: init

Same as YAML 1.1 but relies on the unpinned remarshal version which emits
YAML 1.2.
This commit is contained in:
Martin Weinelt 2025-06-10 05:21:34 +02:00
parent 917dfafa27
commit eb8f7fcc12
No known key found for this signature in database
GPG Key ID: 87C1E9888F856759
2 changed files with 75 additions and 2 deletions

View File

@ -192,7 +192,46 @@ optionalAttrs allowAliases aliases
(listOf valueType)
])
// {
description = "YAML value";
description = "YAML 1.1 value";
};
in
valueType;
};
yaml_1_2 =
{ }:
{
generate =
name: value:
pkgs.callPackage (
{ runCommand, remarshal }:
runCommand name
{
nativeBuildInputs = [ remarshal ];
value = builtins.toJSON value;
passAsFile = [ "value" ];
preferLocalBuild = true;
}
''
json2yaml "$valuePath" "$out"
''
) { };
type =
let
valueType =
nullOr (oneOf [
bool
int
float
str
path
(attrsOf valueType)
(listOf valueType)
])
// {
description = "YAML 1.2 value";
};
in
valueType;

View File

@ -143,7 +143,7 @@ runBuildTests {
};
yaml_1_1Atoms = shouldPass {
format = formats.yaml { };
format = formats.yaml_1_1 { };
input = {
null = null;
false = false;
@ -176,6 +176,40 @@ runBuildTests {
'';
};
yaml_1_2Atoms = shouldPass {
format = formats.yaml_1_2 { };
input = {
null = null;
false = false;
true = true;
float = 3.141;
str = "foo";
attrs.foo = null;
list = [
null
null
];
path = ./testfile;
no = "no";
time = "22:30:00";
};
expected = ''
attrs:
foo: null
'false': false
float: 3.141
list:
- null
- null
no: no
'null': null
path: ${./testfile}
str: foo
time: 22:30:00
'true': true
'';
};
iniAtoms = shouldPass {
format = formats.ini { };
input = {