From f5182ffc4211860348fc7c78e0ba3a9d36f13aeb Mon Sep 17 00:00:00 2001 From: Rodney Lorrimar Date: Thu, 9 Nov 2023 17:27:45 +0800 Subject: [PATCH] emacs: Fix socket activation --- modules/services/emacs.nix | 14 +++++++++++++- .../services/emacs/emacs-socket-emacs.socket | 2 ++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/modules/services/emacs.nix b/modules/services/emacs.nix index 394e3659..d319abf0 100644 --- a/modules/services/emacs.nix +++ b/modules/services/emacs.nix @@ -205,9 +205,21 @@ in { FileDescriptorName = "server"; SocketMode = "0600"; DirectoryMode = "0700"; + # This prevents the service from immediately starting again + # after being stopped, due to the function + # `server-force-stop' present in `kill-emacs-hook', which + # calls `server-running-p', which opens the socket file. + FlushPending = true; }; - Install = { WantedBy = [ "sockets.target" ]; }; + Install = { + WantedBy = [ "sockets.target" ]; + # Adding this Requires= dependency ensures that systemd + # manages the socket file, in the case where the service is + # started when the socket is stopped. + # The socket unit is implicitly ordered before the service. + RequiredBy = [ "emacs.service" ]; + }; }; }) ]); diff --git a/tests/modules/services/emacs/emacs-socket-emacs.socket b/tests/modules/services/emacs/emacs-socket-emacs.socket index 7fffcb0d..843d87fe 100644 --- a/tests/modules/services/emacs/emacs-socket-emacs.socket +++ b/tests/modules/services/emacs/emacs-socket-emacs.socket @@ -1,9 +1,11 @@ [Install] +RequiredBy=emacs.service WantedBy=sockets.target [Socket] DirectoryMode=0700 FileDescriptorName=server +FlushPending=true ListenStream=%t/emacs/server SocketMode=0600