Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at devShellTools-shell 59 lines 2.4 kB view raw
1From e4fe87427f24aa9b506c15c0f73f298e8909aabe Mon Sep 17 00:00:00 2001 2From: OPNA2608 <opna2608@protonmail.com> 3Date: Fri, 31 May 2024 21:31:46 +0200 4Subject: [PATCH] Inject current-system PATH 5 6--- 7 liblomiri-app-launch/jobs-systemd.cpp | 16 ++++++++++++++++ 8 liblomiri-app-launch/jobs-systemd.h | 1 + 9 2 files changed, 17 insertions(+) 10 11diff --git a/liblomiri-app-launch/jobs-systemd.cpp b/liblomiri-app-launch/jobs-systemd.cpp 12index e9be801..246bea8 100644 13--- a/liblomiri-app-launch/jobs-systemd.cpp 14+++ b/liblomiri-app-launch/jobs-systemd.cpp 15@@ -574,6 +574,20 @@ void SystemD::copyEnvByPrefix(const std::string& prefix, std::list<std::pair<std 16 } 17 } 18 19+/* We don't have a normal PATH, so we need to inject our special one as a fallback & propagate it */ 20+void SystemD::setupNixosPath(std::list<std::pair<std::string, std::string>>& env) 21+{ 22+ std::string newPath { "/run/current-system/sw/bin" }; 23+ char* oldPath = getenv("PATH"); 24+ if (oldPath != NULL && oldPath[0] != '\0') 25+ { 26+ newPath.insert(0, 1, ':'); 27+ newPath.insert(0, oldPath); 28+ } 29+ setenv("PATH", newPath.c_str(), true); 30+ copyEnv("PATH", env); 31+} 32+ 33 std::shared_ptr<Application::Instance> SystemD::launch( 34 const AppID& appId, 35 const std::string& job, 36@@ -625,6 +639,8 @@ std::shared_ptr<Application::Instance> SystemD::launch( 37 38 copyEnv("DISPLAY", env); 39 40+ setupNixosPath(env); 41+ 42 for (const auto& prefix : {"DBUS_", "MIR_", "LOMIRI_APP_LAUNCH_"}) 43 { 44 copyEnvByPrefix(prefix, env); 45diff --git a/liblomiri-app-launch/jobs-systemd.h b/liblomiri-app-launch/jobs-systemd.h 46index fe35932..19bf44e 100644 47--- a/liblomiri-app-launch/jobs-systemd.h 48+++ b/liblomiri-app-launch/jobs-systemd.h 49@@ -136,6 +136,7 @@ private: 50 static void copyEnv(const std::string& envname, std::list<std::pair<std::string, std::string>>& env); 51 static void copyEnvByPrefix(const std::string& prefix, std::list<std::pair<std::string, std::string>>& env); 52 static int envSize(std::list<std::pair<std::string, std::string>>& env); 53+ static void setupNixosPath(std::list<std::pair<std::string, std::string>>& env); 54 55 static std::vector<std::string> parseExec(std::list<std::pair<std::string, std::string>>& env); 56 static void application_start_cb(GObject* obj, GAsyncResult* res, gpointer user_data); 57-- 582.42.0 59