1
0
Fork 0
mirror of https://github.com/LnL7/nix-darwin.git synced 2024-12-14 11:57:34 +00:00
nix-darwin/modules/launchd/lib.nix

58 lines
1.4 KiB
Nix
Raw Normal View History

2016-11-01 20:25:22 +00:00
{ lib }:
with lib;
2016-11-30 22:12:06 +00:00
let
attrFilter = name: value: name != "_module" && value != null;
in
2016-11-01 20:25:22 +00:00
rec {
2016-11-30 22:12:06 +00:00
toPLIST = x: ''
<?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:
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: concatMapStringsSep "\n" (pprIndent ind);
pprList = ind: x: concatStringsSep "\n" [
(pprLiteral ind "<array>")
(pprItem ind x)
(pprLiteral ind "</array>")
];
pprAttrs = ind: x: concatStringsSep "\n" [
(pprLiteral ind "<dict>")
(pprAttr ind x)
(pprLiteral ind "</dict>")
];
pprAttr = ind: x: concatStringsSep "\n" (flatten (mapAttrsToList (name: value: optional (attrFilter name value) [
(pprKey "\t${ind}" name)
(pprExpr "\t${ind}" value)
]) x));
2016-11-01 20:25:22 +00:00
}