lock-before-sleep: derive XDG_RUNTIME_DIR at runtime, %U was root

This commit is contained in:
rope 2026-08-16 13:34:38 +01:00
parent 9514664a55
commit 52599fd24d

View file

@ -78,9 +78,14 @@ in
serviceConfig = {
Type = "oneshot";
User = "fred";
Environment = "XDG_RUNTIME_DIR=/run/user/%U";
ExecStart = "${pkgs.quickshell}/bin/qs ipc call lock lock";
ExecStartPost = "${pkgs.coreutils}/bin/sleep 1";
# XDG_RUNTIME_DIR must be derived at runtime: the %U specifier is the
# UID of the *manager* running the unit (0 for system units), not the
# one in User=, so it pointed qs at /run/user/0.
ExecStart = pkgs.writeShellScript "lock-before-sleep" ''
export XDG_RUNTIME_DIR=/run/user/$(${pkgs.coreutils}/bin/id -u)
${pkgs.quickshell}/bin/qs ipc call lock lock
${pkgs.coreutils}/bin/sleep 1
'';
TimeoutStartSec = "5s";
};
};