summaryrefslogtreecommitdiffstats
path: root/lib/generators.nix
diff options
context:
space:
mode:
authorMatthew Bauer <mjbauer95@gmail.com>2018-06-28 11:11:19 -0400
committerMatthew Bauer <mjbauer95@gmail.com>2018-06-28 11:11:19 -0400
commitd361371d236c90bfb550e827124b5350deeadbda (patch)
treec4489ead44d1819064c481afe8275f49d5e2bad1 /lib/generators.nix
parent161414063fa9a87b61e5460c61ab1125c9e68e55 (diff)
generators: refactor toPLIST
Diffstat (limited to 'lib/generators.nix')
-rw-r--r--lib/generators.nix86
1 files changed, 43 insertions, 43 deletions
diff --git a/lib/generators.nix b/lib/generators.nix
index aab4498f9c64..143329815837 100644
--- a/lib/generators.nix
+++ b/lib/generators.nix
@@ -176,51 +176,51 @@ rec {
else abort "toPretty: should never happen (v = ${v})";
# PLIST handling
-
- toPLIST = x: ''
+ toPLIST = {}: v: let
+ pprExpr = ind: x: with builtins;
+ if isNull x then "" else
+ if isBool x then pprBool ind x else
+ if isInt x then pprInt ind x else
+ if isString x then pprStr ind x else
+ if isList x then pprList ind x else
+ if isAttrs x then pprAttrs ind x else
+ abort "pprExpr: should never happen (v = ${v})";
+
+ pprLiteral = ind: x: ind + x;
+
+ pprBool = ind: x: pprLiteral ind (if x then "<true/>" else "<false/>");
+ pprInt = ind: x: pprLiteral ind "<integer>${toString x}</integer>";
+ pprStr = ind: x: pprLiteral ind "<string>${x}</string>";
+ pprKey = ind: x: pprLiteral ind "<key>${x}</key>";
+
+ pprIndent = ind: pprExpr "\t${ind}";
+
+ pprItem = ind: libStr.concatMapStringsSep "\n" (pprIndent ind);
+
+ pprList = ind: x: libStr.concatStringsSep "\n" [
+ (pprLiteral ind "<array>")
+ (pprItem ind x)
+ (pprLiteral ind "</array>")
+ ];
+
+ pprAttrs = ind: x: libStr.concatStringsSep "\n" [
+ (pprLiteral ind "<dict>")
+ (pprAttr ind x)
+ (pprLiteral ind "</dict>")
+ ];
+
+ pprAttr = let attrFilter = name: value: name != "_module" && value != null;
+ in ind: x: libStr.concatStringsSep "\n" (lib.flatten (lib.mapAttrsToList
+ (name: value: lib.optional (attrFilter name value) [
+ (pprKey "\t${ind}" name)
+ (pprExpr "\t${ind}" value)
+ ]) x));
+
+ in ''
<?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">
- '' + pprExpr "" x
- + "\n</plist>";
-
- pprExpr = ind: x: with builtins;
- if isNull x then "" else
- if isBool x then pprBool ind x else
- if isInt x then pprInt ind x else
- if isString x then pprStr ind x else
- if isList x then pprList ind x else
- if isAttrs x then pprAttrs ind x else
- throw "invalid plist type";
-
- pprLiteral = ind: x: ind + x;
-
- pprBool = ind: x: pprLiteral ind (if x then "<true/>" else "<false/>");
- pprInt = ind: x: pprLiteral ind "<integer>${toString x}</integer>";
- pprStr = ind: x: pprLiteral ind "<string>${x}</string>";
- pprKey = ind: x: pprLiteral ind "<key>${x}</key>";
-
- pprIndent = ind: pprExpr "\t${ind}";
-
- pprItem = ind: libStr.concatMapStringsSep "\n" (pprIndent ind);
-
- pprList = ind: x: libStr.concatStringsSep "\n" [
- (pprLiteral ind "<array>")
- (pprItem ind x)
- (pprLiteral ind "</array>")
- ];
-
- pprAttrs = ind: x: libStr.concatStringsSep "\n" [
- (pprLiteral ind "<dict>")
- (pprAttr ind x)
- (pprLiteral ind "</dict>")
- ];
-
- attrFilter = name: value: name != "_module" && value != null;
-
- pprAttr = ind: x: libStr.concatStringsSep "\n" (lib.flatten (lib.mapAttrsToList (name: value: lib.optional (attrFilter name value) [
- (pprKey "\t${ind}" name)
- (pprExpr "\t${ind}" value)
- ]) x));
+ ${pprExpr "" v}
+ </plist>'';
}