From a06868fb0deb4d23ebca065f886e2beca9e36f0d Mon Sep 17 00:00:00 2001 From: K900 Date: Fri, 6 Sep 2024 19:52:06 +0300 Subject: [PATCH 1/2] switch-to-configuration-ng: get runtime directory from logind instead of hardcoding Correctness fix, shouldn't actually matter ~ever. --- .../switch-to-configuration-ng/src/src/main.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/pkgs/by-name/sw/switch-to-configuration-ng/src/src/main.rs b/pkgs/by-name/sw/switch-to-configuration-ng/src/src/main.rs index 057604b03178..4d929918227d 100644 --- a/pkgs/by-name/sw/switch-to-configuration-ng/src/src/main.rs +++ b/pkgs/by-name/sw/switch-to-configuration-ng/src/src/main.rs @@ -1657,15 +1657,19 @@ won't take effect until you reboot the system. } Ok(users) => { for (uid, name, user_dbus_path) in users { - let gid: u32 = dbus_conn - .with_proxy( - "org.freedesktop.login1", - &user_dbus_path, - Duration::from_millis(5000), - ) + let proxy = dbus_conn.with_proxy( + "org.freedesktop.login1", + &user_dbus_path, + Duration::from_millis(5000), + ); + let gid: u32 = proxy .get("org.freedesktop.login1.User", "GID") .with_context(|| format!("Failed to get GID for {name}"))?; + let runtime_path: String = proxy + .get("org.freedesktop.login1.User", "RuntimePath") + .with_context(|| format!("Failed to get runtime directory for {name}"))?; + eprintln!("reloading user units for {}...", name); let myself = Path::new("/proc/self/exe") .canonicalize() @@ -1674,7 +1678,7 @@ won't take effect until you reboot the system. std::process::Command::new(&myself) .uid(uid) .gid(gid) - .env("XDG_RUNTIME_DIR", format!("/run/user/{}", uid)) + .env("XDG_RUNTIME_DIR", runtime_path) .env("__NIXOS_SWITCH_TO_CONFIGURATION_PARENT_EXE", &myself) .spawn() .with_context(|| format!("Failed to spawn user activation for {name}"))? From c80b1661155a17dfef7be39e87eb7af35f378555 Mon Sep 17 00:00:00 2001 From: K900 Date: Fri, 6 Sep 2024 19:52:56 +0300 Subject: [PATCH 2/2] switch-to-configuration-ng: clear environment when reexecing as user Avoids weird magic dbus variables leaking in and ruining everything. --- pkgs/by-name/sw/switch-to-configuration-ng/src/src/main.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/pkgs/by-name/sw/switch-to-configuration-ng/src/src/main.rs b/pkgs/by-name/sw/switch-to-configuration-ng/src/src/main.rs index 4d929918227d..802b5e64f101 100644 --- a/pkgs/by-name/sw/switch-to-configuration-ng/src/src/main.rs +++ b/pkgs/by-name/sw/switch-to-configuration-ng/src/src/main.rs @@ -1678,6 +1678,7 @@ won't take effect until you reboot the system. std::process::Command::new(&myself) .uid(uid) .gid(gid) + .env_clear() .env("XDG_RUNTIME_DIR", runtime_path) .env("__NIXOS_SWITCH_TO_CONFIGURATION_PARENT_EXE", &myself) .spawn()