nix-community / home-manager

Manage a user environment using Nix [maintainer=@rycee]
https://nix-community.github.io/home-manager/
MIT License
6.79k stars 1.78k forks source link

Starting Waybar at login with systemd is flaky #3599

Open pacien opened 1 year ago

pacien commented 1 year ago

Starting Waybar at login with systemd is flaky

Sometimes it starts fine, sometimes it starts but without being able to communicate with Sway, sometimes it doesn't manage to start at all (maxing out the restart counter).

Relevant config keys, logging in with greetd:

{
  wayland.windowManager.sway.systemdIntegration = true;
  programs.waybar.systemd.enable = true;

  # failing with either:
  programs.waybar.systemd.target = "sway-session.target";
  programs.waybar.systemd.target = "graphical-session.target";
}

Partial start failure:

systemd[2504]: waybar.service: Scheduled restart job, restart counter is at 9.
systemd[2504]: Stopped Highly customizable Wayland bar for Sway and Wlroots based compositors..
systemd[2504]: Started Highly customizable Wayland bar for Sway and Wlroots based compositors..
.waybar-wrapped[3972934]: AT-SPI: Error retrieving accessibility bus address: org.freedesktop.DBus.Error.ServiceUnknown: The name org.a11y.Bus was not provided by any .service files
waybar[3972934]: [2023-01-16 07:44:39.459] [info] Using configuration file /home/kea/.config/waybar/config
waybar[3972934]: [2023-01-16 07:44:39.459] [info] Using CSS file /home/kea/.config/waybar/style.css
waybar[3972934]: [2023-01-16 07:44:39.463] [warning] module sway/mode: Disabling module "sway/mode", Unable to connect to Sway
waybar[3972934]: [2023-01-16 07:44:39.463] [warning] module sway/workspaces: Disabling module "sway/workspaces", Unable to connect to Sway
waybar[3972934]: [2023-01-16 07:44:39.463] [warning] module sway/window: Disabling module "sway/window", Unable to connect to Sway

Full start failure:

systemd[2504]: waybar.service: Scheduled restart job, restart counter is at 14.
systemd[2504]: Stopped Highly customizable Wayland bar for Sway and Wlroots based compositors..
systemd[2504]: Started Highly customizable Wayland bar for Sway and Wlroots based compositors..
.waybar-wrapped[4093572]: cannot open display: :0
systemd[2504]: waybar.service: Main process exited, code=exited, status=1/FAILURE
systemd[2504]: waybar.service: Failed with result 'exit-code'.

Versions:

CC maintainers: @berbiche

pacien commented 1 year ago

A simple workaround is to let the window manager start Waybar itself instead of using systemd.

For example, with Sway:

     wayland.windowManager.sway.config = {
-      bars = [ ];  # disable swaybar
+      bars = [{ command = "waybar"; }];
     };

     programs.waybar = {
       enable = true;

-      systemd = {
-        enable = true;
-        target = "sway-session.target";
-      };
berbiche commented 1 year ago

Hi @pacien,

NixOS has a "nasty" behavior and starts the graphical-session.target before launching the DM.

This works alright when using X11, where the DISPLAY doesn't change, but leads to services that randomly fail to start under Wayland.

I personally used a patch to nixpkgs to disable this behavior. I don't use Linux/Sway at all these days so I won't upstream my changes.

You can have a look here:

https://github.com/berbiche/dotfiles/commit/0d8a727df01b8b28f96f2ad57e06ac0e3dc8f217

stale[bot] commented 1 year ago

Thank you for your contribution! I marked this issue as stale due to inactivity. Please be considerate of people watching this issue and receiving notifications before commenting 'I have this issue too'. We welcome additional information that will help resolve this issue. Please read the relevant sections below before commenting.

If you are the original author of the issue

* If this is resolved, please consider closing it so that the maintainers know not to focus on this. * If this might still be an issue, but you are not interested in promoting its resolution, please consider closing it while encouraging others to take over and reopen an issue if they care enough. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

If you are not the original author of the issue

* If you are also experiencing this issue, please add details of your situation to help with the debugging process. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

Memorandum on closing issues

Don't be afraid to manually close an issue, even if it holds valuable information. Closed issues stay in the system for people to search, read, cross-reference, or even reopen – nothing is lost! Closing obsolete issues is an important way to help maintainers focus their time and effort.

pinpox commented 1 year ago

Still happening for me. Any chance we can fix this in the home-manager module?

rycee commented 1 year ago

An (untested) alternative may be to do something like

diff --git a/modules/programs/waybar.nix b/modules/programs/waybar.nix
index efc34a30..ef2827fa 100644
--- a/modules/programs/waybar.nix
+++ b/modules/programs/waybar.nix
@@ -308,8 +308,8 @@ in {
           Description =
             "Highly customizable Wayland bar for Sway and Wlroots based compositors.";
           Documentation = "https://github.com/Alexays/Waybar/wiki";
-          PartOf = [ "graphical-session.target" ];
-          After = [ "graphical-session.target" ];
+          PartOf = [ "tray.target" ];
+          ConditionEnvironment = "WAYLAND_DISPLAY";
         };

         Service = {
@@ -319,7 +319,7 @@ in {
           KillMode = "mixed";
         };

-        Install = { WantedBy = [ cfg.systemd.target ]; };
+        Install.WantedBy = [ "tray.target" ];
       };
     })
   ]);
