mirror of
https://github.com/nix-community/home-manager
synced 2025-01-11 11:39:49 +01:00
services/emacs: Update systemd definitions, drop Emacs 26 support
Emacs 27 added Type=notify support and updated the service definition to remove the use of `emacsclient' to kill the service. Emacs 28 changes the `StartupWMClass' in emacsclient.desktop to `Emacsd'. Update our emacs.service and emacsclient.desktop definitions to match upstream changes. When killing emacs.service, the socket is removed, and subsequently starting the service manually results in a service without a socket. Prevent this by adding `RefuseManualStart=true' to the service's Unit definition. Drop Emacs 26 support as it is no longer shipped in nixpkgs. Update the tests to verify the following configuration scenarios: - Emacs version: 27, 28 - Socket activation: disabled, enabled
This commit is contained in:
parent
e9ed9c2e11
commit
ac82c036d8
13 changed files with 97 additions and 67 deletions
|
@ -9,6 +9,9 @@ let
|
||||||
emacsBinPath = "${cfg.package}/bin";
|
emacsBinPath = "${cfg.package}/bin";
|
||||||
emacsVersion = getVersion cfg.package;
|
emacsVersion = getVersion cfg.package;
|
||||||
|
|
||||||
|
clientWMClass =
|
||||||
|
if versionAtLeast emacsVersion "28" then "Emacsd" else "Emacs";
|
||||||
|
|
||||||
# Adapted from upstream emacs.desktop
|
# Adapted from upstream emacs.desktop
|
||||||
clientDesktopItem = pkgs.writeTextDir "share/applications/emacsclient.desktop"
|
clientDesktopItem = pkgs.writeTextDir "share/applications/emacsclient.desktop"
|
||||||
(generators.toINI { } {
|
(generators.toINI { } {
|
||||||
|
@ -24,26 +27,15 @@ let
|
||||||
GenericName = "Text Editor";
|
GenericName = "Text Editor";
|
||||||
MimeType =
|
MimeType =
|
||||||
"text/english;text/plain;text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-chdr;text/x-csrc;text/x-java;text/x-moc;text/x-pascal;text/x-tcl;text/x-tex;application/x-shellscript;text/x-c;text/x-c++;";
|
"text/english;text/plain;text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-chdr;text/x-csrc;text/x-java;text/x-moc;text/x-pascal;text/x-tcl;text/x-tex;application/x-shellscript;text/x-c;text/x-c++;";
|
||||||
Categories = "Utility;TextEditor;";
|
Categories = "Development;TextEditor;";
|
||||||
StartupWMClass = "Emacs";
|
Keywords = "Text;Editor;";
|
||||||
|
StartupWMClass = clientWMClass;
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
# Match the default socket path for the Emacs version so emacsclient continues
|
# Match the default socket path for the Emacs version so emacsclient continues
|
||||||
# to work without wrapping it. It might be worthwhile to allow customizing the
|
# to work without wrapping it.
|
||||||
# socket path, but we would want to wrap emacsclient in the user profile to
|
socketPath = "%t/emacs/server";
|
||||||
# connect to the alternative socket by default for Emacs 26, and set
|
|
||||||
# EMACS_SOCKET_NAME for Emacs 27.
|
|
||||||
#
|
|
||||||
# As systemd doesn't perform variable expansion for the ListenStream param, we
|
|
||||||
# would also have to solve the problem of matching the shell path to the path
|
|
||||||
# used in the socket unit, which would likely involve templating. It seems of
|
|
||||||
# little value for the most common use case of one Emacs daemon per user
|
|
||||||
# session.
|
|
||||||
socketPath = if versionAtLeast emacsVersion "27" then
|
|
||||||
"%t/emacs/server"
|
|
||||||
else
|
|
||||||
"%T/emacs%U/server";
|
|
||||||
|
|
||||||
in {
|
in {
|
||||||
meta.maintainers = [ maintainers.tadfisher ];
|
meta.maintainers = [ maintainers.tadfisher ];
|
||||||
|
@ -82,24 +74,25 @@ in {
|
||||||
|
|
||||||
config = mkIf cfg.enable (mkMerge [
|
config = mkIf cfg.enable (mkMerge [
|
||||||
{
|
{
|
||||||
assertions = [{
|
|
||||||
assertion = cfg.socketActivation.enable
|
|
||||||
-> versionAtLeast emacsVersion "26";
|
|
||||||
message = "Socket activation requires Emacs 26 or newer.";
|
|
||||||
}];
|
|
||||||
|
|
||||||
systemd.user.services.emacs = {
|
systemd.user.services.emacs = {
|
||||||
Unit = {
|
Unit = {
|
||||||
Description = "Emacs: the extensible, self-documenting text editor";
|
Description = "Emacs text editor";
|
||||||
Documentation =
|
Documentation =
|
||||||
"info:emacs man:emacs(1) https://gnu.org/software/emacs/";
|
"info:emacs man:emacs(1) https://gnu.org/software/emacs/";
|
||||||
|
|
||||||
# Avoid killing the Emacs session, which may be full of
|
# Avoid killing the Emacs session, which may be full of
|
||||||
# unsaved buffers.
|
# unsaved buffers.
|
||||||
X-RestartIfChanged = false;
|
X-RestartIfChanged = false;
|
||||||
|
} // optionalAttrs (cfg.socketActivation.enable) {
|
||||||
|
# Emacs deletes its socket when shutting down, which systemd doesn't
|
||||||
|
# handle, resulting in a server without a socket.
|
||||||
|
# See https://github.com/nix-community/home-manager/issues/2018
|
||||||
|
RefuseManualStart = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
Service = {
|
Service = {
|
||||||
|
Type = "notify";
|
||||||
|
|
||||||
# We wrap ExecStart in a login shell so Emacs starts with the user's
|
# We wrap ExecStart in a login shell so Emacs starts with the user's
|
||||||
# environment, most importantly $PATH and $NIX_PROFILES. It may be
|
# environment, most importantly $PATH and $NIX_PROFILES. It may be
|
||||||
# worth investigating a more targeted approach for user services to
|
# worth investigating a more targeted approach for user services to
|
||||||
|
@ -113,9 +106,11 @@ in {
|
||||||
optionalString cfg.socketActivation.enable
|
optionalString cfg.socketActivation.enable
|
||||||
"=${escapeShellArg socketPath}"
|
"=${escapeShellArg socketPath}"
|
||||||
}"'';
|
}"'';
|
||||||
# We use '(kill-emacs 0)' to avoid exiting with a failure code, which
|
|
||||||
# would restart the service immediately.
|
# Emacs will exit with status 15 after having received SIGTERM, which
|
||||||
ExecStop = "${emacsBinPath}/emacsclient --eval '(kill-emacs 0)'";
|
# is the default "KillSignal" value systemd uses to stop services.
|
||||||
|
SuccessExitStatus = 15;
|
||||||
|
|
||||||
Restart = "on-failure";
|
Restart = "on-failure";
|
||||||
};
|
};
|
||||||
} // optionalAttrs (!cfg.socketActivation.enable) {
|
} // optionalAttrs (!cfg.socketActivation.enable) {
|
||||||
|
@ -128,7 +123,7 @@ in {
|
||||||
(mkIf cfg.socketActivation.enable {
|
(mkIf cfg.socketActivation.enable {
|
||||||
systemd.user.sockets.emacs = {
|
systemd.user.sockets.emacs = {
|
||||||
Unit = {
|
Unit = {
|
||||||
Description = "Emacs: the extensible, self-documenting text editor";
|
Description = "Emacs text editor";
|
||||||
Documentation =
|
Documentation =
|
||||||
"info:emacs man:emacs(1) https://gnu.org/software/emacs/";
|
"info:emacs man:emacs(1) https://gnu.org/software/emacs/";
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
emacs-service = ./emacs-service.nix;
|
emacs-service-27 = ./emacs-service-27.nix;
|
||||||
emacs-socket-26 = ./emacs-socket-26.nix;
|
emacs-service-28 = ./emacs-service-28.nix;
|
||||||
emacs-socket-27 = ./emacs-socket-27.nix;
|
emacs-socket-27 = ./emacs-socket-27.nix;
|
||||||
|
emacs-socket-28 = ./emacs-socket-28.nix;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
[Desktop Entry]
|
[Desktop Entry]
|
||||||
Categories=Utility;TextEditor;
|
Categories=Development;TextEditor;
|
||||||
Comment=Edit text
|
Comment=Edit text
|
||||||
Exec=@emacs@/bin/emacsclient -c %F
|
Exec=@emacs@/bin/emacsclient -c %F
|
||||||
GenericName=Text Editor
|
GenericName=Text Editor
|
||||||
Icon=emacs
|
Icon=emacs
|
||||||
|
Keywords=Text;Editor;
|
||||||
MimeType=text/english;text/plain;text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-chdr;text/x-csrc;text/x-java;text/x-moc;text/x-pascal;text/x-tcl;text/x-tex;application/x-shellscript;text/x-c;text/x-c++;
|
MimeType=text/english;text/plain;text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-chdr;text/x-csrc;text/x-java;text/x-moc;text/x-pascal;text/x-tcl;text/x-tex;application/x-shellscript;text/x-c;text/x-c++;
|
||||||
Name=Emacs Client
|
Name=Emacs Client
|
||||||
StartupWMClass=Emacs
|
StartupWMClass=Emacs
|
12
tests/modules/services/emacs/emacs-28-emacsclient.desktop
Normal file
12
tests/modules/services/emacs/emacs-28-emacsclient.desktop
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
[Desktop Entry]
|
||||||
|
Categories=Development;TextEditor;
|
||||||
|
Comment=Edit text
|
||||||
|
Exec=@emacs@/bin/emacsclient -c %F
|
||||||
|
GenericName=Text Editor
|
||||||
|
Icon=emacs
|
||||||
|
Keywords=Text;Editor;
|
||||||
|
MimeType=text/english;text/plain;text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-chdr;text/x-csrc;text/x-java;text/x-moc;text/x-pascal;text/x-tcl;text/x-tex;application/x-shellscript;text/x-c;text/x-c++;
|
||||||
|
Name=Emacs Client
|
||||||
|
StartupWMClass=Emacsd
|
||||||
|
Terminal=false
|
||||||
|
Type=Application
|
|
@ -6,7 +6,7 @@ with lib;
|
||||||
config = {
|
config = {
|
||||||
nixpkgs.overlays = [
|
nixpkgs.overlays = [
|
||||||
(self: super: rec {
|
(self: super: rec {
|
||||||
emacs = pkgs.writeShellScriptBin "dummy-emacs" "" // {
|
emacs = pkgs.writeShellScriptBin "dummy-emacs-27.2" "" // {
|
||||||
outPath = "@emacs@";
|
outPath = "@emacs@";
|
||||||
};
|
};
|
||||||
emacsPackagesFor = _:
|
emacsPackagesFor = _:
|
||||||
|
@ -31,7 +31,7 @@ with lib;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assertFileContent home-path/share/applications/emacsclient.desktop \
|
assertFileContent home-path/share/applications/emacsclient.desktop \
|
||||||
${./emacs-emacsclient.desktop}
|
${./emacs-27-emacsclient.desktop}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
}
|
}
|
37
tests/modules/services/emacs/emacs-service-28.nix
Normal file
37
tests/modules/services/emacs/emacs-service-28.nix
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
|
with lib;
|
||||||
|
|
||||||
|
{
|
||||||
|
config = {
|
||||||
|
nixpkgs.overlays = [
|
||||||
|
(self: super: rec {
|
||||||
|
emacs = pkgs.writeShellScriptBin "dummy-emacs-28.0.5" "" // {
|
||||||
|
outPath = "@emacs@";
|
||||||
|
};
|
||||||
|
emacsPackagesFor = _:
|
||||||
|
makeScope super.newScope (_: { emacsWithPackages = _: emacs; });
|
||||||
|
})
|
||||||
|
];
|
||||||
|
|
||||||
|
programs.emacs.enable = true;
|
||||||
|
services.emacs.enable = true;
|
||||||
|
services.emacs.client.enable = true;
|
||||||
|
|
||||||
|
nmt.script = ''
|
||||||
|
assertPathNotExists home-files/.config/systemd/user/emacs.socket
|
||||||
|
assertFileExists home-files/.config/systemd/user/emacs.service
|
||||||
|
assertFileExists home-path/share/applications/emacsclient.desktop
|
||||||
|
|
||||||
|
assertFileContent home-files/.config/systemd/user/emacs.service \
|
||||||
|
${
|
||||||
|
pkgs.substituteAll {
|
||||||
|
inherit (pkgs) runtimeShell;
|
||||||
|
src = ./emacs-service-emacs.service;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertFileContent home-path/share/applications/emacsclient.desktop \
|
||||||
|
${./emacs-28-emacsclient.desktop}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
|
@ -3,10 +3,11 @@ WantedBy=default.target
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
ExecStart=@runtimeShell@ -l -c "@emacs@/bin/emacs --fg-daemon"
|
ExecStart=@runtimeShell@ -l -c "@emacs@/bin/emacs --fg-daemon"
|
||||||
ExecStop=@emacs@/bin/emacsclient --eval '(kill-emacs 0)'
|
|
||||||
Restart=on-failure
|
Restart=on-failure
|
||||||
|
SuccessExitStatus=15
|
||||||
|
Type=notify
|
||||||
|
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=Emacs: the extensible, self-documenting text editor
|
Description=Emacs text editor
|
||||||
Documentation=info:emacs man:emacs(1) https://gnu.org/software/emacs/
|
Documentation=info:emacs man:emacs(1) https://gnu.org/software/emacs/
|
||||||
X-RestartIfChanged=false
|
X-RestartIfChanged=false
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
[Service]
|
|
||||||
ExecStart=@runtimeShell@ -l -c "@emacs@/bin/emacs --fg-daemon='%T/emacs%U/server'"
|
|
||||||
ExecStop=@emacs@/bin/emacsclient --eval '(kill-emacs 0)'
|
|
||||||
Restart=on-failure
|
|
||||||
|
|
||||||
[Unit]
|
|
||||||
Description=Emacs: the extensible, self-documenting text editor
|
|
||||||
Documentation=info:emacs man:emacs(1) https://gnu.org/software/emacs/
|
|
||||||
X-RestartIfChanged=false
|
|
|
@ -1,12 +0,0 @@
|
||||||
[Install]
|
|
||||||
WantedBy=sockets.target
|
|
||||||
|
|
||||||
[Socket]
|
|
||||||
DirectoryMode=0700
|
|
||||||
FileDescriptorName=server
|
|
||||||
ListenStream=%T/emacs%U/server
|
|
||||||
SocketMode=0600
|
|
||||||
|
|
||||||
[Unit]
|
|
||||||
Description=Emacs: the extensible, self-documenting text editor
|
|
||||||
Documentation=info:emacs man:emacs(1) https://gnu.org/software/emacs/
|
|
|
@ -8,7 +8,7 @@ in {
|
||||||
config = {
|
config = {
|
||||||
nixpkgs.overlays = [
|
nixpkgs.overlays = [
|
||||||
(self: super: rec {
|
(self: super: rec {
|
||||||
emacs = pkgs.writeShellScriptBin "dummy-emacs-27.0.91" "" // {
|
emacs = pkgs.writeShellScriptBin "dummy-emacs-27.2" "" // {
|
||||||
outPath = "@emacs@";
|
outPath = "@emacs@";
|
||||||
};
|
};
|
||||||
emacsPackagesFor = _:
|
emacsPackagesFor = _:
|
||||||
|
@ -27,16 +27,16 @@ in {
|
||||||
assertFileExists home-path/share/applications/emacsclient.desktop
|
assertFileExists home-path/share/applications/emacsclient.desktop
|
||||||
|
|
||||||
assertFileContent home-files/.config/systemd/user/emacs.socket \
|
assertFileContent home-files/.config/systemd/user/emacs.socket \
|
||||||
${./emacs-socket-27-emacs.socket}
|
${./emacs-socket-emacs.socket}
|
||||||
assertFileContent home-files/.config/systemd/user/emacs.service \
|
assertFileContent home-files/.config/systemd/user/emacs.service \
|
||||||
${
|
${
|
||||||
pkgs.substituteAll {
|
pkgs.substituteAll {
|
||||||
inherit (pkgs) runtimeShell;
|
inherit (pkgs) runtimeShell;
|
||||||
src = ./emacs-socket-27-emacs.service;
|
src = ./emacs-socket-emacs.service;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assertFileContent home-path/share/applications/emacsclient.desktop \
|
assertFileContent home-path/share/applications/emacsclient.desktop \
|
||||||
${./emacs-emacsclient.desktop}
|
${./emacs-27-emacsclient.desktop}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,13 @@
|
||||||
|
|
||||||
with lib;
|
with lib;
|
||||||
|
|
||||||
{
|
let
|
||||||
|
|
||||||
|
in {
|
||||||
config = {
|
config = {
|
||||||
nixpkgs.overlays = [
|
nixpkgs.overlays = [
|
||||||
(self: super: rec {
|
(self: super: rec {
|
||||||
emacs = pkgs.writeShellScriptBin "dummy-emacs-26.3" "" // {
|
emacs = pkgs.writeShellScriptBin "dummy-emacs-28.0.5" "" // {
|
||||||
outPath = "@emacs@";
|
outPath = "@emacs@";
|
||||||
};
|
};
|
||||||
emacsPackagesFor = _:
|
emacsPackagesFor = _:
|
||||||
|
@ -25,16 +27,16 @@ with lib;
|
||||||
assertFileExists home-path/share/applications/emacsclient.desktop
|
assertFileExists home-path/share/applications/emacsclient.desktop
|
||||||
|
|
||||||
assertFileContent home-files/.config/systemd/user/emacs.socket \
|
assertFileContent home-files/.config/systemd/user/emacs.socket \
|
||||||
${./emacs-socket-26-emacs.socket}
|
${./emacs-socket-emacs.socket}
|
||||||
assertFileContent home-files/.config/systemd/user/emacs.service \
|
assertFileContent home-files/.config/systemd/user/emacs.service \
|
||||||
${
|
${
|
||||||
pkgs.substituteAll {
|
pkgs.substituteAll {
|
||||||
inherit (pkgs) runtimeShell;
|
inherit (pkgs) runtimeShell;
|
||||||
src = ./emacs-socket-26-emacs.service;
|
src = ./emacs-socket-emacs.service;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assertFileContent home-path/share/applications/emacsclient.desktop \
|
assertFileContent home-path/share/applications/emacsclient.desktop \
|
||||||
${./emacs-emacsclient.desktop}
|
${./emacs-28-emacsclient.desktop}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
}
|
}
|
|
@ -1,9 +1,11 @@
|
||||||
[Service]
|
[Service]
|
||||||
ExecStart=@runtimeShell@ -l -c "@emacs@/bin/emacs --fg-daemon='%t/emacs/server'"
|
ExecStart=@runtimeShell@ -l -c "@emacs@/bin/emacs --fg-daemon='%t/emacs/server'"
|
||||||
ExecStop=@emacs@/bin/emacsclient --eval '(kill-emacs 0)'
|
|
||||||
Restart=on-failure
|
Restart=on-failure
|
||||||
|
SuccessExitStatus=15
|
||||||
|
Type=notify
|
||||||
|
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=Emacs: the extensible, self-documenting text editor
|
Description=Emacs text editor
|
||||||
Documentation=info:emacs man:emacs(1) https://gnu.org/software/emacs/
|
Documentation=info:emacs man:emacs(1) https://gnu.org/software/emacs/
|
||||||
|
RefuseManualStart=true
|
||||||
X-RestartIfChanged=false
|
X-RestartIfChanged=false
|
|
@ -8,5 +8,5 @@ ListenStream=%t/emacs/server
|
||||||
SocketMode=0600
|
SocketMode=0600
|
||||||
|
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=Emacs: the extensible, self-documenting text editor
|
Description=Emacs text editor
|
||||||
Documentation=info:emacs man:emacs(1) https://gnu.org/software/emacs/
|
Documentation=info:emacs man:emacs(1) https://gnu.org/software/emacs/
|
Loading…
Reference in a new issue