From d1a3298de0e309881faf459009cc723b8c47097e Mon Sep 17 00:00:00 2001 From: klchen0112 Date: Fri, 22 Nov 2024 23:35:22 +0800 Subject: [PATCH] emacs: add darwin service --- modules/services/emacs.nix | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/modules/services/emacs.nix b/modules/services/emacs.nix index d319abf01..fa0db187b 100644 --- a/modules/services/emacs.nix +++ b/modules/services/emacs.nix @@ -1,9 +1,6 @@ { config, lib, pkgs, ... }: - with lib; - let - cfg = config.services.emacs; emacsCfg = config.programs.emacs; emacsBinPath = "${cfg.package}/bin"; @@ -41,7 +38,6 @@ let # to work without wrapping it. socketDir = "%t/emacs"; socketPath = "${socketDir}/server"; - in { meta.maintainers = [ maintainers.tadfisher ]; @@ -112,12 +108,7 @@ in { }; config = mkIf cfg.enable (mkMerge [ - { - assertions = [ - (lib.hm.assertions.assertPlatform "services.emacs" pkgs - lib.platforms.linux) - ]; - + (mkIf pkgs.stdenv.isLinux { systemd.user.services.emacs = { Unit = { Description = "Emacs text editor"; @@ -190,9 +181,9 @@ in { }/bin/emacsclient "''${@:---create-frame}"''); }; }; - } + }) - (mkIf cfg.socketActivation.enable { + (mkIf (cfg.socketActivation.enable && pkgs.stdenv.isLinux) { systemd.user.sockets.emacs = { Unit = { Description = "Emacs text editor"; @@ -222,5 +213,20 @@ in { }; }; }) + + (mkIf pkgs.stdenv.isDarwin { + launchd.agents.emacs = { + enable = true; + config = { + ProgramArguments = [ "${cfg.package}/bin/emacs" "--fg-daemon" ] + ++ cfg.extraOptions; + RunAtLoad = true; + KeepAlive = { + Crashed = true; + SuccessfulExit = false; + }; + }; + }; + }) ]); }