From e1c6094075d28d496a1b0db208afd31e0b213d67 Mon Sep 17 00:00:00 2001 From: Robert Helgesson Date: Thu, 12 Sep 2024 13:42:59 +0200 Subject: [PATCH] systemd: unify handling of switch environment --- modules/systemd.nix | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/modules/systemd.nix b/modules/systemd.nix index 707bb3294..77d9df862 100644 --- a/modules/systemd.nix +++ b/modules/systemd.nix @@ -325,11 +325,9 @@ in { home.activation.reloadSystemd = hm.dag.entryAfter [ "linkGeneration" ] (let cmd = { suggest = '' - PATH=${dirOf cfg.systemctlPath}:$PATH \ bash ${./systemd-activate.sh} "''${oldGenPath=}" "$newGenPath" ''; legacy = '' - PATH=${dirOf cfg.systemctlPath}:$PATH \ ${pkgs.ruby}/bin/ruby ${./systemd-activate.rb} \ "''${oldGenPath=}" "$newGenPath" "${servicesStartTimeoutMs}" ''; @@ -346,10 +344,14 @@ in { ''; }; - ensureRuntimeDir = - "XDG_RUNTIME_DIR=\${XDG_RUNTIME_DIR:-/run/user/$(id -u)}"; + # Make sure that we have an environment where we are likely to + # successfully talk with systemd. + ensureSystemd = '' + env XDG_RUNTIME_DIR="''${XDG_RUNTIME_DIR:-/run/user/$(id -u)}" \ + PATH="${dirOf cfg.systemctlPath}:$PATH" \ + ''; - systemctl = "${ensureRuntimeDir} ${cfg.systemctlPath}"; + systemctl = "${ensureSystemd} systemctl"; in '' systemdStatus=$(${systemctl} --user is-system-running 2>&1 || true) @@ -372,8 +374,7 @@ in { newUnitsDir=${pkgs.emptyDirectory} fi - ${ensureRuntimeDir} \ - ${getAttr cfg.startServices cmd} + ${ensureSystemd} ${getAttr cfg.startServices cmd} unset newUnitsDir oldUnitsDir else