Skip to content

wayland: create tray.target if xsession is not enabled#6332

Merged
teto merged 1 commit intonix-community:masterfrom
onemoresuza:tray-target-wayland
Feb 6, 2025
Merged

wayland: create tray.target if xsession is not enabled#6332
teto merged 1 commit intonix-community:masterfrom
onemoresuza:tray-target-wayland

Conversation

@onemoresuza
Copy link
Copy Markdown
Contributor

Description

As it current stands, the tray target is only created if xsession is
enabled. This causes services that depend on it to fail on wayland
sessions on configurations that do not have services.xsession.enable = true; or the workaround as the following:

{config, lib, ...}: {
  systemd.user.targets.tray = lib.mkIf (!config.xsession.enable) {
    Unit = {
      Description = "Home Manager System Tray";
      Requires = [ "graphical-session-pre.target" ];
    };
  };
}

This PR addresses #6329 and
#2064,
albeit I do not think it is the greatest solution, since it allows the
targets defined by the xsession and wayland modules to be kept out of
sync.

I'd recommend defining tray.target independently from either one of
those modules, since virtually every graphical session that requires a
system tray would need such target.

Checklist

  • Change is backwards compatible. May break config of non xsession enabled
    users that do not use mkForce for the tray target definition.

  • Code formatted with ./format.

  • Code tested through nix-shell --pure tests -A run.all or nix develop --ignore-environment .#all using Flakes.

  • Test cases updated/added. See example.

  • Commit messages are formatted like

    {component}: {description}
    
    {long description}
    

    See CONTRIBUTING for more information and recent commit messages for examples.

  • If this PR adds a new module

    • Added myself as module maintainer. See example.

Maintainer CC

@teto
Copy link
Copy Markdown
Collaborator

teto commented Jan 20, 2025

the target looks defined in several modules like modules/services/window-managers/wayfire.nix. / river /hyperland/sway. shouldn't the tray.target be removed from there as well ?

I'd recommend defining tray.target independently from either one of
those modules, since virtually every graphical session that requires a
system tray would need such target.

fine by me. We could also merge the current approach as a first step.

@onemoresuza
Copy link
Copy Markdown
Contributor Author

@teto, you're right. I've added some commits removing them to be squashed if this is to be merged.

Regarding setting tray.target independently from either the xsession or a window manager, systemd.user.targets.tray could be a read-only/internal option from either xsession or wayland so that it would not, as my current implementation, allow the tray targets to get out of sync, since there'd be only one.

@onemoresuza onemoresuza force-pushed the tray-target-wayland branch 2 times, most recently from aecf6ec to 9bfea70 Compare January 29, 2025 14:00
@onemoresuza onemoresuza marked this pull request as ready for review January 29, 2025 14:00
@onemoresuza
Copy link
Copy Markdown
Contributor Author

onemoresuza commented Jan 29, 2025

Created a trayTarget option (internal/read-only) under xsession, which is not only used by it, but also by wayland's config when the former is not enabled.

@onemoresuza
Copy link
Copy Markdown
Contributor Author

Maintainer CC for xsession and wayland:

@thiagokokada @rycee

Create a internal/read-only trayTarget option for the xsession, which is
also used in wayland's config, if the former is not enabled.

Remove all other definitions of `systemd.user.targets.tray`, i. e, the
ones from the following modules: hyprland, sway, river and wayfire.
@onemoresuza
Copy link
Copy Markdown
Contributor Author

Just added the removal of the systemd.user.targets.tray definitions from other modules to the git commit message.

Comment thread modules/xsession.nix
@onemoresuza
Copy link
Copy Markdown
Contributor Author

onemoresuza commented Jan 29, 2025 via email

@thiagokokada
Copy link
Copy Markdown
Contributor

  • Unit = { + Description = "Home Manager System Tray"; + Requires = [ "graphical-session-pre.target" ]; + }; This is the implementation that is fine, but the option shouldn't implement a whole Unit unless there is a good reason to do so.
    I've set it just like the implementation because, as of now, it's a readOnly/internal option, so the user would not be allowed to change it. Do you see a use case in which the user would have to modify systemd.user.target.tray?

Oh ok, true, didn't realise that this was set to internal/readOnly.

I can find a few cases where this would be a good idea to change it, for example I know that grapgical-session-pre.target is a bad choice for Hyprland in a few other cases at least (not sure about the tray though).

I would recommend at least making the actual target an option just to make sure that we can cover other use cases, but the current implementation looks fine and we can add an option later too if you want.

@onemoresuza
Copy link
Copy Markdown
Contributor Author

I can find a few cases where this would be a good idea to change it, for example I know that grapgical-session-pre.target is a bad choice for Hyprland in a few other cases at least (not sure about the tray though).

I would recommend at least making the actual target an option just to make sure that we can cover other use cases, but the current implementation looks fine and we can add an option later too if you want.

I think we could create an option under the wayland module for enabling the systemd tray target, while leaving as is for the xsession one, since, on the latter, the tray target is always created.

I saw that the wayland module has a systemd.target option already. For a more smooth transition, I'd suggest something like the following:

# wayland module

options = {
  wayland.systemd.enableTrayTarget = mkEnableOption "tray.target" // { default = true; };
};

