swaywm / swayidle

Idle management daemon for Wayland
MIT License
550 stars 50 forks source link

No effect when started from systemd service unit #129

Closed spikespaz closed 2 years ago

spikespaz commented 2 years ago

I have the following systemd unit:

# /home/jacob/.config/systemd/user/swayidle.service
[Install]
WantedBy=hyprland-session.target

[Service]
Environment=PATH=/nix/store/1b9p07z77phvv2hf6gm9f28syp39f1ag-bash-5.1-p16/bin
ExecStart=/nix/store/0pfw3kry1gj3l6x1rwv6waq0w1wgvv01-swayidle-1.7.1/bin/swayidle timeout 5 'swaylock -f --grace 10'
Type=simple

[Unit]
Description=Idle manager for Wayland
Documentation=man:swayidle(1)
PartOf=graphical-session.target

I can confirm that it starts successfully.

I have the following lines in my config for the Hyprland window manager:

exec-once=export XDG_SESSION_TYPE=wayland
exec-once=/nix/store/h3i7qlla1isix0vbw1j9d3v0a7qjrds4-dbus-1.14.0/bin/dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY HYPRLAND_INSTANCE_SIGNATURE XDG_CURRENT_DESKTOP
exec-once=systemctl --user start hyprland-session.target

Hopefully they are self-explanatory. The second line should have set any environment variables for swayidle, but I can see that it only cares about XDG directories according to the source code.

Note that when I run that command that is in the unit directly in the command line, it executes the swaylock command after 5 seconds as expected.

WhyNotHugo commented 2 years ago

Does systemctl --user show-environment include WAYLAND_DISPLAY? What about XDG_SESSION_ID?

spikespaz commented 2 years ago

I can confirm they are set. I do not have access to the system at the moment but @fufexan can also verify.

fufexan commented 2 years ago

@spikespaz try adding {pkgs.swaylock}/bin to the Environment PATH, or manually using "${pkgs.swaylock}/bin/swaylock". SystemD services do not inherit the user PATH.

Using the above works for me.

cyntheticfox commented 2 years ago

@spikespaz try adding {pkgs.swaylock}/bin to the Environment PATH, or manually using "${pkgs.swaylock}/bin/swaylock". SystemD services do not inherit the user PATH.

Using the above works for me.

Alternatively, if you're configuring the service from a central location (as with NixOS or home-manager), you could instead hard-code the binary path. I personally have my exec statement like

ExecStart=${pkgs.swayidle}/bin/swayidle timeout 5 '${pkgs.swaylock}/bin/swaylock --daemonize'

It's probably a more "declarative" way, since that way it doesn't rely on PATH.

spikespaz commented 2 years ago

@houstdav000 That's what I'm currently doing.

Fufexan's suggestion was to add the binary to PATH only for the systemd unit. It won't affect anything else.