From 3a9755f98dfc0589890ea54a870d9475e10b064f Mon Sep 17 00:00:00 2001 From: Thane Gill Date: Sat, 27 Jan 2024 17:09:41 -0800 Subject: [PATCH] Use nixpkgs generators.toPlist for launchd service generation. Fixes #93 --- modules/launchd/default.nix | 3 +- modules/launchd/lib.nix | 57 ------------------------------------- 2 files changed, 1 insertion(+), 59 deletions(-) delete mode 100644 modules/launchd/lib.nix diff --git a/modules/launchd/default.nix b/modules/launchd/default.nix index d1b2b50aa..5b24a9f6a 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 65fc03639..000000000 --- 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: '' - - - - '' + pprExpr "" x - + "\n"; - - 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 "" else ""); - pprInt = ind: x: pprLiteral ind "${toString x}"; - pprStr = ind: x: pprLiteral ind "${x}"; - pprKey = ind: x: pprLiteral ind "${x}"; - - pprIndent = ind: (pprExpr "\t${ind}"); - - pprItem = ind: concatMapStringsSep "\n" (pprIndent ind); - - pprList = ind: x: concatStringsSep "\n" [ - (pprLiteral ind "") - (pprItem ind x) - (pprLiteral ind "") - ]; - - pprAttrs = ind: x: concatStringsSep "\n" [ - (pprLiteral ind "") - (pprAttr ind x) - (pprLiteral ind "") - ]; - - pprAttr = ind: x: concatStringsSep "\n" (flatten (mapAttrsToList (name: value: optional (attrFilter name value) [ - (pprKey "\t${ind}" name) - (pprExpr "\t${ind}" value) - ]) x)); - -}