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

Diez B. Roggisch deets at web.de
Wed Jul 9 13:26:39 UTC 2025


I think the cause here is rather that for IPC mechanisms like URL opening to work, modern desktops rely on facilities like DBUS to make this happen.  These run as per-user-session and are available via environment variables. Similar as to how SSH agents work. 

So by adding this to your config eMacs was able to access these services. 

Cheers,

Diez 

Mobile Mail. Excuse brevity. 


> Am 09.07.2025 um 00:55 schrieb jman <emacs-berlin at city17.xyz>:
> 
> 
> 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,
> _______________________________________________
> emacs-berlin mailing list
> emacs-berlin at emacs-berlin.org
> https://mailb.org/mailman/listinfo/emacs-berlin



More information about the emacs-berlin mailing list