pkgs.formats.plist: init

This commit is contained in:
Sizhe Zhao
2025-10-05 20:30:02 +08:00
parent 3627818f3c
commit 948a89c96b
2 changed files with 103 additions and 0 deletions
+25
View File
@@ -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);
};
}
+78
View File
@@ -1005,4 +1005,82 @@ runBuildTests {
</root>
'';
};
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 = ''
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
''\t<key>attrs</key>
''\t<dict>
''\t''\t<key>foo</key>
''\t''\t<integer>0</integer>
''\t</dict>
''\t<key>false</key>
''\t<false/>
''\t<key>float</key>
''\t<real>3.141000</real>
''\t<key>int</key>
''\t<integer>10</integer>
''\t<key>list</key>
''\t<array>
''\t''\t<integer>1</integer>
''\t''\t<string>hello</string>
''\t''\t<dict>
''\t''\t''\t<key>attrs</key>
''\t''\t''\t<dict>
''\t''\t''\t''\t<key>key</key>
''\t''\t''\t''\t<dict>
''\t''\t''\t''\t''\t<key>value</key>
''\t''\t''\t''\t''\t<array>
''\t''\t''\t''\t''\t''\t<array>
''\t''\t''\t''\t''\t''\t''\t<integer>1</integer>
''\t''\t''\t''\t''\t''\t''\t<integer>2</integer>
''\t''\t''\t''\t''\t''\t''\t<integer>3</integer>
''\t''\t''\t''\t''\t''\t</array>
''\t''\t''\t''\t''\t''\t<string>test</string>
''\t''\t''\t''\t''\t</array>
''\t''\t''\t''\t</dict>
''\t''\t''\t</dict>
''\t''\t</dict>
''\t</array>
''\t<key>path</key>
''\t<string>${toString ./testfile}</string>
''\t<key>str</key>
''\t<string>foo</string>
''\t<key>true</key>
''\t<true/>
</dict>
</plist>'';
};
}