Files
dev/configs/nixos/modules/desktop/session/mako.nix

72 lines
2.1 KiB
Nix

{
config,
lib,
pkgs,
...
}:
# mako as the notification daemon: toasts, a do-not-disturb mode, and history recall.
let
glyph = code: builtins.fromJSON ''"\u${code}"'';
dndStatus = pkgs.writeShellScript "waybar-dnd-status" ''
if ${lib.getExe' pkgs.mako "makoctl"} mode 2>/dev/null | ${lib.getExe pkgs.gnugrep} -qx dnd; then
printf '{"text":"${glyph "f1f6"}","tooltip":"Do not disturb: on","class":"dnd"}\n'
else
printf '{"text":"${glyph "f0f3"}","tooltip":"Notifications on","class":"active"}\n'
fi
'';
dndToggle = pkgs.writeShellScript "waybar-dnd-toggle" ''
${lib.getExe' pkgs.mako "makoctl"} mode -t dnd >/dev/null 2>&1
${lib.getExe' pkgs.procps "pkill"} -RTMIN+8 waybar
'';
in
{
options.modules.desktop.session.mako.enable = lib.mkEnableOption "the mako notification daemon";
config = lib.mkIf config.modules.desktop.session.mako.enable {
home-manager.users.${config.user.name} = {
# Colors and the popup font come from Stylix's mako target, so only
# behaviour is set here.
services.mako = {
enable = true;
settings = {
# Toasts auto-dismiss into history rather than lingering.
# mako's own default of 0 leaves every notification on screen until acted on.
default-timeout = 5000;
# The do-not-disturb mode.
# Invisible hides the toasts but still records them to history.
# Missed notifications can therefore be recalled.
"mode=dnd".invisible = true;
};
};
};
registry.keybind.${config.networking.hostName}.mako-history = {
keys = "SUPER + N";
action = {
kind = "exec";
command = "${lib.getExe' pkgs.mako "makoctl"} restore";
};
};
registry.waybar.${config.networking.hostName}."custom/dnd" = {
order = 80;
style = ''
#custom-dnd {
margin-right: 8px;
}
'';
settings = {
return-type = "json";
exec = "${dndStatus}";
on-click = "${dndToggle}";
interval = "once";
signal = 8;
};
};
};
}