Files
nixos-blueprint/modules/home/desktop/niri/programs/waybar/default.nix
2025-11-27 14:33:34 +02:00

410 lines
9.5 KiB
Nix

{
config,
lib,
osConfig,
pkgs,
launcher,
...
}: let
ifLaptop = lib.mkIf (osConfig.networking.hostName != "dunamis");
in {
enable = true;
systemd = {
enable = true;
target = "graphical-session.target";
};
settings.bottom = {
position = "bottom";
height = 34;
spacing = 0;
margin-left = 36 + 3;
margin-right = 36 + 3;
margin-bottom = 3;
modules-left = [
"custom/launcher"
"wlr/taskbar"
];
modules-right = [
"niri/workspaces"
"clock"
"niri/language"
];
"niri/workspaces" = {
format = "{index}";
};
"niri/language" = {
format = "{short}";
# format-en = "🇺🇸";
# format-uk = "🇺🇦";
};
clock = {
format = "{:%R}";
interval = 1;
tooltip = true;
tooltip-format = "{:%B %d, %A}";
};
"custom/launcher" = {
format = "";
on-click = launcher;
tooltip = false;
};
"wlr/taskbar" = {
format = "{icon} {name}";
icon-size = 16;
icon-theme = "${config.dconf.settings."org/gnome/desktop/interface".icon-theme}";
tooltip-format = "{title}";
on-click = "activate";
};
};
settings.top = {
position = "top";
height = 34;
spacing = 0;
margin-left = 36 + 3;
margin-right = 36 + 3;
margin-top = 3;
modules-left = [
"custom/notification"
"tray"
"privacy"
];
modules-right = [
"network"
"cpu"
"memory"
"wireplumber"
"wireplumber#source"
(ifLaptop "group/laptop")
"idle_inhibitor"
];
"group/laptop" = {
orientation = "inherit";
modules = [
"backlight"
"battery"
"power-profiles-daemon"
];
};
backlight = {
format = "{percent}% {icon}";
format-icons = [
"󰃚"
"󰃛"
"󰃜"
"󰃝"
"󰃞"
"󰃟"
"󰃠"
];
};
idle_inhibitor = {
tooltip = false;
format = "{icon}";
format-icons = {
activated = "󰅶";
deactivated = "󰾪";
};
};
tray = {
icon-size = 16;
spacing = 6;
};
battery = {
states = {
good = 95;
warning = 30;
critical = 15;
};
format = "{capacity}% {icon}";
format-full = "{capacity}% 󱟢";
format-charging = "{capacity}% 󰂄";
format-plugged = "{capacity}% 󰚥";
format-alt = "{icon} {time}";
format-icons = ["󰁺" "󰁻" "󰁼" "󰁽" "󰁾" "󰁿" "󰂀" "󰂁" "󰂂" "󰁹"];
};
memory = {
format = "{used:0.1f}G ";
tooltip-format = ''
RAM: {used:0.1f}G/{total:0.1f}G ({percentage}%)
Swap: {swapUsed:0.1f}G/{swapTotal:0.1f}G ({swapPercentage}%)'';
};
network = {
format = "{bandwidthDownBits} 󰇚 | {bandwidthUpBits} 󰕒";
interval = 3;
tooltip = false;
};
cpu = {
format = "{usage}% 󰍛";
interval = 3;
};
power-profiles-daemon = {
format = "{icon}";
tooltip = true;
tooltip-format = "Power profile: {profile}\nDriver: {driver}";
format-icons = {
default = "󱡮";
performance = "󱡮";
balanced = "";
power-saver = "";
};
};
wireplumber = {
format = "{volume}% {icon}";
format-muted = "󰖁";
format-icons = ["󰕿" "󰖀" "󰕾"];
on-click = lib.getExe pkgs.pwvucontrol;
on-click-right = "wpctl set-mute @DEFAULT_SINK@ toggle";
scroll-step = 3;
};
"wireplumber#source" = {
node-type = "Audio/Source";
format = "{volume}% 󰍬";
format-muted = "󰍭";
on-click-right = "wpctl set-mute @DEFAULT_AUDIO_SOURCE@ toggle";
scroll-step = 3;
};
"custom/notification" = {
tooltip = false;
format = "{icon}";
format-icons = {
notification = "󱅫";
none = "󰂚";
dnd-notification = "󰂛";
dnd-none = "󰂛";
};
return-type = "json";
exec =
pkgs.writeShellApplication {
name = "xfce-notifyd-waybar";
runtimeInputs = with pkgs; [sqlite xfce.xfconf coreutils];
text =
# bash
''
is_dnd=$(xfconf-query -c xfce4-notifyd -p /do-not-disturb)
notifications_count=$(sqlite3 ~/.cache/xfce4/notifyd/log.sqlite "SELECT count(*) FROM notifications WHERE NOT is_read")
if [[ "$notifications_count" -ne 0 ]]; then
icon="notification"
else
icon="none"
fi
if [[ "$is_dnd" == "true" ]]; then
icon="dnd-$icon"
fi
printf '{"text": "%s", "alt": "%s"}' "$notifications_count" "$icon"
'';
}
+ "/bin/xfce-notifyd-waybar";
on-click = "xfconf-query -c xfce4-notifyd -p /do-not-disturb -T";
on-click-right = lib.getExe pkgs.xfce.xfce4-notifyd;
escape = true;
signal = 1;
};
"privacy" = {
icon-spacing = 0;
icon-size = 16;
transition-duration = 250;
screenshare = {
type = "screenshare";
tooltip = true;
tooltip-icon-size = 24;
};
audio-in = {
type = "audio-in";
tooltip = true;
tooltip-icon-size = 24;
};
};
};
# TODO: figure out magic waybar css styling (does it pick up `~/.config/gtk-3.0/gtk.css` ?)
style = let
colors = config.lib.stylix.colors.withHashtag;
in
# css
''
@define-color base00 ${colors.base00}; @define-color base08 ${colors.base08};
@define-color base01 ${colors.base01}; @define-color base09 ${colors.base09};
@define-color base02 ${colors.base02}; @define-color base0A ${colors.base0A};
@define-color base03 ${colors.base03}; @define-color base0B ${colors.base0B};
@define-color base04 ${colors.base04}; @define-color base0C ${colors.base0C};
@define-color base05 ${colors.base05}; @define-color base0D ${colors.base0D};
@define-color base06 ${colors.base06}; @define-color base0E ${colors.base0E};
@define-color base07 ${colors.base07}; @define-color base0F ${colors.base0F};
* {
font-family: Symbols Nerd Font, FontAwesome, ${config.stylix.fonts.sansSerif.name};
font-size: 16px;
font-weight: 500;
}
.modules-left,
.modules-center,
.modules-right,
window#waybar {
background-color: @base00;
color: @base05;
border-radius: 12px;
}
.modules-left,
.modules-center,
.modules-right {
padding-left: 3px;
} /* for leftmost modules */
button {
border-radius: 6px;
box-shadow: inset 0 -3px transparent;
}
button:hover {
background: inherit;
box-shadow: inset 0 -3px transparent;
}
label:focus {
background-color: #000000;
}
tooltip label {
color: @base05;
}
tooltip {
background: @base01;
border: 1px solid @base0D;
border-radius: 16px;
padding: 2em;
}
window#bottom.modules-center {
background-color: transparent
}
#backlight,
#battery,
#clock,
#cpu,
#custom-launcher,
#custom-notification,
#idle_inhibitor,
#language,
#memory,
#network,
#power-profiles-daemon,
#privacy,
#privacy-item,
#taskbar button,
#taskbar,
#tray,
#wireplumber,
#workspaces button,
#workspaces {
all: unset;
border-radius: 9px;
background-color: @base01;
margin: 3px 3px 3px 0;
padding: 0 0.42em;
}
#backlight,
#battery,
#custom-launcher,
#custom-notification,
#idle_inhibitor,
#power-profiles-daemon,
#wireplumber {
padding: 0 0.5em;
}
#battery.critical:not(.charging) {
background-color: @base09;
color: @base00;
}
#custom-launcher,
#custom-notification,
#idle_inhibitor,
#language,
#power-profiles-daemon {
padding: 0;
min-width: 1.7em;
}
#power-profiles-daemon.performance {
background-color: @base0D;
color: @base00;
}
#power-profiles-daemon.power-saver {
background-color: @base0A;
color: @base00;
}
#privacy,
#taskbar,
#workspaces {
padding: 0;
}
#privacy-item,
#taskbar button,
#workspaces button {
border-radius: 6px;
min-width: 1.35em;
padding: 0;
}
#privacy-item.audio-in {
background-color: @base0E;
color: @base00;
margin: 3px;
}
#privacy-item.screenshare {
background-color: @base0C;
color: @base00;
margin-right: 0;
}
#taskbar button {
padding: 0 0.4em;
margin: 3px 3px 3px 0;
}
#taskbar button.active,
#workspaces button.active {
background-color: @base02;
}
#taskbar button.active:hover,
#taskbar button:hover,
#workspaces button:hover,
#workspaces button.active:hover {
background-color: @base0D;
color: @base00;
}
#taskbar.empty {
background-color: transparent;
}
#tray>.needs-attention {
-gtk-icon-effect: highlight;
background-color: @base08;
}
#tray>.passive {
-gtk-icon-effect: dim;
}
#taskbar,
#workspaces {
padding-left: 3px;
}
'';
}