On Wed, 27 Aug 2025 14:03:32 +0200 Klaus Stein <[email protected]> wrote:
I had the exactly same problem. […]
but i managed to get emacs.service working correctly […]

Unfortunately this was a half-baked solution (which I found out directly after posting this). I played around with Gnome on X11 vs. Gnome on Wayland and the given file was not enough.

Especially when running under Wayland it had problems with Xauthority.

I ended up with creating a new file
(by copying /usr/lib/systemd/user/emacs.service)
as follows:

=== .config/systemd/user/graphical-emacs.service ===
[Unit]
Description=Emacs text editor
Documentation=info:emacs man:emacs(1) https://gnu.org/software/emacs/

[Service]
Type=notify
ExecStart=/usr/bin/emacs --fg-daemon

# Emacs will exit with status 15 after having received SIGTERM, which
# is the default "KillSignal" value systemd uses to stop services.
SuccessExitStatus=15

# The location of the SSH auth socket varies by distribution, and some
# set it from PAM, so don't override by default.
Environment=SSH_AUTH_SOCK=%t/keyring/ssh
Restart=on-failure

[Install]
WantedBy=graphical-session.target

[Unit]
After=gnome-session-x11-services.target
=====================================================

I am not sure this could have been done with overrides, I just did not manage to get “systemctl --user enable graphical-emacs” to create the correct link.

Don't forget to
systemctl --user disable emacs
systemctl --user enable graphical-emacs
systemctl --user stop emacs
systemctl --user start graphical-emacs

I hope this works for you and others.
If it does (and does not have other drawbacks I don't understand with my limited knowledge of systemd) providing a patched version of this file in future releases could be helpful.

The EmacsWiki already knows about this:
<https://www.emacswiki.org/emacs/EmacsAsDaemon> (I learned from this)

I basically stole the above from here: <https://emacs.stackexchange.com/questions/74937/systemd-starts-emacs-daemon-without-xauthority-environment-variable-after-upgrad>.

This also was somehow helpful: <https://askubuntu.com/questions/1499139/how-to-run-emacs-daemon-as-a-systemd-service-with-wayland-on-ubuntu-22-04>.

Klaus

--
http://lapiz.istik.de/

The Answer is 42. And I am the Answer. Now I am looking for the Question.

Reply via email to