Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

systemd: add targets #8339

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ if(NO_SYSTEMD)
else()
message(STATUS "SYSTEMD support is requested (NO_SYSTEMD not defined)...")
add_compile_definitions(USES_SYSTEMD)
configure_file(systemd/hyprland-session.service.in
systemd/hyprland-session.service @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/systemd/hyprland-session.service.in
${CMAKE_BINARY_DIR}/systemd/hyprland-session.service @ONLY)

# session file -systemd
install(FILES ${CMAKE_SOURCE_DIR}/systemd/hyprland-systemd.desktop
Expand All @@ -232,6 +232,14 @@ else()
# install systemd service
install(FILES ${CMAKE_BINARY_DIR}/systemd/hyprland-session.service
DESTINATION ${CMAKE_INSTALL_LIBDIR}/systemd/user)

# install systemd targets
install(FILES ${CMAKE_SOURCE_DIR}/systemd/hyprland-session.target
DESTINATION ${CMAKE_INSTALL_LIBDIR}/systemd/user)
install(FILES ${CMAKE_SOURCE_DIR}/systemd/[email protected]
DESTINATION ${CMAKE_INSTALL_LIBDIR}/systemd/user)
install(FILES ${CMAKE_SOURCE_DIR}/systemd/hyprland-session-pre.target
DESTINATION ${CMAKE_INSTALL_LIBDIR}/systemd/user)
endif()

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
Expand Down
8 changes: 8 additions & 0 deletions systemd/hyprland-session-pre.target
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[Unit]
Description=Tasks to be run before Hyprland Session starts
DefaultDependencies=no
RefuseManualStart=yes
RefuseManualStop=yes

Requires=graphical-session-pre.target
After=graphical-session-pre.target
17 changes: 11 additions & 6 deletions systemd/hyprland-session.service.in
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
[Unit]
Description=Hyprland - Tiling compositor with the looks
Documentation=man:Hyprland(1)
BindsTo=graphical-session.target
Before=graphical-session.target

BindsTo=hyprland-session.target
Before=hyprland-session.target

Wants=xdg-desktop-autostart.target
Wants=graphical-session-pre.target
After=graphical-session-pre.target

Wants=hyprland-session-pre.target
After=hyprland-session-pre.target

[Service]
Type=notify
ExecStart=@PREFIX@/@BINDIR@/Hyprland
ExecStop=@PREFIX@/@BINDIR@/hyprctl dispatch exit
ExecStart=@BINDIR@/Hyprland
ExecStop=@BINDIR@/hyprctl dispatch exit
Comment on lines +15 to +16
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks using the current flake:

...
[Service]
Type=notify
ExecStart=bin/Hyprland
ExecStop=bin/hyprctl dispatch exit
ExecStopPost=systemctl --user unset-environment DISPLAY WAYLAND_DISPLAY HYPRLAND_INSTANCE_SIGNATURE XDG_CURRENT_DESKTOP
OnFailure=systemctl --user unset-environment DISPLAY WAYLAND_DISPLAY HYPRLAND_INSTANCE_SIGNATURE XDG_CURRENT_DESKTOP
OnSuccess=systemctl --user unset-environment DISPLAY WAYLAND_DISPLAY HYPRLAND_INSTANCE_SIGNATURE XDG_CURRENT_DESKTOP
...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're scrapping the idea anyway.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, that's odd, bindir is set in the mesonFlags: --bindir=/nix/store/81g3gcxh6ca0gk46r6p7zqna2fb3svd7-hyprland-0.44.0+date=2024-11-03_dirty/bin

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, after I built the package I got this

[Service]
Type=notify
ExecStart=/nix/store/hsx2dwp9agi54dvkkp7rhr9wgvar6d4h-hyprland-0.44.0+date=2024-11-03_403cd66/bin/Hyprland
ExecStop=/nix/store/hsx2dwp9agi54dvkkp7rhr9wgvar6d4h-hyprland-0.44.0+date=2024-11-03_403cd66/bin/hyprctl dispatch exit
ExecStopPost=systemctl --user unset-environment DISPLAY WAYLAND_DISPLAY HYPRLAND_INSTANCE_SIGNATURE XDG_CURRENT_DESKTOP
Restart=on-failure
Slice=session.slice

Copy link

@Atemu Atemu Nov 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very odd indeed. I was overriding the nixpkgs input, let me change that and see if we get the same eval:

/nix/store/8gww5vdnbxgvd8ian4m7z8rhixb0vsy9-hyprland-0.44.0+date=2024-11-03_d78bc75.drv

/nix/store/p1fx35kj1nw5w6swlz9xwhkbmjbknn55-hyprland-0.44.0+date=2024-11-03_d78bc75

It's different to your store path. Have you pushed all changes?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate wanting to use ready-made solutions but they need to actually solve the problem properly in order to be viable.

Unless I'm missing something, it is not possible in uwsm to create a service that is part of the greater hyprland session but starts after the compositor is up. You cannot make it wantedBy graphical-session because it'd then be wantedBy any graphical session, regardless of the compositor. If you made it After the compositor service other services After the compositor service or the graphical-session wouldn't wait on your service, so that wouldn't work either.
I'd have expected uwsm to create a target for us that'd allow for this use-case.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, it does create all sorts of targets. I didn't immediately find them because it appears to generate them dynamically rather than putting them into /etc/systemd/user/?!

Copy link
Member Author

@fufexan fufexan Nov 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Vladimir-csp is it feasible to also create a {name}-session.target that would be bound to wayland-session@{name}.target?

@Atemu would this address your concern?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, as I said, it already does this, I just didn't see it because the units files weren't where I expected them to be.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using [email protected] while target not yet existing is valid and works, but will result in a (harmless) warning from systemd.

Alternatively there is systemd-xdg-autostart-condition, see examples

ExecStopPost=systemctl --user unset-environment DISPLAY WAYLAND_DISPLAY HYPRLAND_INSTANCE_SIGNATURE XDG_CURRENT_DESKTOP
OnFailure=systemctl --user unset-environment DISPLAY WAYLAND_DISPLAY HYPRLAND_INSTANCE_SIGNATURE XDG_CURRENT_DESKTOP
OnSuccess=systemctl --user unset-environment DISPLAY WAYLAND_DISPLAY HYPRLAND_INSTANCE_SIGNATURE XDG_CURRENT_DESKTOP
Comment on lines +18 to +19
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/etc/systemd/user/hyprland-session.service:18: Unknown key 'OnFailure' in section [Service], ignoring.
/etc/systemd/user/hyprland-session.service:19: Unknown key 'OnSuccess' in section [Service], ignoring.

These go into the [Unit] section.

Restart=on-failure
Slice=session.slice
9 changes: 9 additions & 0 deletions systemd/hyprland-session.target
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Unit]
Description=Hyprland Session
DefaultDependencies=no
RefuseManualStart=yes
RefuseManualStop=yes