diff --git a/modules/services/window-managers/i3-sway/sway.nix b/modules/services/window-managers/i3-sway/sway.nix
index 9031a0a7..ee0e9d75 100644
--- a/modules/services/window-managers/i3-sway/sway.nix
+++ b/modules/services/window-managers/i3-sway/sway.nix
@@ -481,7 +481,7 @@ in {
         Unit = {
           Description = "sway compositor session";
           Documentation = [ "man:systemd.special(7)" ];
-          BindsTo = [ "graphical-session.target" ];
+          BindsTo = [ "graphical-session.target" "tray.target" ];
           Wants = [ "graphical-session-pre.target" ]
             ++ optional cfg.systemd.xdgAutostart "xdg-desktop-autostart.target";
           After = [ "graphical-session-pre.target" ];
stale[bot] commented 11 months ago

Thank you for your contribution! I marked this issue as stale due to inactivity. Please be considerate of people watching this issue and receiving notifications before commenting 'I have this issue too'. We welcome additional information that will help resolve this issue. Please read the relevant sections below before commenting.

If you are the original author of the issue

* If this is resolved, please consider closing it so that the maintainers know not to focus on this. * If this might still be an issue, but you are not interested in promoting its resolution, please consider closing it while encouraging others to take over and reopen an issue if they care enough. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

If you are not the original author of the issue

* If you are also experiencing this issue, please add details of your situation to help with the debugging process. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

Memorandum on closing issues

Don't be afraid to manually close an issue, even if it holds valuable information. Closed issues stay in the system for people to search, read, cross-reference, or even reopen – nothing is lost! Closing obsolete issues is an important way to help maintainers focus their time and effort.

hacker1024 commented 8 months ago

Not stale. Something along the lines of the proposed systemd changes should be implemented as Waybar has a tray module.

madonius commented 4 months ago

I also have the same issue.

aacebedo commented 3 months ago

I also have this issue. I cannot logout and relogin without half of may services broken.

stale[bot] commented 2 weeks ago

Thank you for your contribution! I marked this issue as stale due to inactivity. Please be considerate of people watching this issue and receiving notifications before commenting 'I have this issue too'. We welcome additional information that will help resolve this issue. Please read the relevant sections below before commenting.

If you are the original author of the issue

* If this is resolved, please consider closing it so that the maintainers know not to focus on this. * If this might still be an issue, but you are not interested in promoting its resolution, please consider closing it while encouraging others to take over and reopen an issue if they care enough. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

If you are not the original author of the issue

* If you are also experiencing this issue, please add details of your situation to help with the debugging process. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

Memorandum on closing issues

Don't be afraid to manually close an issue, even if it holds valuable information. Closed issues stay in the system for people to search, read, cross-reference, or even reopen – nothing is lost! Closing obsolete issues is an important way to help maintainers focus their time and effort.