refactor: users/services: have waitExists support waiting on multiple paths

This commit is contained in:
Colin 2024-03-23 17:28:29 +00:00
parent f65d3d04dc
commit 2e58353b0e
3 changed files with 14 additions and 16 deletions

View File

@ -42,10 +42,10 @@ in
mkdir -p $PIPEWIRE_RUNTIME_DIR mkdir -p $PIPEWIRE_RUNTIME_DIR
exec pipewire exec pipewire
''; '';
readiness.waitCommand = pkgs.writeShellScript "pipewire-wait-started" '' readiness.waitExists = [
test -e "$PIPEWIRE_RUNTIME_DIR/pipewire-0" && \ "$PIPEWIRE_RUNTIME_DIR/pipewire-0"
test -e "$PIPEWIRE_RUNTIME_DIR/pipewire-0-manager" "$PIPEWIRE_RUNTIME_DIR/pipewire-0-manager"
''; ];
cleanupCommand = ''rm -f "$PIPEWIRE_RUNTIME_DIR/{pipewire-0,pipewire-0.lock,pipewire-0-manager,pipewire-0-manager.lock}"''; cleanupCommand = ''rm -f "$PIPEWIRE_RUNTIME_DIR/{pipewire-0,pipewire-0.lock,pipewire-0-manager,pipewire-0-manager.lock}"'';
}; };
services.pipewire-pulse = { services.pipewire-pulse = {
@ -53,10 +53,10 @@ in
depends = [ "pipewire" ]; depends = [ "pipewire" ];
partOf = [ "sound" ]; partOf = [ "sound" ];
command = "pipewire-pulse"; command = "pipewire-pulse";
readiness.waitCommand = pkgs.writeShellScript "pipewire-pulse-wait-started" '' readiness.waitExists = [
test -e "$XDG_RUNTIME_DIR/pulse/native" && \ "$XDG_RUNTIME_DIR/pulse/native"
test -e "$XDG_RUNTIME_DIR/pulse/pid" "$XDG_RUNTIME_DIR/pulse/pid"
''; ];
cleanupCommand = ''rm -f "$XDG_RUNTIME_DIR/pulse/{native,pid}"''; cleanupCommand = ''rm -f "$XDG_RUNTIME_DIR/pulse/{native,pid}"'';
}; };
}; };

View File

@ -230,10 +230,7 @@ in
mkdir -p /tmp/.X11-unix # for Xwayland mkdir -p /tmp/.X11-unix # for Xwayland
exec sway exec sway
''; '';
# readiness.waitExists = "$SWAYSOCK"; readiness.waitExists = [ "$SWAYSOCK" "$WAYLAND_DISPLAY" ];
readiness.waitCommand = pkgs.writeShellScript "sway-readycheck" ''
test -e "$SWAYSOCK" && test -e "$WAYLAND_DISPLAY"
'';
}; };
# link the graphical-session into the default target, so sway gets auto-started # link the graphical-session into the default target, so sway gets auto-started
services.graphical-session.partOf = [ "default" ]; services.graphical-session.partOf = [ "default" ];

View File

@ -67,8 +67,8 @@ let
''; '';
}; };
readiness.waitExists = mkOption { readiness.waitExists = mkOption {
type = types.nullOr types.str; type = types.coercedTo types.str toList (types.listOf types.str);
default = null; default = [];
description = '' description = ''
path to a directory or file whose existence signals the service's readiness. path to a directory or file whose existence signals the service's readiness.
this is expanded as a shell expression, and may contain variables like `$HOME`, etc. this is expanded as a shell expression, and may contain variables like `$HOME`, etc.
@ -80,8 +80,9 @@ let
(lib.mkIf (config.readiness.waitDbus != null) (lib.mkIf (config.readiness.waitDbus != null)
''${pkgs.systemdMinimal}/bin/busctl --user status "${config.readiness.waitDbus}" > /dev/null'' ''${pkgs.systemdMinimal}/bin/busctl --user status "${config.readiness.waitDbus}" > /dev/null''
) )
(lib.mkIf (config.readiness.waitExists != null) (lib.mkIf (config.readiness.waitExists != [])
''test -e "${config.readiness.waitExists}"'' # e.g.: test -e /foo -a -e /bar
("test -e " + (lib.concatStringsSep " -a -e " config.readiness.waitExists))
) )
]; ];
}; };