Skip to content

Commit dd9ec5c

Browse files
committed
Fix journal log flood in headless mode
Signed-off-by: Kajus Naujokaitis <[email protected]>
1 parent b82a218 commit dd9ec5c

File tree

2 files changed

+73
-15
lines changed

2 files changed

+73
-15
lines changed

modules/desktop/graphics/ewwbar.nix

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,33 @@ in
115115
description = "ewwbar";
116116
serviceConfig = {
117117
Type = "forking";
118-
ExecCondition = ''
119-
${pkgs.bash}/bin/bash -c "${pkgs.wlr-randr}/bin/wlr-randr > /dev/null 2>&1"
120-
'';
118+
ExecCondition =
119+
let
120+
display-connected = pkgs.writeShellApplication {
121+
name = "display-connected";
122+
runtimeInputs = [
123+
pkgs.jq
124+
pkgs.wlr-randr
125+
];
126+
bashOptions = [ ];
127+
text = ''
128+
# Exits with error if no display is detected
129+
130+
# Retrieve display information
131+
if ! wlr_output_json=$(wlr-randr --json); then
132+
echo "Error: Failed to get display info from wlr-randr"
133+
exit 1
134+
fi
135+
136+
# Check if any displays are connected
137+
if ! echo "$wlr_output_json" | jq -e 'length > 0' > /dev/null; then
138+
echo "Error: No connected displays found."
139+
exit 1
140+
fi
141+
'';
142+
};
143+
in
144+
"${display-connected}/bin/display-connected";
121145
ExecStart = "${ewwScripts.ewwbar-ctrl}/bin/ewwbar-ctrl start";
122146
ExecReload = "${ewwScripts.ewwbar-ctrl}/bin/ewwbar-ctrl reload";
123147
ExecStopPost = ''

modules/desktop/graphics/labwc.config.nix

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -426,21 +426,56 @@ let
426426
auto-display-scale
427427
pkgs.mako
428428
pkgs.wlr-randr
429+
pkgs.jq
429430
];
430431
bashOptions = [ ];
431432
text = ''
432-
# Run the following commands in order every time a display change event is detected
433+
stop_services() {
434+
echo "No displays connected. Stopping ghaf-launcher and ewwbar services."
435+
systemctl --user stop ewwbar ghaf-launcher
436+
}
437+
433438
auto-display-scale # Auto scaling
434439
makoctl set-mode default # Reset mako mode so notifications don't break
435440
436-
if wlr-randr > /dev/null 2>&1; then
437-
# If displays are connected (not headless mode), ensure ewwbar and ghaf-launcher are running
438-
systemctl --user is-active --quiet ewwbar || systemctl --user reload-or-restart ewwbar
439-
systemctl --user is-active --quiet ghaf-launcher || systemctl --user reload-or-restart ghaf-launcher
440-
else
441-
# If all displays were disconnected, we can stop ghaf-launcher and ewwbar services
442-
echo "No displays connected. Stopping ghaf-launcher and ewwbar services"
443-
systemctl --user stop ewwbar ghaf-launcher
441+
# Retrieve display information
442+
if ! wlr_output_json=$(wlr-randr --json); then
443+
echo "Error: Failed to get display info from wlr-randr"
444+
stop_services
445+
fi
446+
447+
# Check if any displays are connected
448+
if ! echo "$wlr_output_json" | jq -e 'length > 0' > /dev/null; then
449+
echo "Error: No connected displays found."
450+
stop_services
451+
fi
452+
453+
# If displays are connected (not headless mode), ensure ewwbar and ghaf-launcher are running
454+
systemctl --user is-active --quiet ewwbar || systemctl --user reload-or-restart ewwbar
455+
systemctl --user is-active --quiet ghaf-launcher || systemctl --user reload-or-restart ghaf-launcher
456+
'';
457+
};
458+
459+
display-connected = pkgs.writeShellApplication {
460+
name = "display-connected";
461+
runtimeInputs = [
462+
pkgs.jq
463+
pkgs.wlr-randr
464+
];
465+
bashOptions = [ ];
466+
text = ''
467+
# Exits with error if no display is detected
468+
469+
# Retrieve display information
470+
if ! wlr_output_json=$(wlr-randr --json); then
471+
echo "Error: Failed to get display info from wlr-randr"
472+
exit 1
473+
fi
474+
475+
# Check if any displays are connected
476+
if ! echo "$wlr_output_json" | jq -e 'length > 0' > /dev/null; then
477+
echo "Error: No connected displays found."
478+
exit 1
444479
fi
445480
'';
446481
};
@@ -501,9 +536,7 @@ in
501536
serviceConfig = {
502537
Type = "simple";
503538
EnvironmentFile = "-/etc/locale.conf";
504-
ExecCondition = ''
505-
${pkgs.bash}/bin/bash -c "${pkgs.wlr-randr}/bin/wlr-randr > /dev/null 2>&1"
506-
'';
539+
ExecCondition = "${display-connected}/bin/display-connected";
507540
ExecStart = "${pkgs.nwg-drawer}/bin/nwg-drawer -r -nofs -nocats -s ${drawerStyle}";
508541
Restart = "always";
509542
RestartSec = "1";
@@ -569,6 +602,7 @@ in
569602
Type = "simple";
570603
Restart = "always";
571604
RestartSec = "5";
605+
ExecCondition = "${display-connected}/bin/display-connected";
572606
ExecStart = "${pkgs.ghaf-audio-control}/bin/GhafAudioControlStandalone --pulseaudio_server=audio-vm:${toString config.ghaf.services.audio.pulseaudioTcpControlPort} --deamon_mode=true --indicator_icon_name=audio-subwoofer";
573607
};
574608

0 commit comments

Comments
 (0)