1
0
mirror of https://github.com/nix-community/home-manager synced 2024-06-18 12:38:30 +02:00

services/emacs: Prevent deletion of socket file

When running a socket-activated emacs service, we don't want emacs to
remove the socket file after exiting, because then subsequent
invocations of `emacsclient` won't be able to use the socket to start
emacs.service again.
This commit is contained in:
Rodney Lorrimar 2021-05-30 12:40:58 +10:00 committed by Robert Helgesson
parent ac82c036d8
commit 5060262b79
No known key found for this signature in database
GPG Key ID: 36BDAA14C2797E89
4 changed files with 13 additions and 3 deletions

View File

@ -35,7 +35,8 @@ let
# Match the default socket path for the Emacs version so emacsclient continues
# to work without wrapping it.
socketPath = "%t/emacs/server";
socketDir = "%t/emacs";
socketPath = "${socketDir}/server";
in {
meta.maintainers = [ maintainers.tadfisher ];
@ -112,6 +113,13 @@ in {
SuccessExitStatus = 15;
Restart = "on-failure";
} // optionalAttrs (cfg.socketActivation.enable) {
# Use read-only directory permissions to prevent emacs from
# deleting systemd's socket file before exiting.
ExecStartPost =
"${pkgs.coreutils}/bin/chmod --changes -w ${socketDir}";
ExecStopPost =
"${pkgs.coreutils}/bin/chmod --changes +w ${socketDir}";
};
} // optionalAttrs (!cfg.socketActivation.enable) {
Install = { WantedBy = [ "default.target" ]; };

View File

@ -31,7 +31,7 @@ in {
assertFileContent home-files/.config/systemd/user/emacs.service \
${
pkgs.substituteAll {
inherit (pkgs) runtimeShell;
inherit (pkgs) runtimeShell coreutils;
src = ./emacs-socket-emacs.service;
}
}

View File

@ -31,7 +31,7 @@ in {
assertFileContent home-files/.config/systemd/user/emacs.service \
${
pkgs.substituteAll {
inherit (pkgs) runtimeShell;
inherit (pkgs) runtimeShell coreutils;
src = ./emacs-socket-emacs.service;
}
}

View File

@ -1,5 +1,7 @@
[Service]
ExecStart=@runtimeShell@ -l -c "@emacs@/bin/emacs --fg-daemon='%t/emacs/server'"
ExecStartPost=@coreutils@/bin/chmod --changes -w %t/emacs
ExecStopPost=@coreutils@/bin/chmod --changes +w %t/emacs
Restart=on-failure
SuccessExitStatus=15
Type=notify