1
0
Fork 0
mirror of https://github.com/LnL7/nix-darwin.git synced 2025-03-13 20:30:02 +00:00

Use nixpkgs generators.toPlist for launchd service generation.

Fixes #93
This commit is contained in:
Thane Gill 2024-01-27 17:09:41 -08:00
parent 1e706ef323
commit 3a9755f98d
2 changed files with 1 additions and 59 deletions

View file

@ -1,6 +1,5 @@
{ config, lib, pkgs, ... }:
with import ./lib.nix { inherit lib; };
with lib;
let
@ -10,7 +9,7 @@ let
toEnvironmentText = name: value: {
name = "${value.serviceConfig.Label}.plist";
value.text = toPLIST value.serviceConfig;
value.text = generators.toPlist { } value.serviceConfig;
};
launchdConfig = import ./launchd.nix;

View file

@ -1,57 +0,0 @@
{ lib }:
with lib;
let
attrFilter = name: value: name != "_module" && value != null;
in
rec {
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));
}