mirror of
https://github.com/LnL7/nix-darwin.git
synced 2024-12-14 11:57:34 +00:00
launchd: properly generate plist files
This commit is contained in:
parent
4322078270
commit
7ac68a8629
2 changed files with 47 additions and 67 deletions
|
@ -35,56 +35,7 @@ let
|
|||
config = {
|
||||
serviceConfig.Label = mkDefault "org.nixos.${name}";
|
||||
|
||||
plist = pkgs.writeText "${config.serviceConfig.Label}.plist" (''
|
||||
<?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>
|
||||
'' + xmlMapAttr xmlString "Label" config.serviceConfig.Label
|
||||
+ xmlMapAttr xmlBool "Disabled" config.serviceConfig.Disabled
|
||||
+ xmlMapAttr xmlString "UserName" config.serviceConfig.UserName
|
||||
+ xmlMapAttr xmlString "GroupName" config.serviceConfig.GroupName
|
||||
+ xmlMapAttr (xmlMapAttrs xmlBool) "inetdCompatibility" config.serviceConfig.inetdCompatibility
|
||||
+ xmlMapAttr (xmlMap xmlString) "LimitLoadToHosts" config.serviceConfig.LimitLoadToHosts
|
||||
+ xmlMapAttr (xmlMap xmlString) "LimitLoadFromHosts" config.serviceConfig.LimitLoadFromHosts
|
||||
+ xmlMapAttr xmlString "LimitLoadToSessionType" config.serviceConfig.LimitLoadToSessionType
|
||||
+ xmlMapAttr xmlString "Program" config.serviceConfig.Program
|
||||
+ xmlMapAttr (xmlMap xmlString) "ProgramArguments" config.serviceConfig.ProgramArguments
|
||||
+ xmlMapAttr xmlBool "EnableGlobbing" config.serviceConfig.EnableGlobbing
|
||||
+ xmlMapAttr xmlBool "EnableTransactions" config.serviceConfig.EnableTransactions
|
||||
+ xmlMapAttr xmlBool "OnDemand" config.serviceConfig.OnDemand
|
||||
+ xmlMapAttr xmlBool "KeepAlive" config.serviceConfig.KeepAlive
|
||||
+ xmlMapAttr xmlBool "RunAtLoad" config.serviceConfig.RunAtLoad
|
||||
+ xmlMapAttr xmlString "RootDirectory" config.serviceConfig.RootDirectory
|
||||
+ xmlMapAttr xmlString "WorkingDirectory" config.serviceConfig.WorkingDirectory
|
||||
+ xmlMapAttr (xmlMapAttrs xmlString) "EnvironmentVariables" config.serviceConfig.EnvironmentVariables
|
||||
+ xmlMapAttr xmlInt "Umask" config.serviceConfig.Umask
|
||||
+ xmlMapAttr xmlInt "TimeOut" config.serviceConfig.TimeOut
|
||||
+ xmlMapAttr xmlInt "ExitTimeOut" config.serviceConfig.ExitTimeOut
|
||||
+ xmlMapAttr xmlInt "ThrottleInterval" config.serviceConfig.ThrottleInterval
|
||||
+ xmlMapAttr xmlBool "InitGroups" config.serviceConfig.InitGroups
|
||||
+ xmlMapAttr (xmlMap xmlString) "WatchPaths" config.serviceConfig.WatchPaths
|
||||
+ xmlMapAttr (xmlMap xmlString) "QueueDirectories" config.serviceConfig.QueueDirectories
|
||||
+ xmlMapAttr xmlBool "StartOnMount" config.serviceConfig.StartOnMount
|
||||
+ xmlMapAttr xmlInt "StartInterval" config.serviceConfig.StartInterval
|
||||
+ xmlMapAttr (xmlMapAttrs xmlInt) "StartCalendarInterval" config.serviceConfig.StartCalendarInterval
|
||||
+ xmlMapAttr xmlString "StandardInPath" config.serviceConfig.StandardInPath
|
||||
+ xmlMapAttr xmlString "StandardOutPath" config.serviceConfig.StandardOutPath
|
||||
+ xmlMapAttr xmlString "StandardErrorPath" config.serviceConfig.StandardErrorPath
|
||||
+ xmlMapAttr xmlBool "Debug" config.serviceConfig.Debug
|
||||
+ xmlMapAttr xmlBool "WaitForDebugger" config.serviceConfig.WaitForDebugger
|
||||
+ xmlMapAttr (xmlMapAttrs xmlInt) "SoftResourceLimits" config.serviceConfig.SoftResourceLimits
|
||||
+ xmlMapAttr (xmlMapAttrs xmlInt) "HardResourceLimits" config.serviceConfig.HardResourceLimits
|
||||
+ xmlMapAttr xmlInt "Nice" config.serviceConfig.Nice
|
||||
+ xmlMapAttr xmlString "ProcessType" config.serviceConfig.ProcessType
|
||||
+ xmlMapAttr xmlBool "AbandonProcessGroup" config.serviceConfig.AbandonProcessGroup
|
||||
+ xmlMapAttr xmlBool "LowPriorityIO" config.serviceConfig.LowPriorityIO
|
||||
+ xmlMapAttr xmlBool "LaunchOnlyOnce" config.serviceConfig.LaunchOnlyOnce
|
||||
+ xmlMapAttr (xmlMapAttrs xmlBool) "MachServices" config.serviceConfig.MachServices
|
||||
+ ''
|
||||
</dict>
|
||||
</plist>
|
||||
'');
|
||||
plist = pkgs.writeText "${config.serviceConfig.Label}.plist" (toPLIST config.serviceConfig);
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -2,27 +2,56 @@
|
|||
|
||||
with lib;
|
||||
|
||||
let
|
||||
|
||||
attrFilter = name: value: name != "_module" && value != null;
|
||||
|
||||
in
|
||||
|
||||
rec {
|
||||
|
||||
xmlMap = f: xs: ''
|
||||
<array>
|
||||
${concatMapStringsSep "\n" f xs}
|
||||
</array>
|
||||
'';
|
||||
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>";
|
||||
|
||||
xmlMapAttrs = f: attr: ''
|
||||
<dict>
|
||||
${concatStringsSep "\n" (mapAttrsFlatten (xmlMapAttr f) attr)}
|
||||
</dict>
|
||||
'';
|
||||
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";
|
||||
|
||||
xmlMapAttr = f: n: v: optionalString (v != null) ''
|
||||
<key>${n}</key>
|
||||
${f v}
|
||||
'';
|
||||
pprLiteral = ind: x: ind + x;
|
||||
|
||||
xmlBool = x: if x then "<true/>" else "<false/>";
|
||||
xmlInt = x: "<integer>${toString x}</integer>";
|
||||
xmlString = x: "<string>${x}</string>";
|
||||
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));
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue