about summary refs log tree commit diff
path: root/pkgs/desktops/lomiri
diff options
context:
space:
mode:
authorOPNA2608 <opna2608@protonmail.com>2024-05-31 22:11:59 +0200
committerOPNA2608 <opna2608@protonmail.com>2024-05-31 22:11:59 +0200
commitaf1d2bd13a27e39eb306fe206ce0389c06c0e9b9 (patch)
treef4412bba49c1f902f0d5a657915514f53f6fa93e /pkgs/desktops/lomiri
parentf4c6d452efd86a135afa3c913e947a964e927cb4 (diff)
lomiri.lomiri-app-launch: Inject /run/current-system/sw/bin into PATH
LAL manages desktop file parsing for various parts of the Lomiri environment. It also handles turning them into SystemD services tracked in the background.
And due to how things work one, it's code is also SystemD-launched by itself.

When we package applications with desktop files, we don't want the Exec values to be absolute, so we patch out absolute paths.
Without absolute paths, PATH is expected to have the path to the executables. But our PATHs don't always contain i.e. /run/current-system/sw/bin.

Services launched by SystemD are one such instance. If LAL code is run under SystemD's restricted reduced PATH, then it fails to find the requested executables.
This is what happens to content-hub, and it causes all transfer requests to be met with an immediate "could not launch peer"-like error, and a transfer being stuck halfway.

To work around this (I wouldn't call this a real solution?), patch LAL code to:
- also propagate whatever PATH it currently *does* have to its launched applications
- postfix the PATH it has with /run/current-system/sw/bin, to give it a decent fallback

These changes allow for lomiri-filemanager-app to be launched via a content-hub request from lomiri-system-settings (i.e. the background selection).
Diffstat (limited to 'pkgs/desktops/lomiri')
-rw-r--r--pkgs/desktops/lomiri/development/lomiri-app-launch/2001-Inject-current-system-PATH.patch59
-rw-r--r--pkgs/desktops/lomiri/development/lomiri-app-launch/default.nix3
2 files changed, 62 insertions, 0 deletions
diff --git a/pkgs/desktops/lomiri/development/lomiri-app-launch/2001-Inject-current-system-PATH.patch b/pkgs/desktops/lomiri/development/lomiri-app-launch/2001-Inject-current-system-PATH.patch
new file mode 100644
index 0000000000000..86bf90085d7a0
--- /dev/null
+++ b/pkgs/desktops/lomiri/development/lomiri-app-launch/2001-Inject-current-system-PATH.patch
@@ -0,0 +1,59 @@
+From e4fe87427f24aa9b506c15c0f73f298e8909aabe Mon Sep 17 00:00:00 2001
+From: OPNA2608 <opna2608@protonmail.com>
+Date: Fri, 31 May 2024 21:31:46 +0200
+Subject: [PATCH] Inject current-system PATH
+
+---
+ liblomiri-app-launch/jobs-systemd.cpp | 16 ++++++++++++++++
+ liblomiri-app-launch/jobs-systemd.h   |  1 +
+ 2 files changed, 17 insertions(+)
+
+diff --git a/liblomiri-app-launch/jobs-systemd.cpp b/liblomiri-app-launch/jobs-systemd.cpp
+index e9be801..246bea8 100644
+--- a/liblomiri-app-launch/jobs-systemd.cpp
++++ b/liblomiri-app-launch/jobs-systemd.cpp
+@@ -574,6 +574,20 @@ void SystemD::copyEnvByPrefix(const std::string& prefix, std::list<std::pair<std
+     }
+ }
+ 
++/* We don't have a normal PATH, so we need to inject our special one as a fallback & propagate it */
++void SystemD::setupNixosPath(std::list<std::pair<std::string, std::string>>& env)
++{
++        std::string newPath { "/run/current-system/sw/bin" };
++        char* oldPath = getenv("PATH");
++        if (oldPath != NULL && oldPath[0] != '\0')
++        {
++            newPath.insert(0, 1, ':');
++            newPath.insert(0, oldPath);
++        }
++        setenv("PATH", newPath.c_str(), true);
++        copyEnv("PATH", env);
++}
++
+ std::shared_ptr<Application::Instance> SystemD::launch(
+     const AppID& appId,
+     const std::string& job,
+@@ -625,6 +639,8 @@ std::shared_ptr<Application::Instance> SystemD::launch(
+ 
+         copyEnv("DISPLAY", env);
+ 
++        setupNixosPath(env);
++
+         for (const auto& prefix : {"DBUS_", "MIR_", "LOMIRI_APP_LAUNCH_"})
+         {
+             copyEnvByPrefix(prefix, env);
+diff --git a/liblomiri-app-launch/jobs-systemd.h b/liblomiri-app-launch/jobs-systemd.h
+index fe35932..19bf44e 100644
+--- a/liblomiri-app-launch/jobs-systemd.h
++++ b/liblomiri-app-launch/jobs-systemd.h
+@@ -136,6 +136,7 @@ private:
+     static void copyEnv(const std::string& envname, std::list<std::pair<std::string, std::string>>& env);
+     static void copyEnvByPrefix(const std::string& prefix, std::list<std::pair<std::string, std::string>>& env);
+     static int envSize(std::list<std::pair<std::string, std::string>>& env);
++    static void setupNixosPath(std::list<std::pair<std::string, std::string>>& env);
+ 
+     static std::vector<std::string> parseExec(std::list<std::pair<std::string, std::string>>& env);
+     static void application_start_cb(GObject* obj, GAsyncResult* res, gpointer user_data);
+-- 
+2.42.0
+
diff --git a/pkgs/desktops/lomiri/development/lomiri-app-launch/default.nix b/pkgs/desktops/lomiri/development/lomiri-app-launch/default.nix
index 381a89fe10ff6..f248ae9ca0d0a 100644
--- a/pkgs/desktops/lomiri/development/lomiri-app-launch/default.nix
+++ b/pkgs/desktops/lomiri/development/lomiri-app-launch/default.nix
@@ -54,6 +54,9 @@ stdenv.mkDerivation (finalAttrs: {
       url = "https://gitlab.com/ubports/development/core/lomiri-app-launch/-/commit/0419b2592284f43ee5e76060948ea3d5f1c991fd.patch";
       hash = "sha256-11pEhFi39Cvqb9Hg47kT8+5hq+bz6WmySqaIdwt1MVk=";
     })
+
+    # Use /run/current-system/sw/bin fallback for desktop file Exec= lookups, propagate to launched applications
+    ./2001-Inject-current-system-PATH.patch
   ];
 
   postPatch = ''