swaync: factor out a "service-dispatcher"
This commit is contained in:
parent
86400f45d6
commit
774066e53c
|
@ -1,91 +1,23 @@
|
||||||
{ pkgs }:
|
{ pkgs }:
|
||||||
let
|
let
|
||||||
# TODO: move ALL of the scripts into just one helper.
|
serviceButton = svcType: name: label: {
|
||||||
systemctl-toggle' = pkgs.writeShellApplication {
|
|
||||||
name = "systemctl-toggle";
|
|
||||||
runtimeInputs = [
|
|
||||||
pkgs.systemd
|
|
||||||
];
|
|
||||||
text = ''
|
|
||||||
if systemctl is-active "$@"; then
|
|
||||||
systemctl stop "$@"
|
|
||||||
else
|
|
||||||
systemctl start "$@"
|
|
||||||
fi
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
systemctl-toggle = "${systemctl-toggle'}/bin/systemctl-toggle";
|
|
||||||
|
|
||||||
print-systemd-active' = pkgs.writeShellApplication {
|
|
||||||
name = "print-systemd-active";
|
|
||||||
runtimeInputs = [
|
|
||||||
pkgs.systemd
|
|
||||||
];
|
|
||||||
text = ''
|
|
||||||
if systemctl is-active "$@"; then
|
|
||||||
echo true
|
|
||||||
else
|
|
||||||
echo false
|
|
||||||
fi
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
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;
|
inherit label;
|
||||||
type = "toggle";
|
type = "toggle";
|
||||||
command = "/run/wrappers/bin/sudo ${systemctl-toggle} ${name}";
|
command = "swaync-service-dispatcher toggle ${svcType} ${name}";
|
||||||
update-command = "${print-systemd-active} ${name}.service";
|
update-command = "swaync-service-dispatcher print ${svcType} ${name}";
|
||||||
active = true;
|
|
||||||
};
|
|
||||||
userServiceButton = name: label: {
|
|
||||||
inherit label;
|
|
||||||
type = "toggle";
|
|
||||||
command = "${s6-toggle} ${name}";
|
|
||||||
update-command = "${print-s6-active} ${name}";
|
|
||||||
active = true;
|
active = true;
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
gps = systemServiceButton "eg25-control-gps" ""; # GPS services; other icons: gps, ⌖, 🛰, 🌎,
|
gps = serviceButton "systemd" "eg25-control-gps" ""; # GPS services; other icons: gps, ⌖, 🛰, 🌎,
|
||||||
cell-modem = systemServiceButton "eg25-control-powered" ""; # icons: 5g, 📡, 📱, ᯤ, ⚡, , 🌐, 📶, 🗼, , , ,
|
cell-modem = serviceButton "systemd" "eg25-control-powered" ""; # icons: 5g, 📡, 📱, ᯤ, ⚡, , 🌐, 📶, 🗼, , , ,
|
||||||
vpn = systemServiceButton "wg-quick-vpn-servo" "vpn::hn";
|
vpn = serviceButton "systemd" "wg-quick-vpn-servo" "vpn::hn";
|
||||||
|
|
||||||
gnome-calls = userServiceButton "gnome-calls" "SIP";
|
gnome-calls = serviceButton "s6" "gnome-calls" "SIP";
|
||||||
geary = userServiceButton "geary" ""; # email (Geary); other icons: ✉, [E], 📧,
|
geary = serviceButton "s6" "geary" ""; # email (Geary); other icons: ✉, [E], 📧,
|
||||||
abaddon = userServiceButton "abaddon" ""; # Discord chat client; icons: , 🎮
|
abaddon = serviceButton "s6" "abaddon" ""; # Discord chat client; icons: , 🎮
|
||||||
dissent = userServiceButton "dissent" ""; # Discord chat client; icons: , 🎮
|
dissent = serviceButton "s6" "dissent" ""; # Discord chat client; icons: , 🎮
|
||||||
signal-desktop = userServiceButton "signal-desktop" "💬"; # Signal messenger; other icons:
|
signal-desktop = serviceButton "s6" "signal-desktop" "💬"; # Signal messenger; other icons:
|
||||||
dino = userServiceButton "dino" "XMPP"; # XMPP calls (jingle)
|
dino = serviceButton "s6" "dino" "XMPP"; # XMPP calls (jingle)
|
||||||
fractal = userServiceButton "fractal" "[m]"; # Matrix messages
|
fractal = serviceButton "s6" "fractal" "[m]"; # Matrix messages
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,18 @@ let
|
||||||
scripts = import ./scripts.nix { inherit pkgs; };
|
scripts = import ./scripts.nix { inherit pkgs; };
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
sane.programs.swaync-service-dispatcher = {
|
||||||
|
packageUnwrapped = pkgs.static-nix-shell.mkBash {
|
||||||
|
pname = "swaync-service-dispatcher";
|
||||||
|
srcRoot = ./.;
|
||||||
|
pkgs = [
|
||||||
|
"s6"
|
||||||
|
"s6-rc"
|
||||||
|
"systemd"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
sane.programs.swaynotificationcenter = {
|
sane.programs.swaynotificationcenter = {
|
||||||
configOption = with lib; mkOption {
|
configOption = with lib; mkOption {
|
||||||
type = types.submodule {
|
type = types.submodule {
|
||||||
|
@ -77,7 +89,10 @@ in
|
||||||
# the glib code which consumes this is `g_notification_backend_new_default`, calling into `_g_io_module_get_default_type`.
|
# the glib code which consumes this is `g_notification_backend_new_default`, calling into `_g_io_module_get_default_type`.
|
||||||
env.GNOTIFICATION_BACKEND = "freedesktop";
|
env.GNOTIFICATION_BACKEND = "freedesktop";
|
||||||
|
|
||||||
suggestedPrograms = [ "feedbackd" ];
|
suggestedPrograms = [
|
||||||
|
"feedbackd"
|
||||||
|
"swaync-service-dispatcher" #< used when toggling buttons
|
||||||
|
];
|
||||||
|
|
||||||
fs.".config/swaync/style.css".symlink.target = ./style.css;
|
fs.".config/swaync/style.css".symlink.target = ./style.css;
|
||||||
fs.".config/swaync/config.json".symlink.text = builtins.toJSON {
|
fs.".config/swaync/config.json".symlink.text = builtins.toJSON {
|
||||||
|
|
53
hosts/common/programs/swaynotificationcenter/swaync-service-dispatcher
Executable file
53
hosts/common/programs/swaynotificationcenter/swaync-service-dispatcher
Executable file
|
@ -0,0 +1,53 @@
|
||||||
|
#!/usr/bin/env nix-shell
|
||||||
|
#!nix-shell -i bash -p s6 -p s6-rc -p systemd
|
||||||
|
|
||||||
|
action="$1"
|
||||||
|
type="$2"
|
||||||
|
service="$3"
|
||||||
|
|
||||||
|
checkActive() {
|
||||||
|
case "$type" in
|
||||||
|
systemd)
|
||||||
|
systemctl is-active "$service.service" > /dev/null && echo true || echo false
|
||||||
|
;;
|
||||||
|
s6)
|
||||||
|
s6-svstat -o wantedup "$XDG_RUNTIME_DIR/s6/live/servicedirs/$service"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
startService() {
|
||||||
|
case "$type" in
|
||||||
|
systemd)
|
||||||
|
/run/wrappers/bin/sudo systemctl start "$service"
|
||||||
|
;;
|
||||||
|
s6)
|
||||||
|
s6-rc start "$service"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
stopService() {
|
||||||
|
case "$type" in
|
||||||
|
systemd)
|
||||||
|
/run/wrappers/bin/sudo systemctl stop "$service"
|
||||||
|
;;
|
||||||
|
s6)
|
||||||
|
s6-rc stop "$service"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
case "$action" in
|
||||||
|
print)
|
||||||
|
checkActive
|
||||||
|
;;
|
||||||
|
toggle)
|
||||||
|
case "$(checkActive)" in
|
||||||
|
false)
|
||||||
|
stopService
|
||||||
|
;;
|
||||||
|
true)
|
||||||
|
startService
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
esac
|
Loading…
Reference in New Issue
Block a user