nixos/users/malte/waybar.nix

417 lines
11 KiB
Nix

{
pkgs,
lib,
config,
nixosConfig,
...
}: let
mkBorder = hex: ((config.myLib.mkColor hex).darker 0.4).hashRgb;
col = config.colorsDark.colors;
task-activity = with pkgs; let
task = "${pkgs.taskwarrior}/bin/task";
jq = "${pkgs.jq}/bin/jq";
timew = "${pkgs.timewarrior}/bin/timew";
getTaskwarriorDesc = "${task} +ACTIVE export | ${jq} '.[0].description'";
getTimewarriorDesc = "${timew} get dom.active.json | ${jq} '.tags|join(\", \")'";
in
writeScriptBin "task-activity" ''
#!${stdenv.shell}
task +ACTIVE >/dev/null 2>/dev/null
if [[ $? -eq 0 ]]; then
# taskwarrior is running
echo "{ \"text\": \" \", \
\"tooltip\": $(${getTaskwarriorDesc}) \
}" | ${jq} --unbuffered --compact-output
exit 0
fi
if [[ $(${timew} get dom.active) -eq 1 ]]; then
# Timew is running but taskwarrior is not
echo "{ \"text\": \" \", \
\"tooltip\": $(${getTimewarriorDesc}) \
}" | ${jq} --unbuffered --compact-output
exit 0
fi
# Nothing is running
echo "{ \"text\": \"\", \
\"tooltip\": \"\" \
}" | ${jq} --unbuffered --compact-output
'';
doNotDisturbJson = pkgs.writeShellApplication {
name = "do-not-disturb-json";
runtimeInputs = [
(pkgs.callPackage ../../pkgs/do-not-disturb.nix {})
pkgs.coreutils
pkgs.jq
];
text = ''
state=$(do-not-disturb get-file)
if [ -f "$state" ]; then
printf "{ \"text\": \" \", \
\"tooltip\": \"DO NOT DISTURB!\" \
}" | jq --unbuffered --compact-output
fi
'';
};
new-mail = let
notmuch = "${pkgs.notmuch}/bin/notmuch";
wc = "${pkgs.coreutils}/bin/wc";
jq = "${pkgs.jq}/bin/jq";
in
pkgs.writeScriptBin "new-mail" ''
#!${pkgs.stdenv.shell}
count=$(${notmuch} search tag:unread | ${wc} -l)
if [[ $count -ne 0 ]]; then
echo "{ \"text\": \" \", \
\"tooltip\": \"$count\" \
}" | ${jq} --unbuffered --compact-output
fi
'';
checkSystem = let
systemctl = "${pkgs.systemd}/bin/systemctl";
jq = "${pkgs.jq}/bin/jq";
extractJson = "${jq} '.[].unit' --raw-output";
newline = "\n";
replaceNewlines = "${pkgs.coreutils}/bin/tr '${newline}' ' '";
in
pkgs.writeScriptBin "check-system" ''
#!${pkgs.stdenv.shell}
failed_user=$(${systemctl} --user --output json list-units --failed | ${extractJson} | ${replaceNewlines})
failed_system=$(${systemctl} --output json list-units --failed | ${extractJson} | ${replaceNewlines})
if [[ -n $failed_system ]]; then
# Some system services failed
echo "{ \"text\": \" \", \
\"tooltip\": \"$failed_system\" \
}" | ${jq} --unbuffered --compact-output
fi
if [[ -n $failed_user ]]; then
# Some user services failed
echo "{ \"text\": \" \", \
\"tooltip\": \"$failed_user\" \
}" | ${jq} --unbuffered --compact-output
fi
'';
in {
home.packages = [pkgs.hackNerdLigatures task-activity];
programs.waybar = {
enable = true;
settings = [
{
layer = "top";
position = "top";
modules-left = ["sway/workspaces" "sway/mode" "sway/window"];
modules-center = ["clock#time" "custom/check-system" "clock#date"];
modules-right =
["custom/do-not-disturb" "custom/taskwarrior" "custom/new-mail" "network"]
++ (lib.optional nixosConfig.settings.batteryStuff.enable "battery")
++ ["tray"];
modules = {
"sway/workspaces" = {
disable-scroll = true;
all-outputs = true;
};
"sway/mode" = {
format = "<span foreground='@base00'>{}</span>";
};
"sway/window" = {tooltip = false;};
"clock#time" = {
interval = 1;
format = "{:%T}";
tooltip = false;
};
"custom/check-system" = {
exec = "${checkSystem}/bin/check-system";
return-type = "json";
interval = 5;
};
"clock#date" = {
format = "{:%d.%m.%y}";
tooltip = false;
};
"custom/do-not-disturb" = {
exec = "${doNotDisturbJson}/bin/do-not-disturb-json";
return-type = "json";
interval = 1;
};
"custom/taskwarrior" = {
exec = "${task-activity}/bin/task-activity";
return-type = "json";
interval = 1;
};
"custom/new-mail" = {
exec = "${new-mail}/bin/new-mail";
return-type = "json";
interval = 1;
};
"idle_inhibitor" = {
format = "{icon}";
format-icons = {
activated = " ";
deactivated = " ";
};
tooltip = false;
};
"battery" = {
states = {
good = 95;
warning = 30;
critical = 15;
};
format = "{icon} {capacity}%";
format-charging = " {capacity}%";
format-plugged = "";
design-capacity = true;
format-icons = ["" "" "" "" ""];
tooltip = false;
};
"network" = {
format-wifi = " <b>{essid}</b> ({signalStrength}%)";
format-ethernet = " <b>{ifname}</b> {ipaddr}/{cidr}";
format-linked = " <b>{ifname}</b>";
format-disconnected = " ";
tooltip = false;
interval = 5;
};
"tray" = {
spacing = 5;
};
};
}
];
style = ''
@import "${config.myLib.mkCSSVariables config.colorsDark}";
* {
border: none;
border-radius: 0;
font-family: Hack NF FC Ligatured;
font-size: 11px;
min-height: 20px;
}
window#waybar {
background-color: @base00;
border-bottom: 3px solid ${mkBorder col.base00};
color: @base0D;
}
window#waybar.hidden {
opacity: 0.2;
}
tooltip {
margin: 0;
padding: 0;
background-color: @base00;
color: @base0D;
border: 1px solid ${mkBorder col.base00};
}
tooltip label {
margin: 0;
padding: 0;
color: @base0D;
font-weight: bolder;
}
/* Workspace basics, existing workspaces on other displays */
#workspaces button {
padding: 0 5px;
background-color: transparent;
color: @base01;
font-weight: bolder;
min-width: 20px;
/* border-bottom: 3px solid ${mkBorder col.base00}; */
}
/* Workspaces on the current output, not visible */
#workspaces button.current_output {
color: @base03;
}
/* Workspaces that are visible on other displays but not selected */
#workspaces button.visible {
color: @base03;
background-color: @base01;
border-bottom: 3px solid ${mkBorder col.base01};
}
/* Unselected workspace that is visible on this display */
#workspaces button.current_output.visible {
color: @base00;
background-color: @base03;
border-bottom: 3px solid ${mkBorder col.base03};
}
#workspaces button.current_output.focused {
color: @base00;
background-color: @base0D;
border-bottom: 3px solid ${mkBorder col.base0D};
}
#workspaces button.urgent {
color: @base00;
background-color: @base08;
border-bottom: 3px solid ${mkBorder col.base08};
}
#mode {
background-color: @base08;
color: @base00;
border-bottom: 3px solid ${mkBorder col.base08};
}
#workspaces button:hover {
color: @base00;
background-color: @base0D;
border-bottom: 3px solid ${mkBorder col.base0D};
}
#clock,
#battery,
#network,
#mode,
#custom-taskwarrior,
#custom-do-not-disturb,
#custom-new-mail,
#custom-check-system {
padding: 0 10px;
color: @base05;
}
#custom-taskwarrior,
#custom-do-not-disturb,
#custom-new-mail {
padding: 0px 10px 0px 13px;
margin-right: 10px;
font-weight: bolder;
background-color: @base09;
color: @base00;
border-bottom: 3px solid ${mkBorder col.base09};
}
#custom-do-not-disturb {
background-color: @base0B;
border-bottom: 3px solid ${mkBorder col.base0B};
}
#custom-check-system {
margin: 0 5px;
padding: 0 10px 0 13px;
font-weight: bolder;
color: @base08;
}
#network {
margin-right: 10px;
background-color: @base04;
color: @base00;
border-bottom: 3px solid ${mkBorder col.base04};
}
#network.disconnected {
padding: 0px 10px 0px 13px;
background-color: @base08;
color: @base00;
border-bottom: 3px solid ${mkBorder col.base08};
}
#clock {
color: @base05;
border-bottom: 3px solid transparent;
}
#clock.time {
font-weight: bolder;
padding-right: 2px;
}
#clock.date {
padding-left: 2px;
}
#window,
#workspaces {
margin: 0 4px;
}
#window {
border-bottom: 3px solid transparent;
}
/* If workspaces is the leftmost module, omit left margin */
.modules-left > widget:first-child > #workspaces {
margin-left: 0;
}
/* If workspaces is the rightmost module, omit right margin */
.modules-right > widget:last-child > #workspaces {
margin-right: 0;
}
#battery {
background-color: @base05;
border-bottom: 3px solid ${mkBorder col.base05};
color: @base00;
}
#battery.warning:not(.charging) {
background-color: @base08;
border-bottom: 3px solid ${mkBorder col.base08};
}
#battery.critical:not(.charging) {
background-color: @base0F;
border-bottom: 3px solid ${mkBorder col.base0F};
}
label:focus {
background-color: #000000;
}
#tray {
padding: 0 10px;
}
#tray menu {
background-color: @base00;
color: @base0D;
border: 1px solid @base0D;
padding: 0;
margin: 10px;
font-weight: bold;
}
#tray menu menuitem {
border-bottom: 1px solid @base00;
}
#tray menu menuitem:last-child {
border-bottom: none;
}
#tray menu menuitem:hover {
background-color: @base0D;
color: @base00;
}
'';
};
}