BindsTo=graphical-session.target
Before=graphical-session.target
After=hyprland-session-pre.target
15 changes: 15 additions & 0 deletions systemd/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[Unit]
Description=Hyprland Session (session: %i)
DefaultDependencies=no
# Start happens explicitly
RefuseManualStart=no

Conflicts=shutdown.target
PartOf=graphical-session.target

# As this is the main entry point, pull in the other toplevel hyprland-session targets
[email protected]
[email protected]

Requires=hyprland-session.target
After=hyprland-session.target
34 changes: 25 additions & 9 deletions systemd/meson.build
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
install_data(
'hyprland-systemd.desktop',
install_dir: join_paths(get_option('datadir'), 'wayland-sessions'),
install_tag: 'runtime',
)
user_unit_dir = systemd.get_variable(pkgconfig: 'systemduserunitdir',
pkgconfig_define: ['prefix', get_option('prefix')])

install_data(
'hyprland-systemd.desktop',
install_dir: join_paths(get_option('datadir'), 'wayland-sessions'),
install_tag: 'runtime',
)
install_data(
'hyprland-session.target',
install_dir: user_unit_dir,
install_tag: 'runtime',
)
install_data(
'[email protected]',
install_dir: user_unit_dir,
install_tag: 'runtime',
)
install_data(
'hyprland-session-pre.target',
install_dir: user_unit_dir,
install_tag: 'runtime',
)

conf_data = configuration_data()
conf_data.set('PREFIX', get_option('prefix'))
conf_data.set('BINDIR', get_option('bindir'))
user_unit_dir = systemd.get_variable(pkgconfig: 'systemduserunitdir',
pkgconfig_define: ['prefix', get_option('prefix')])

configure_file(
configuration: conf_data,
input: 'hyprland-session.service.in',
output: '@BASENAME@',
install_dir: user_unit_dir )
install_dir: user_unit_dir
)
Loading