diff --git a/.editorconfig b/.editorconfig index c9711d519408..ebb66b07945c 100644 --- a/.editorconfig +++ b/.editorconfig @@ -101,3 +101,7 @@ end_of_line = unset insert_final_newline = unset trim_trailing_whitespace = unset charset = unset + +[lib/tests/*.plist] +indent_style = tab +insert_final_newline = unset diff --git a/lib/generators.nix b/lib/generators.nix index c46ecca58c68..aace53e2f750 100644 --- a/lib/generators.nix +++ b/lib/generators.nix @@ -355,6 +355,7 @@ rec { # PLIST handling toPlist = {}: v: let isFloat = builtins.isFloat or (x: false); + isPath = x: builtins.typeOf x == "path"; expr = ind: x: with builtins; if x == null then "" else if isBool x then bool ind x else @@ -362,6 +363,7 @@ rec { if isString x then str ind x else if isList x then list ind x else if isAttrs x then attrs ind x else + if isPath x then str ind (toString x) else if isFloat x then float ind x else abort "generators.toPlist: should never happen (v = ${v})"; diff --git a/lib/tests/misc.nix b/lib/tests/misc.nix index ea3548b9514e..231f19c513eb 100644 --- a/lib/tests/misc.nix +++ b/lib/tests/misc.nix @@ -919,6 +919,30 @@ runTests { expected = "«foo»"; }; + testToPlist = + let + deriv = derivation { name = "test"; builder = "/bin/sh"; system = "aarch64-linux"; }; + in { + expr = mapAttrs (const (generators.toPlist { })) { + value = { + nested.values = rec { + int = 42; + float = 0.1337; + bool = true; + emptystring = ""; + string = "fn\${o}\"r\\d"; + newlinestring = "\n"; + path = /. + "/foo"; + null_ = null; + list = [ 3 4 "test" ]; + emptylist = []; + attrs = { foo = null; "foo b/ar" = "baz"; }; + emptyattrs = {}; + }; + }; + }; + expected = { value = builtins.readFile ./test-to-plist-expected.plist; }; + }; testToLuaEmptyAttrSet = { expr = generators.toLua {} {}; diff --git a/lib/tests/test-to-plist-expected.plist b/lib/tests/test-to-plist-expected.plist new file mode 100644 index 000000000000..df0528a60767 --- /dev/null +++ b/lib/tests/test-to-plist-expected.plist @@ -0,0 +1,46 @@ + + + + + nested + + values + + attrs + + foo b/ar + baz + + bool + + emptyattrs + + + + emptylist + + + + emptystring + + float + 0.133700 + int + 42 + list + + 3 + 4 + test + + newlinestring + + + path + /foo + string + fn${o}"r\d + + + + \ No newline at end of file