diff options
author | toonn <toonn@toonn.io> | 2023-05-05 21:15:23 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-05 21:15:23 +0200 |
commit | e31c8b22ddb121f8840e2c94fa25557b572e3bb5 (patch) | |
tree | bcb7505eec51480dfee58ae2a54203bd6954a969 | |
parent | 7d76bc7e818a419282c6502993864eb2ae8e07a1 (diff) | |
parent | e932e98437ea9184365233bad439860c795f65a1 (diff) | |
download | nixpkgs-e31c8b22ddb121f8840e2c94fa25557b572e3bb5.tar nixpkgs-e31c8b22ddb121f8840e2c94fa25557b572e3bb5.tar.gz nixpkgs-e31c8b22ddb121f8840e2c94fa25557b572e3bb5.tar.bz2 nixpkgs-e31c8b22ddb121f8840e2c94fa25557b572e3bb5.tar.lz nixpkgs-e31c8b22ddb121f8840e2c94fa25557b572e3bb5.tar.xz nixpkgs-e31c8b22ddb121f8840e2c94fa25557b572e3bb5.tar.zst nixpkgs-e31c8b22ddb121f8840e2c94fa25557b572e3bb5.zip |
Merge pull request #223407 from AngryAnt/toplist-path
lib.toPlist: Add support for path values
-rw-r--r-- | .editorconfig | 4 | ||||
-rw-r--r-- | lib/generators.nix | 2 | ||||
-rw-r--r-- | lib/tests/misc.nix | 24 | ||||
-rw-r--r-- | lib/tests/test-to-plist-expected.plist | 46 |
4 files changed, 76 insertions, 0 deletions
diff --git a/.editorconfig b/.editorconfig index c9711d51940..ebb66b07945 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 c46ecca58c6..aace53e2f75 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 ea3548b9514..231f19c513e 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 00000000000..df0528a6076 --- /dev/null +++ b/lib/tests/test-to-plist-expected.plist @@ -0,0 +1,46 @@ +<?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> + <key>nested</key> + <dict> + <key>values</key> + <dict> + <key>attrs</key> + <dict> + <key>foo b/ar</key> + <string>baz</string> + </dict> + <key>bool</key> + <true/> + <key>emptyattrs</key> + <dict> + + </dict> + <key>emptylist</key> + <array> + + </array> + <key>emptystring</key> + <string></string> + <key>float</key> + <real>0.133700</real> + <key>int</key> + <integer>42</integer> + <key>list</key> + <array> + <integer>3</integer> + <integer>4</integer> + <string>test</string> + </array> + <key>newlinestring</key> + <string> +</string> + <key>path</key> + <string>/foo</string> + <key>string</key> + <string>fn${o}"r\d</string> + </dict> + </dict> +</dict> +</plist> \ No newline at end of file |