Subject: Re: bug#76924: 31.0.50; Wrong install location for systemd user unit file

From: Ulrich Müller <[email-masked]>
Date: Tue, 11 Mar 2025 14:34:20 +0100

>>>>> On Tue, 11 Mar 2025, Eli Zaretskii wrote:

> The comment there says:

>   # Where the etc/emacs.service file is to be installed.
>   # The system value (typically /usr/lib/systemd/user) can be
>   # obtained with: pkg-config --variable=systemduserunitdir systemd
>   # but that does not respect configure's prefix.
>   # It is not clear where we should install this file when
>   # prefix != /usr (or /usr/local?) (eg for non-root installs).
>   # Other options include ~/.config/systemd/user/,
>   # $XDG_RUNTIME_DIR/systemd/user/
>   # It seems the user may end up having to make a manual link...
>   systemdunitdir=$(libdir)/systemd/user

> So this isn't a simple mistake, but a deliberate decision.  We should
> do more research before we override this.  For example: what do
> distros do with this? do they really all use what you suggest?

Gentoo removes the emacs.service file from Emacs' install image and
installs it in /usr/lib/systemd/user instead.

IIUC Debian installs system unit files in the /lib/systemd/system
directory, see https://wiki.debian.org/systemd. The article doesn't
mention user files, but the corresponding location would be
/lib/systemd/user (i.e. _not_ /lib64).

(Note that systemd no longer supports the concept of separate /lib and
/usr/lib, i.e. /lib is a symlink to /usr/lib and it doesn't matter if
the prefix is / or /usr.)

> Or maybe we should use pkg-config, at least if no --prefix was
> specified at configure time?

systemd.pc has this
(https://github.com/systemd/systemd/blob/cd20d48c69f9e586de914e1facf33b11122477ae/src/core/systemd.pc.in#L34):

   systemd_user_unit_dir=${prefix}/lib/systemd/user
   systemduserunitdir=${systemd_user_unit_dir}

So depending on the prefix, that would be /lib or /usr/lib (which are
equivalent, see above).

Maybe the cleanest solution would be to ask pkg-config (after all,
systemd must find these files), with $(prefix)/lib/systemd/user as
fallback location.