[emacs-berlin] Quirks of Emacs as a systemd service

jman emacs-berlin at city17.xyz
Tue Jul 8 21:49:06 UTC 2025


Hello fellow emacser:innen :-)

Today at the meetup I was asked if Emacs as a systemd service makes sense: I still don't have an 
answer but I am running the experiment.

In my hand-wavy understanding, a systemd service runs a process in a bit more "isolated" 
environment, though - by default - not so strictly as a chroot, Docker container, SELinux or 
AppArmor. I know (and I have a bit of experience) that a system service _can_ almost become a 
chroot.

Anyway, back to Emacs. I notice that my Emacs is broken when starting it as a daemon from systemd: 
the reason is that I need a few env variables to make specific things to work. The `emacs.service` 
examples I find around are not very helpful.

For example, today I fixed three very puzzling issues in one blow:
1. I could not open anymore links from org-mode files (`org-open-at-point`)
2. I could not open anymore links from emails (`shr-browse-url`)
3. I could not paste in the terminal emulator stuff from the kill ring (`kill-ring-save`)

I solved by adding the following to the systemd Unit (the configuration file of the service):

--8<---------------cut here---------------start------------->8---
[Service]
...
# Inherits $HOME, $LOGNAME, and $SHELL from the user environment
# See man systemd.exec(5)
SetLoginEnvironment=true
--8<---------------cut here---------------end--------------->8---

Why this solved those three issues? My speculation is that 1. and 2. happened because somehow Emacs 
didn't have access to my MIME types database and could not open my browser, though unclear the 
workflow from clicking a URI to my system telling Emacs to send that link to Firefox.

Why this also solved 3. is even more unclear. The clipboard should the clipboard, right?

Anyway, just wanted to share these misterious things :-) If anyone has some intuitions, I'm all 
ears.

I'm writing a blog post with my learning:
https://www.city17.xyz/quirks-about-emacs-as-a-systemd-service/

Cheers,


More information about the emacs-berlin mailing list