From 6ec3026e510d7e9440e8d0cbe206ef68a8e4251a Mon Sep 17 00:00:00 2001 From: Robert Helgesson Date: Sun, 15 Jan 2017 10:46:20 +0100 Subject: [PATCH] xsession: improve initialization script This adds a `graphical-session-pre` target for things that need to run just before the main session starts. Also adds a loop during shutdown that waits until all deactivating units are gone. Inspired by . --- modules/xsession.nix | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/modules/xsession.nix b/modules/xsession.nix index 52393c7fb..3b36a5b53 100644 --- a/modules/xsession.nix +++ b/modules/xsession.nix @@ -53,6 +53,14 @@ in }; }; + # For stuff that needs to start just before a graphical session + # starts. + systemd.user.targets.graphical-session-pre = { + Unit = { + Description = "Pre-graphical session"; + }; + }; + # A basic graphical session target. Apparently this will come # standard in future Systemd versions. systemd.user.targets.graphical-session = { @@ -73,13 +81,21 @@ in systemctl --user import-environment XAUTHORITY systemctl --user import-environment XDG_DATA_DIRS systemctl --user import-environment XDG_RUNTIME_DIR - systemctl --user start graphical-session.target + + systemctl --user restart graphical-session-pre.target + systemctl --user restart graphical-session.target ${cfg.initExtra} ${cfg.windowManager} systemctl --user stop graphical-session.target + systemctl --user stop graphical-session-pre.target + + # Wait until the units actually stop. + while [[ -n "$(systemctl --user --no-legend --state=deactivating list-units)" ]]; do + sleep 0.5 + done ''; }; };