From 86400f45d606c437d3dde2dcec084ab83470b3c3 Mon Sep 17 00:00:00 2001 From: Colin Date: Sun, 24 Mar 2024 08:53:19 +0000 Subject: [PATCH] swaync: port to s6 --- .../swaynotificationcenter/buttons.nix | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/hosts/common/programs/swaynotificationcenter/buttons.nix b/hosts/common/programs/swaynotificationcenter/buttons.nix index e63b4676..68d207d1 100644 --- a/hosts/common/programs/swaynotificationcenter/buttons.nix +++ b/hosts/common/programs/swaynotificationcenter/buttons.nix @@ -1,5 +1,6 @@ { pkgs }: let + # TODO: move ALL of the scripts into just one helper. systemctl-toggle' = pkgs.writeShellApplication { name = "systemctl-toggle"; runtimeInputs = [ @@ -30,6 +31,35 @@ let }; print-systemd-active = "${print-systemd-active'}/bin/print-systemd-active"; + s6-toggle' = pkgs.writeShellApplication { + name = "s6-toggle"; + runtimeInputs = [ + pkgs.s6 + pkgs.s6-rc + ]; + text = '' + service="$1" + if [ "$(s6-svstat -o wantedup "$XDG_RUNTIME_DIR/s6/live/servicedirs/$service")" = "true" ]; then + s6-rc stop "$service" + else + s6-rc start "$service" + fi + ''; + }; + s6-toggle = "${s6-toggle'}/bin/s6-toggle"; + + print-s6-active' = pkgs.writeShellApplication { + name = "print-s6-active"; + runtimeInputs = [ + pkgs.s6 + ]; + text = '' + # s6-svstat's native output is "true"/"false" as expected by swaync + s6-svstat -o wantedup "$XDG_RUNTIME_DIR/s6/live/servicedirs/$1" + ''; + }; + print-s6-active = "${print-s6-active'}/bin/print-s6-active"; + systemServiceButton = name: label: { # XXX: this is surely broken, due to sandboxing/perms inherit label; @@ -41,8 +71,8 @@ let userServiceButton = name: label: { inherit label; type = "toggle"; - command = "${systemctl-toggle} --user ${name}"; - update-command = "${print-systemd-active} --user ${name}"; + command = "${s6-toggle} ${name}"; + update-command = "${print-s6-active} ${name}"; active = true; }; in