-
Notifications
You must be signed in to change notification settings - Fork 14
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 services that depend on niri don't work as expected (maybe solved??) #348
Comments
For the systemd unit @YaLTeR do you have any input on this? why it's done the way it is now, rather than something more similar to what everyone else seems to be doing? It would definitely be a lot nicer if we could rely on |
Relying on graphical-session.target is the intended way and, well, it works on my machine (tm). This is what I describe here: https://github.com/YaLTeR/niri/wiki/Example-systemd-Setup The only reason niri.service.wants is part of that, is to restrict those example services to only start in niri (and not if you log into GNOME for example). If things didn't work, they would start at exactly the same time as niri.service, which is indeed too early, but the graphical-session rules make them start at the correct time. I'm not sure why it's not working on NixOS. |
To elaborate, this is the expected order of events:
|
It seems to be a NixOS problem:
It's crazy that this has been around for so long. |
I just learned about uwsm (Universal Wayland Session Manager), which got added to Nixpkgs recently. Some links that might be of interest:
|
The issue persists with the recently merged UWSM module. ╰─ sudo journalctl -xb | rg uwsm
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: Preparing environment for niri...
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: Exporting variables to systemd user manager:
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: DOCKER_HOST
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: EDITOR
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: GTK_PATH
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: INFOPATH
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: LESSKEYIN_SYSTEM
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: LESSOPEN
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: LIBEXEC_PATH
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: NIXPKGS_CONFIG
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: NIX_PATH
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: NIX_PROFILES
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: NIX_USER_PROFILE_DIR
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: PAGER
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: PATH
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: QTWEBKIT_PLUGIN_PATH
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: SSH_ASKPASS
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: TERM
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: TERMINFO_DIRS
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: XCURSOR_PATH
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: XDG_BACKEND
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: XDG_CONFIG_DIRS
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: XDG_CURRENT_DESKTOP
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: XDG_DATA_DIRS
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: XDG_MENU_PREFIX
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: XDG_SESSION_DESKTOP
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: XDG_SESSION_ID
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: XDG_SESSION_TYPE
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: XDG_VTNR
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: __ETC_PROFILE_DONE
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: __NIXOS_SET_ENVIRONMENT_DONE
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: Variables marked for cleanup from systemd user manager on stop:
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: DISPLAY
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: DOCKER_HOST
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: EDITOR
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: GTK_PATH
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: INFOPATH
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: LANG
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: LESSKEYIN_SYSTEM
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: LESSOPEN
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: LIBEXEC_PATH
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: NIXPKGS_CONFIG
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: NIX_PATH
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: NIX_PROFILES
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: NIX_USER_PROFILE_DIR
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: PAGER
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: PATH
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: QTWEBKIT_PLUGIN_PATH
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: SSH_ASKPASS
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: TERM
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: TERMINFO_DIRS
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: WAYLAND_DISPLAY
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: XCURSOR_PATH
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: XCURSOR_SIZE
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: XCURSOR_THEME
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: XDG_BACKEND
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: XDG_CONFIG_DIRS
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: XDG_CURRENT_DESKTOP
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: XDG_DATA_DIRS
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: XDG_MENU_PREFIX
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: XDG_SESSION_DESKTOP
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: XDG_SESSION_ID
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: XDG_SESSION_TYPE
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: XDG_VTNR
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: __ETC_PROFILE_DONE
Aug 29 19:13:44 nixos uwsm_env-preloader[2163]: __NIXOS_SET_ENVIRONMENT_DONE
Aug 29 19:13:44 nixos uwsm_niri[2211]: Starting: /run/current-system/sw/bin/niri...
Aug 29 19:13:44 nixos uwsm_niri[2211]: 2024-08-29T17:13:44.461718Z INFO niri: starting version unstable 2024-08-26 (commit 598b27f83c4d4dd72c5cfbd06ca60b12e2833429)
Aug 29 19:13:44 nixos uwsm_niri[2211]: 2024-08-29T17:13:44.469504Z DEBUG niri_config: loaded config from "/home/etho/.config/niri/config.kdl"
Aug 29 19:13:44 nixos uwsm_niri[2211]: 2024-08-29T17:13:44.944623Z INFO niri::backend::tty: using as the render node: "/dev/dri/renderD128"
Aug 29 19:13:45 nixos uwsm_niri[2211]: 2024-08-29T17:13:45.069355Z DEBUG niri::backend::tty: device added: 57857 "/dev/dri/card1"
Aug 29 19:13:45 nixos uwsm_niri[2211]: 2024-08-29T17:13:45.380679Z DEBUG niri::backend::tty: this is the primary node
Aug 29 19:13:45 nixos uwsm_niri[2211]: 2024-08-29T17:13:45.380692Z DEBUG niri::backend::tty: this is the primary render node
Aug 29 19:13:45 nixos uwsm_niri[2211]: 2024-08-29T17:13:45.428766Z DEBUG niri::backend::tty: device changed: 57857
Aug 29 19:13:45 nixos uwsm_niri[2211]: 2024-08-29T17:13:45.433015Z DEBUG niri::backend::tty: connecting connector: DP-1
Aug 29 19:13:45 nixos uwsm_niri[2211]: 2024-08-29T17:13:45.433042Z DEBUG niri::backend::tty: picking mode: Mode { name: "2560x1440", clock: 645000, size: (2560, 1440), hsync: (2568, 2600, 2640), vsync: (1446, 1454, 1480), hskew: 0, vscan: 0, vrefresh: 165, mode_type: ModeTypeFlags(DRIVER) }
Aug 29 19:13:45 nixos uwsm_niri[2211]: 2024-08-29T17:13:45.433082Z DEBUG niri::backend::tty: set max bpc to 8
Aug 29 19:13:45 nixos uwsm_niri[2211]: 2024-08-29T17:13:45.440093Z DEBUG niri::niri: putting output DP-1 at x=0 y=0
Aug 29 19:13:45 nixos uwsm_niri[2211]: 2024-08-29T17:13:45.440148Z INFO niri: listening on Wayland socket: wayland-1
Aug 29 19:13:45 nixos uwsm_niri[2211]: 2024-08-29T17:13:45.440154Z INFO niri: IPC listening on: /run/user/1000/niri.wayland-1.2211.sock
Aug 29 19:14:50 nixos sudo[2897]: etho : TTY=pts/0 ; PWD=/home/etho ; USER=root ; COMMAND=/run/current-system/sw/bin/journalctl -xb -u uwsm
╰─ systemctl --user status swayidle.service
○ swayidle.service - Idle manager for Wayland
Loaded: loaded (/home/etho/.config/systemd/user/swayidle.service; enabled; preset: enabled)
Active: inactive (dead)
Condition: start condition unmet at Thu 2024-08-29 19:13:44 CEST; 4min 5s ago
└─ ConditionEnvironment=WAYLAND_DISPLAY was not met
Docs: man:swayidle(1)
Aug 29 19:13:44 nixos systemd[2039]: Idle manager for Wayland was skipped because of an unmet condition check (ConditionEnvironment=WAYLAND_DISPLAY). |
I have yet to try UWSM, but my current workaround is to use the session target method. I used the Sway and Hyprland Home Manager modules as reference :
[Unit]
After=graphical-session-pre.target
Before=xdg-desktop-autostart.target
BindsTo=graphical-session.target
Description=niri compositor session
Documentation=man:systemd.special(7)
Wants=graphical-session-pre.target
Wants=xdg-desktop-autostart.target
This is pretty much all I had to do to get user services working. |
I've been able to fix this with just pure systemd config and no I used this code in home-manager to switch to the upstream waybar systemd service in the waybar repo itself: systemd.user.services.waybar = {
Unit = {
After = lib.mkForce [ "graphical-session.target" ];
Requisite = [ "graphical-session.target" ];
};
Service = {
ExecStartPost = "${pkgs.coreutils}/bin/sleep 2";
};
}; I also made a "tray.target" following the sway module in home-manager and set A demo of this method is in this commit in my nix config repo: https://gitlab.com/coffeetables/lower/-/commit/cfc03d0b16b5c213959413097a7e3a950856af34. Theres also a commit after with some comments |
I think the reason that logout then login doesn't work is because graphical-session.target is still active when niri exits and its happening because of the niri-flake-polkit service. If I add this code to my nixos config, I'm no longer experiencing issues with systemd services not starting after logout then login: systemd.user.services.niri-flake-polkit = {
wants = lib.mkForce [];
requisite = [ "graphical-session.target" ];
partOf = [ "graphical-session.target" ];
}; I think its because the niri-session script stops graphical-session.target by starting the niri-shutdown.target which conflicts with graphical-session.target, but niri-flake-polkit service has a dependency on graphical-session.target so systemd chooses to keep graphical-session.target running and stops niri-shutdown.target. |
WAIT WHAT. IT WAS MY FAULT ALL ALONG? I AM SO SORRY Y'ALL 😭 i will investigate this today and fix it if true. thank you @Pacman99 this seems like an entirely plausible diagnosis. |
This seems to work for things like xdg-autostart, thank you!!!!! 🎉 |
@Pacman99 Yeah I have this as well. @sodiboo I think
I was actually doing this before I switched to the session target method. But instead of overriding That said, I have no idea why some services started by HM modules start
Hmm. I usually just wait about 8-10 secs after logging out before logging back in. I'm using polkit-gnome rather than the KDE one from the flake, but the code is almost the same. Only difference is |
Yeah, after discussing it here, it doesn't really make sense. All these services require the compositor to be running before they can start, and only |
I mean I think your service is written well and as @Brisingr05 pointed out it's similar to the systemd service recommended for polkit-gnome. I'm not sure why systemd chooses to keep graphical-session.target up, because in the manual it doesn't mention that behavior and only says that conflicts might not work when one service "requires" the conflicting service. Either way I guess there's no reason for niri-flake-polkit to have a Wants dependency on graphical-session.target since no one is likely to start it manually outside a compositor. |
I guess it's because the polkit service doesn't die when niri shuts down, and other than this it basically runs as "part of" |
Even when I used the session target method encouraged by home-manager I still had to override After for every service so it ended up being more work overall. AFAICT the only advantage of that method is if you want gnome and niri/sway/hyprland to be available at login together and not have waybar and things start with gnome. But I believe UWSM's solution of adding |
Okay, so yeah i've reproduced the same issue described. After closing niri, This solves a lot of the jank i have, and i think i was able to remove all special casing from my config necessary to get waybar working. My I am so sorry for having this be persistently broken for at least 7 months. Hopefully everyone's issues are resolved, or at least mediated, by this new change. Thank you @Pacman99 |
How to solve this, home-manager swayidle failed start. |
You need to override the swayidle service in Home Manager: systemd.user.swayidle.Unit.After = [ "graphical-session.target" ]; |
this shouldn't be necessary :neocat_anxiety: it's already (if this workaround fixes it on your setup, then great do it and just appreciate it working, but there is definitely something wrong because it really shouldn't be necessary. something more fundamental should be fixed in niri-flake and/or niri) |
After 318b1ef, most of my services don't need me to define |
I'm surprised the commit made it so services don't need to have After=graphical-session.target. I don't see why systemd would have any reason to start them after niri since all of them are started when graphical-session.target is started and they are all started before graphical-session.target is reached. |
According to the docs,
I decided to do some testing without any tl;dr:
|
After checking logs, it seems like that happened in my case as well. It's weird that the units completely failed before but manage to get a successful startup now though. EDIT: nix-community/home-manager#5785 would resolve the ordering issue. |
Okay the services restarting and succeeding makes sense. This definitely needs to be properly fixed in the home manager side. It might be good to add something in the Readme here about the issue and how to workaround it. tray.target can be useful for applications that only show their system tray icon if a tray is available when they start up. I binded waybar to tray.target and added |
The systemd integration is quite a mess compared to the Sway and Hyprland modules.
The swayidle service won't start because it doesn't have access to the
WAYLAND_DISPLAY
variable, and the wbg and waybar services work erratically when binded tographical-session.target
.I've seen that in your personal configuration, some hacks had to be implemented to get around these problems, but this is far from desirable...
A solution using a session target would be much better integrated with NixOS/Home Manager, as most modules that need integration provide a
systemdTarget
parameter to set the relevant one. It can also be easily integrated into custom services.I'm not sure whether these changes can be made directly in the NixOS module or whether they need to be made on the niri side, as the author seems to be leaning towards a different solution for systemd integration that uses a session script and no target.
The text was updated successfully, but these errors were encountered: