diff options
Diffstat (limited to 'home-manager/modules/systemd.nix')
-rw-r--r-- | home-manager/modules/systemd.nix | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/home-manager/modules/systemd.nix b/home-manager/modules/systemd.nix index cdc4486f542..56164020577 100644 --- a/home-manager/modules/systemd.nix +++ b/home-manager/modules/systemd.nix @@ -6,8 +6,6 @@ let cfg = config.systemd.user; - dag = config.lib.dag; - enabled = cfg.services != {} || cfg.sockets != {} || cfg.targets != {} @@ -230,7 +228,7 @@ in # running this from the NixOS module then XDG_RUNTIME_DIR is not # set and systemd commands will fail. We'll therefore have to # set it ourselves in that case. - home.activation.reloadSystemD = dag.entryAfter ["linkGeneration"] ( + home.activation.reloadSystemD = hm.dag.entryAfter ["linkGeneration"] ( let autoReloadCmd = '' ${pkgs.ruby}/bin/ruby ${./systemd-activate.rb} \ @@ -242,15 +240,27 @@ in ''; ensureRuntimeDir = "XDG_RUNTIME_DIR=\${XDG_RUNTIME_DIR:-/run/user/$(id -u)}"; + + systemctl = "${ensureRuntimeDir} ${cfg.systemctlPath}"; in '' - if ${ensureRuntimeDir} ${cfg.systemctlPath} --quiet --user is-system-running 2> /dev/null; then + systemdStatus=$(${systemctl} --user is-system-running 2>&1 || true) + + if [[ $systemdStatus == 'running' || $systemdStatus == 'degraded' ]]; then + if [[ $systemdStatus == 'degraded' ]]; then + warnEcho "The user systemd session is degraded:" + ${systemctl} --user --state=failed + warnEcho "Attempting to reload services anyway..." + fi + ${ensureRuntimeDir} \ PATH=${dirOf cfg.systemctlPath}:$PATH \ ${if cfg.startServices then autoReloadCmd else legacyReloadCmd} else echo "User systemd daemon not running. Skipping reload." fi + + unset systemdStatus '' ); }) |