From e6c00e62159675d0a4bfcce84c18cfed90dad3b7 Mon Sep 17 00:00:00 2001 From: Colin Date: Thu, 21 Mar 2024 16:59:04 +0000 Subject: [PATCH] users/services: implement dbus readiness checks for s6-rc --- hosts/common/programs/pipewire.nix | 4 ++-- hosts/common/programs/playerctl.nix | 2 +- .../swaynotificationcenter/default.nix | 2 +- .../programs/xdg-desktop-portal-gtk.nix | 2 +- .../programs/xdg-desktop-portal-wlr.nix | 2 +- hosts/common/programs/xdg-desktop-portal.nix | 4 ++-- modules/users/default.nix | 20 ++++++++++++------- modules/users/s6-rc.nix | 8 ++++---- 8 files changed, 25 insertions(+), 19 deletions(-) diff --git a/hosts/common/programs/pipewire.nix b/hosts/common/programs/pipewire.nix index d10fc539..f6e2a516 100644 --- a/hosts/common/programs/pipewire.nix +++ b/hosts/common/programs/pipewire.nix @@ -34,7 +34,7 @@ in # env PIPEWIRE_LOG_SYSTEMD=false" # env PIPEWIRE_DEBUG"*:3,mod.raop*:5,pw.rtsp-client*:5" command = "pipewire"; - pollReadyCommand = pkgs.writeShellScript "pipewire-wait-started" '' + readiness.waitCommand = pkgs.writeShellScript "pipewire-wait-started" '' [ -e "$XDG_RUNTIME_DIR/pipewire-0" ] && \ [ -e "$XDG_RUNTIME_DIR/pipewire-0-manager" ] ''; @@ -45,7 +45,7 @@ in depends = [ "pipewire" ]; partOf = [ "sound" ]; command = "pipewire-pulse"; - pollReadyCommand = pkgs.writeShellScript "pipewire-pulse-wait-started" '' + readiness.waitCommand = pkgs.writeShellScript "pipewire-pulse-wait-started" '' [ -e "$XDG_RUNTIME_DIR/pulse/native" ] && \ [ -e "$XDG_RUNTIME_DIR/pulse/pid" ] ''; diff --git a/hosts/common/programs/playerctl.nix b/hosts/common/programs/playerctl.nix index 9a7f45c0..01c3f3e6 100644 --- a/hosts/common/programs/playerctl.nix +++ b/hosts/common/programs/playerctl.nix @@ -10,7 +10,7 @@ documentation = [ "https://github.com/altdesktop/playerctl/issues/161" ]; partOf = [ "default" ]; #< TODO: maybe better to zero `wantedBy` here and have the specific consumers (e.g. swaync) explicitly depend on this. command = "playerctld"; - # serviceConfig.BusName = "org.mpris.MediaPlayer2.Player"; + # readiness.waitDbus = "org.mpris.MediaPlayer2.Player"; #< doesn't work... did the endpoint change? }; }; } diff --git a/hosts/common/programs/swaynotificationcenter/default.nix b/hosts/common/programs/swaynotificationcenter/default.nix index 0b84aca2..9cdbc95c 100644 --- a/hosts/common/programs/swaynotificationcenter/default.nix +++ b/hosts/common/programs/swaynotificationcenter/default.nix @@ -475,7 +475,7 @@ in partOf = [ "graphical-session" ]; command = "env G_MESSAGES_DEBUG=all swaync"; - # serviceConfig.BusName = "org.freedesktop.Notifications"; + readiness.waitDbus = "org.freedesktop.Notifications"; }; }; diff --git a/hosts/common/programs/xdg-desktop-portal-gtk.nix b/hosts/common/programs/xdg-desktop-portal-gtk.nix index eb4ec3fc..f86a0007 100644 --- a/hosts/common/programs/xdg-desktop-portal-gtk.nix +++ b/hosts/common/programs/xdg-desktop-portal-gtk.nix @@ -45,7 +45,7 @@ in dependencyOf = [ "xdg-desktop-portal" ]; command = "${cfg.package}/libexec/xdg-desktop-portal-gtk"; - serviceConfig.BusName = "org.freedesktop.impl.portal.desktop.gtk"; + readiness.waitDbus = "org.freedesktop.impl.portal.desktop.gtk"; }; }; } diff --git a/hosts/common/programs/xdg-desktop-portal-wlr.nix b/hosts/common/programs/xdg-desktop-portal-wlr.nix index 3958bae8..86e144be 100644 --- a/hosts/common/programs/xdg-desktop-portal-wlr.nix +++ b/hosts/common/programs/xdg-desktop-portal-wlr.nix @@ -30,7 +30,7 @@ in dependencyOf = [ "xdg-desktop-portal" ]; command = "${cfg.package}/libexec/xdg-desktop-portal-wlr"; - serviceConfig.BusName = "org.freedesktop.impl.portal.desktop.wlr"; + readiness.waitDbus = "org.freedesktop.impl.portal.desktop.wlr"; }; }; } diff --git a/hosts/common/programs/xdg-desktop-portal.nix b/hosts/common/programs/xdg-desktop-portal.nix index 1cc6c6c1..c1dbb769 100644 --- a/hosts/common/programs/xdg-desktop-portal.nix +++ b/hosts/common/programs/xdg-desktop-portal.nix @@ -67,7 +67,7 @@ in # "G_MESSAGES_DEBUG=all" #< also applies to all apps launched by the portal "${cfg.package}/libexec/xdg-desktop-portal" ]; - serviceConfig.BusName = "org.freedesktop.portal.Desktop"; + readiness.waitDbus = "org.freedesktop.portal.Desktop"; }; services.xdg-permission-store = { @@ -82,7 +82,7 @@ in "XDG_DESKTOP_PORTAL_DIR=$HOME/.config/xdg-desktop-portal" "${cfg.package}/libexec/xdg-permission-store" ]; - serviceConfig.BusName = "org.freedesktop.impl.portal.PermissionStore"; + readiness.waitDbus = "org.freedesktop.impl.portal.PermissionStore"; }; # also available: ${cfg.package}/libexec/xdg-document-portal # - diff --git a/modules/users/default.nix b/modules/users/default.nix index 275e6cb3..477cdd4a 100644 --- a/modules/users/default.nix +++ b/modules/users/default.nix @@ -1,10 +1,10 @@ -{ config, lib, options, sane-lib, ... }: +{ config, lib, options, pkgs, sane-lib, ... }: let sane-user-cfg = config.sane.user; cfg = config.sane.users; path-lib = sane-lib.path; - serviceType = with lib; types.submodule { + serviceType = with lib; types.submodule ({ config, ... }: { options = { description = mkOption { type = types.str; @@ -49,25 +49,31 @@ let restart of the service (if applicable) is blocked on this command. ''; }; - pollReadyCommand = mkOption { + readiness.waitCommand = mkOption { type = types.nullOr (types.coercedTo types.package toString types.str); default = null; description = '' - path to executable which exits zero only when the service is ready. + command or path to executable which exits zero only when the service is ready. this may be invoked repeatedly (with delay), though it's not an error for it to block either (it may, though, be killed and restarted if it blocks too long) ''; }; - serviceConfig.BusName = mkOption { + readiness.waitDbus = mkOption { type = types.nullOr types.str; default = null; description = '' name of the dbus name this service is expected to register. - only once the name is registered will the service be considered "active". + only once the name is registered will the service be considered "ready". ''; }; }; - }; + config = { + readiness.waitCommand = lib.mkIf + (config.readiness.waitDbus != null) + ''${pkgs.systemdMinimal}/bin/busctl --user status "${config.readiness.waitDbus}" > /dev/null'' + ; + }; + }); userOptions = { options = with lib; { fs = mkOption { diff --git a/modules/users/s6-rc.nix b/modules/users/s6-rc.nix index f8154668..74afab9c 100644 --- a/modules/users/s6-rc.nix +++ b/modules/users/s6-rc.nix @@ -156,7 +156,7 @@ let s6SvcsFromConfigServices = services: lib.mapAttrsToList (name: service: { inherit name; - check = service.pollReadyCommand; + check = service.readiness.waitCommand; contents = builtins.attrNames ( lib.filterAttrs (_: cfg: lib.elem name cfg.partOf) services ); @@ -180,7 +180,7 @@ let depends = []; dependencyOf = []; partOf = []; - pollReadyCommand = null; + readiness.waitCommand = null; }; "graphical-session" = { command = null; @@ -189,7 +189,7 @@ let depends = []; dependencyOf = []; partOf = []; - pollReadyCommand = null; + readiness.waitCommand = null; }; "sound" = { command = null; @@ -198,7 +198,7 @@ let depends = []; dependencyOf = []; partOf = [ "default" ]; - pollReadyCommand = null; + readiness.waitCommand = null; }; }; in