From eb8f7fcc12258b95fda8ce2192319db861794db1 Mon Sep 17 00:00:00 2001 From: Martin Weinelt Date: Tue, 10 Jun 2025 05:21:34 +0200 Subject: [PATCH] pkgs.formats.yaml_1_2: init Same as YAML 1.1 but relies on the unpinned remarshal version which emits YAML 1.2. --- pkgs/pkgs-lib/formats.nix | 41 ++++++++++++++++++++++++++++++++- pkgs/pkgs-lib/tests/formats.nix | 36 ++++++++++++++++++++++++++++- 2 files changed, 75 insertions(+), 2 deletions(-) diff --git a/pkgs/pkgs-lib/formats.nix b/pkgs/pkgs-lib/formats.nix index 9113d8ec3307..0836519c203d 100644 --- a/pkgs/pkgs-lib/formats.nix +++ b/pkgs/pkgs-lib/formats.nix @@ -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; diff --git a/pkgs/pkgs-lib/tests/formats.nix b/pkgs/pkgs-lib/tests/formats.nix index d69fd9e15fb9..4f635a4070fe 100644 --- a/pkgs/pkgs-lib/tests/formats.nix +++ b/pkgs/pkgs-lib/tests/formats.nix @@ -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 = {