config = mkIf config.wayland.systemd.enableTrayTarget {
  systemd.user.targets.tray = config.xsession.trayTarget;
};

That would allow modules, for instance, hyprland's, to not have a tray.target:

# hyprland module

config = mkIf cfg.enable {
  assertions = [
    {
      assertion = !config.wayland.systemd.enableTrayTarget;
      message = ''
        hyprland cannot work correctly when `wayland.systemd.enableTrayTarget` is enabled.
      '';
    }
  ];

  wayland.systemd.enableTrayTarget = false;
};

What do you think?

@thiagokokada
Copy link
Copy Markdown
Contributor

What do you think?

I think the main issue is that the tray target is hardcoded to graphical-session-pre.target that is known to cause some issues in Hyprland and probably other Wayland DMs too, not that we need to enable/disable this target. graphical-session.target is more reliable in general since it ensures that everything in the graphical session is initialised (e.g.: WAYLAND_DISPLAY).

In my opinion we should:

  • Either change the target to graphical-session.target (this would change the behavior but should work fine)
  • Or allow the target to be configurable

@onemoresuza
Copy link
Copy Markdown
Contributor Author

It can be made configurable by removing the readOnly/internal attributes; however, as of now, wayland DM modules would have to access an xsession attribute to change their tray.target.

This goes back to what I've mention on the description of this PR:

I'd recommend defining tray.target independently from either one of
those modules, since virtually every graphical session that requires a
system tray would need such target.

We could either create a graphical-session module, defining the trayTarget on it, or move it to another module like systemd's.

@onemoresuza
Copy link
Copy Markdown
Contributor Author

It can be made configurable by removing the readOnly/internal attributes; however, as of now, wayland DM modules would have to access an xsession attribute to change their tray.target.

This goes back to what I've mention on the description of this PR:

I'd recommend defining tray.target independently from either one of
those modules, since virtually every graphical session that requires a
system tray would need such target.

We could either create a graphical-session module, defining the trayTarget on it, or move it to another module like systemd's.

@thiagokokada, are you approving the current state of the PR or the proposed changes mentioned above?

@thiagokokada
Copy link
Copy Markdown
Contributor

@thiagokokada, are you approving the current state of the PR or the proposed changes mentioned above?

The current state, it doesn't make sense to approve for something that doesn't exist.

I think we can merge it in the current state and change it to accommodate customization in the future.

@onemoresuza
Copy link
Copy Markdown
Contributor Author

Got it.

@teto teto merged commit 4337992 into nix-community:master Feb 6, 2025
lordkekz pushed a commit to lordkekz/home-manager that referenced this pull request Feb 9, 2025
…#6332)

Create a internal/read-only trayTarget option for the xsession, which is
also used in wayland's config, if the former is not enabled.

Remove all other definitions of `systemd.user.targets.tray`, i. e, the
ones from the following modules: hyprland, sway, river and wayfire.
lordkekz pushed a commit to lordkekz/home-manager that referenced this pull request Feb 9, 2025
…#6332)

Create a internal/read-only trayTarget option for the xsession, which is
also used in wayland's config, if the former is not enabled.

Remove all other definitions of `systemd.user.targets.tray`, i. e, the
ones from the following modules: hyprland, sway, river and wayfire.
@lordkekz lordkekz mentioned this pull request Feb 9, 2025
6 tasks
teto pushed a commit to teto/home-manager that referenced this pull request Feb 11, 2025
…#6332)

Create a internal/read-only trayTarget option for the xsession, which is
also used in wayland's config, if the former is not enabled.

Remove all other definitions of `systemd.user.targets.tray`, i. e, the
ones from the following modules: hyprland, sway, river and wayfire.
tetov pushed a commit to tetov/home-manager that referenced this pull request Feb 16, 2025
…#6332)

Create a internal/read-only trayTarget option for the xsession, which is
also used in wayland's config, if the former is not enabled.

Remove all other definitions of `systemd.user.targets.tray`, i. e, the
ones from the following modules: hyprland, sway, river and wayfire.
347Online pushed a commit to 347Online/home-manager that referenced this pull request Mar 1, 2025
…#6332)

Create a internal/read-only trayTarget option for the xsession, which is
also used in wayland's config, if the former is not enabled.

Remove all other definitions of `systemd.user.targets.tray`, i. e, the
ones from the following modules: hyprland, sway, river and wayfire.
nfelber pushed a commit to nfelber/home-manager that referenced this pull request Mar 19, 2025
…#6332)

Create a internal/read-only trayTarget option for the xsession, which is
also used in wayland's config, if the former is not enabled.

Remove all other definitions of `systemd.user.targets.tray`, i. e, the
ones from the following modules: hyprland, sway, river and wayfire.
khaneliman pushed a commit that referenced this pull request Apr 25, 2025
Create a internal/read-only trayTarget option for the xsession, which is
also used in wayland's config, if the former is not enabled.

Remove all other definitions of `systemd.user.targets.tray`, i. e, the
ones from the following modules: hyprland, sway, river and wayfire.
Zocker1999NET added a commit to Zocker1999NET/server that referenced this pull request Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants