diff options
| author | Michael Hoang <Enzime@users.noreply.github.com> | 2024-01-28 11:24:25 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-28 11:24:25 +1000 |
| commit | 0108864c15bb68ad57d17fb2e7d3a3e025751d79 (patch) | |
| tree | 7489f1e99438520188f1f2a3c6d85beabffe4275 /modules | |
| parent | 1e706ef323de76236eb183d7784f3bd57255ec0b (diff) | |
| parent | 3a9755f98dfc0589890ea54a870d9475e10b064f (diff) | |
Merge pull request #860 from thanegill/use-nixpkgs-lib.generators.toPlist
Use nixpkgs generators.toPlist for launchd service generation
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/launchd/default.nix | 3 | ||||
| -rw-r--r-- | modules/launchd/lib.nix | 57 |
2 files changed, 1 insertions, 59 deletions
diff --git a/modules/launchd/default.nix b/modules/launchd/default.nix index d1b2b50..5b24a9f 100644 --- a/modules/launchd/default.nix +++ b/modules/launchd/default.nix @@ -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; diff --git a/modules/launchd/lib.nix b/modules/launchd/lib.nix deleted file mode 100644 index 65fc036..0000000 --- a/modules/launchd/lib.nix +++ /dev/null @@ -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)); - -} |
