[jhbuild/wip/benzea/systemd-user-session] env: Set systemd unit and generator paths



commit 0982434251596c49ad124b302d1b777c6b9b651e
Author: Benjamin Berg <bberg redhat com>
Date:   Tue Mar 24 15:11:29 2020 +0100

    env: Set systemd unit and generator paths
    
    When starting a (nested) systemd user instance, we can get systemd to
    pick up unit and generator directories from inside the virtual
    environment (without re-compiling systemd to adjust the paths). This
    also means that units from the outside can still be picked up, with the
    corresponding advantages and disadvantages.

 jhbuild/environment.py | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
---
diff --git a/jhbuild/environment.py b/jhbuild/environment.py
index 9b96bdad..48d5f836 100644
--- a/jhbuild/environment.py
+++ b/jhbuild/environment.py
@@ -268,3 +268,31 @@ def setup_env(prefix):
         addpath('PYTHONPATH', os.path.join(PKGDATADIR, 'sitecustomize'))
     else:
         addpath('PYTHONPATH', os.path.join(SRCDIR, 'jhbuild', 'sitecustomize'))
+
+    # SYSTEMD unit and generators paths, this only makes sense if
+    # XDG_RUNTIME_DIR is set.
+    if 'XDG_RUNTIME_DIR' in os.environ:
+        # The following variables allow launching a full blown desktop including
+        # its own systemd instance. It is intended for use together with the
+        # gnome-launch-systemd script provided by gnome-session for testing
+        # purposes. It also requires an environment generator to ensure that
+        # the jhbuild environment is fully imported into systemd.
+        # Ensure an empty postfix so that systemd appends the default paths
+        addpath('SYSTEMD_UNIT_PATH', '')
+        addpath('SYSTEMD_GENERATOR_PATH', '')
+        addpath('SYSTEMD_ENVIRONMENT_GENERATOR_PATH', '')
+
+        # Generator paths are easy, just add the correct directories from lib
+        addpath('SYSTEMD_GENERATOR_PATH', os.path.join(libdir, 'systemd/user-generators'))
+        addpath('SYSTEMD_ENVIRONMENT_GENERATOR_PATH', os.path.join(libdir, 
'systemd/user-environment-generators'))
+
+        # For the systemd unit path, it makes sense to include some more directories
+        # to ensure correct priority from systemd (i.e. we intentionally repeat some
+        # default paths here). The first is the one we really care about.
+        addpath('SYSTEMD_UNIT_PATH', os.path.join(libdir, 'systemd/user'))
+        addpath('SYSTEMD_UNIT_PATH', os.path.join(os.environ['XDG_RUNTIME_DIR'], 'systemd/generator'))
+        addpath('SYSTEMD_UNIT_PATH', os.path.join(os.environ['XDG_RUNTIME_DIR'], 'systemd/user'))
+        addpath('SYSTEMD_UNIT_PATH', os.path.join(prefix, 'etc/systemd/user'))
+        # permit higher priority user configurations?
+        # addpath('SYSTEMD_UNIT_PATH', os.path.join(xdg_config_dir, 'systemd/user'))
+        addpath('SYSTEMD_UNIT_PATH', os.path.join(os.environ['XDG_RUNTIME_DIR'], 'systemd/generator.early'))


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]