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

@ -76,11 +76,16 @@ in
before = [ "sleep.target" ]; before = [ "sleep.target" ];
wantedBy = [ "sleep.target" ]; wantedBy = [ "sleep.target" ];
serviceConfig = { serviceConfig = {
Type = "oneshot"; Type = "oneshot";
User = "fred"; User = "fred";
Environment = "XDG_RUNTIME_DIR=/run/user/%U"; # XDG_RUNTIME_DIR must be derived at runtime: the %U specifier is the
ExecStart = "${pkgs.quickshell}/bin/qs ipc call lock lock"; # UID of the *manager* running the unit (0 for system units), not the
ExecStartPost = "${pkgs.coreutils}/bin/sleep 1"; # 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"; TimeoutStartSec = "5s";
}; };
}; };