diff options
author | Alyssa Ross <hi@alyssa.is> | 2021-09-08 17:57:14 +0000 |
---|---|---|
committer | Alyssa Ross <hi@alyssa.is> | 2021-09-13 11:31:47 +0000 |
commit | ee7984efa14902a2ddd820c937457667a4f40c6a (patch) | |
tree | c9c1d046733cefe5e21fdd8a52104175d47b2443 /nixpkgs/pkgs/pkgs-lib | |
parent | ffc9d4ba381da62fd08b361bacd1e71e2a3d934d (diff) | |
parent | b3c692172e5b5241b028a98e1977f9fb12eeaf42 (diff) | |
download | nixlib-ee7984efa14902a2ddd820c937457667a4f40c6a.tar nixlib-ee7984efa14902a2ddd820c937457667a4f40c6a.tar.gz nixlib-ee7984efa14902a2ddd820c937457667a4f40c6a.tar.bz2 nixlib-ee7984efa14902a2ddd820c937457667a4f40c6a.tar.lz nixlib-ee7984efa14902a2ddd820c937457667a4f40c6a.tar.xz nixlib-ee7984efa14902a2ddd820c937457667a4f40c6a.tar.zst nixlib-ee7984efa14902a2ddd820c937457667a4f40c6a.zip |
Merge commit 'b3c692172e5b5241b028a98e1977f9fb12eeaf42'
Diffstat (limited to 'nixpkgs/pkgs/pkgs-lib')
-rw-r--r-- | nixpkgs/pkgs/pkgs-lib/formats.nix | 33 | ||||
-rw-r--r-- | nixpkgs/pkgs/pkgs-lib/tests/formats.nix | 28 |
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 ''; }; |