diff --git a/pkgs/pkgs-lib/formats.nix b/pkgs/pkgs-lib/formats.nix index f83a00b9e610..14fca4c3d395 100644 --- a/pkgs/pkgs-lib/formats.nix +++ b/pkgs/pkgs-lib/formats.nix @@ -1125,4 +1125,29 @@ optionalAttrs allowAliases aliases else throw "pkgs.formats.xml: Unknown format: ${format}"; + plist = + { + escape ? true, + }: + { + type = + let + valueType = + nullOr (oneOf [ + bool + int + float + str + path + (attrsOf valueType) + (listOf valueType) + ]) + // { + description = "Property list (plist) value"; + }; + in + valueType; + + generate = name: value: pkgs.writeText name (lib.generators.toPlist { inherit escape; } value); + }; } diff --git a/pkgs/pkgs-lib/tests/formats.nix b/pkgs/pkgs-lib/tests/formats.nix index 9afd9d783b65..12fbd2ddd4cc 100644 --- a/pkgs/pkgs-lib/tests/formats.nix +++ b/pkgs/pkgs-lib/tests/formats.nix @@ -1005,4 +1005,82 @@ runBuildTests { ''; }; + + PlistGenerate = shouldPass { + format = formats.plist { }; + input = { + null = null; + false = false; + true = true; + int = 10; + float = 3.141; + str = "foo"; + attrs.foo = 0; + list = [ + 1 + "hello" + { + attrs = { + key = { + value = [ + [ + 1 + 2 + 3 + ] + "test" + ]; + }; + }; + } + ]; + path = ./testfile; + }; + expected = '' + + + + + ''\tattrs + ''\t + ''\t''\tfoo + ''\t''\t0 + ''\t + ''\tfalse + ''\t + ''\tfloat + ''\t3.141000 + ''\tint + ''\t10 + ''\tlist + ''\t + ''\t''\t1 + ''\t''\thello + ''\t''\t + ''\t''\t''\tattrs + ''\t''\t''\t + ''\t''\t''\t''\tkey + ''\t''\t''\t''\t + ''\t''\t''\t''\t''\tvalue + ''\t''\t''\t''\t''\t + ''\t''\t''\t''\t''\t''\t + ''\t''\t''\t''\t''\t''\t''\t1 + ''\t''\t''\t''\t''\t''\t''\t2 + ''\t''\t''\t''\t''\t''\t''\t3 + ''\t''\t''\t''\t''\t''\t + ''\t''\t''\t''\t''\t''\ttest + ''\t''\t''\t''\t''\t + ''\t''\t''\t''\t + ''\t''\t''\t + ''\t''\t + ''\t + ''\tpath + ''\t${toString ./testfile} + ''\tstr + ''\tfoo + ''\ttrue + ''\t + + ''; + }; }