about summary refs log tree commit diff
path: root/nixpkgs/pkgs/pkgs-lib
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/pkgs-lib')
-rw-r--r--nixpkgs/pkgs/pkgs-lib/formats.nix33
-rw-r--r--nixpkgs/pkgs/pkgs-lib/tests/formats.nix28
2 files changed, 37 insertions, 24 deletions
diff --git a/nixpkgs/pkgs/pkgs-lib/formats.nix b/nixpkgs/pkgs/pkgs-lib/formats.nix
index 4d5395664612..5e17519d4ce1 100644
--- a/nixpkgs/pkgs/pkgs-lib/formats.nix
+++ b/nixpkgs/pkgs/pkgs-lib/formats.nix
@@ -38,7 +38,7 @@ rec {
       };
     in valueType;
 
-    generate = name: value: pkgs.runCommandNoCC name {
+    generate = name: value: pkgs.runCommand name {
       nativeBuildInputs = [ pkgs.jq ];
       value = builtins.toJSON value;
       passAsFile = [ "value" ];
@@ -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
@@ -121,7 +138,7 @@ rec {
       };
     in valueType;
 
-    generate = name: value: pkgs.runCommandNoCC name {
+    generate = name: value: pkgs.runCommand name {
       nativeBuildInputs = [ pkgs.remarshal ];
       value = builtins.toJSON value;
       passAsFile = [ "value" ];
diff --git a/nixpkgs/pkgs/pkgs-lib/tests/formats.nix b/nixpkgs/pkgs/pkgs-lib/tests/formats.nix
index 679fde015228..2bc4e407fe75 100644
--- a/nixpkgs/pkgs/pkgs-lib/tests/formats.nix
+++ b/nixpkgs/pkgs/pkgs-lib/tests/formats.nix
@@ -14,7 +14,7 @@ let
       }) [ def ]);
     in formatSet.generate "test-format-file" config;
 
-  runBuildTest = name: { drv, expected }: pkgs.runCommandNoCC name {} ''
+  runBuildTest = name: { drv, expected }: pkgs.runCommand name {} ''
     if diff -u '${builtins.toFile "expected" expected}' '${drv}'; then
       touch "$out"
     else
@@ -72,21 +72,17 @@ in runBuildTests {
       path = ./formats.nix;
     };
     expected = ''
-      {
-        "attrs": {
-          "foo": null
-        },
-        "false": false,
-        "float": 3.141,
-        "list": [
-          null,
-          null
-        ],
-        "null": null,
-        "path": "${./formats.nix}",
-        "str": "foo",
-        "true": true
-      }
+      attrs:
+        foo: null
+      'false': false
+      float: 3.141
+      list:
+      - null
+      - null
+      'null': null
+      path: ${./formats.nix}
+      str: foo
+      'true': true
     '';
   };