1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-12-02 16:09:46 +01:00

systemd: replace use of who command

Curiously the `who` command sometimes does not list logged-in users,
resulting in systemd not being reloaded. Instead we use

    systemctl --user is-system-running

to more directly detect whether systemd is running.
This commit is contained in:
Robert Helgesson 2018-02-18 16:39:28 +01:00
parent 4745c7a00d
commit e307ceeee7
No known key found for this signature in database
GPG key ID: C3DB11069E65DC86

View file

@ -159,14 +159,16 @@ in
legacyReloadCmd = '' legacyReloadCmd = ''
bash ${./systemd-activate.sh} "''${oldGenPath=}" "$newGenPath" bash ${./systemd-activate.sh} "''${oldGenPath=}" "$newGenPath"
''; '';
ensureRuntimeDir = "XDG_RUNTIME_DIR=\${XDG_RUNTIME_DIR:-/run/user/$(id -u)}";
in in
'' ''
if who | grep -q '^${config.home.username} '; then if ${ensureRuntimeDir} ${cfg.systemctlPath} --quiet --user is-system-running 2> /dev/null; then
XDG_RUNTIME_DIR=''${XDG_RUNTIME_DIR:-/run/user/$(id -u)} \ ${ensureRuntimeDir} \
PATH=${dirOf cfg.systemctlPath}:$PATH \ PATH=${dirOf cfg.systemctlPath}:$PATH \
${if cfg.startServices then autoReloadCmd else legacyReloadCmd} ${if cfg.startServices then autoReloadCmd else legacyReloadCmd}
else else
echo "User ${config.home.username} not logged in. Skipping." echo "User systemd daemon not running. Skipping reload."
fi fi
'' ''
); );