1
1
Fork 0

waybar: refactor config

Signed-off-by: Myned <dev@bjork.tech>
This commit is contained in:
Myned 2024-12-26 19:10:30 -05:00
parent 4c593ab11f
commit c324b5a115
Signed by: Myned
GPG key ID: C7224454F7881A34
2 changed files with 429 additions and 407 deletions

View file

@ -7,39 +7,41 @@
}: }:
with lib; let with lib; let
audio = config.home-manager.users.${config.custom.username}.home.file.".local/bin/audio".source; audio = config.home-manager.users.${config.custom.username}.home.file.".local/bin/audio".source;
bash = "${pkgs.bash}/bin/bash";
blueberry = "${pkgs.blueberry}/bin/blueberry"; blueberry = "${pkgs.blueberry}/bin/blueberry";
bluetoothctl = "${pkgs.bluez}/bin/bluetoothctl"; bluetoothctl = "${pkgs.bluez}/bin/bluetoothctl";
cat = "${pkgs.coreutils}/bin/cat"; cat = "${pkgs.coreutils}/bin/cat";
date = "${pkgs.coreutils}/bin/date";
easyeffects = "${pkgs.easyeffects}/bin/easyeffects"; easyeffects = "${pkgs.easyeffects}/bin/easyeffects";
echo = "${pkgs.coreutils}/bin/echo"; echo = "${pkgs.coreutils}/bin/echo";
grep = "${pkgs.gnugrep}/bin/grep"; gnome-calendar = "${pkgs.gnome-calendar}/bin/gnome-calendar";
hyprctl = "${config.programs.hyprland.package}/bin/hyprctl"; gnome-clocks = "${pkgs.gnome-clocks}/bin/gnome-clocks";
gnome-weather = "${pkgs.gnome-weather}/bin/gnome-weather";
inhibit = config.home-manager.users.${config.custom.username}.home.file.".local/bin/inhibit".source; inhibit = config.home-manager.users.${config.custom.username}.home.file.".local/bin/inhibit".source;
jq = "${pkgs.jq}/bin/jq"; jq = "${pkgs.jq}/bin/jq";
loginctl = "${pkgs.systemd}/bin/loginctl"; loginctl = "${pkgs.systemd}/bin/loginctl";
network = config.home-manager.users.${config.custom.username}.home.file.".local/bin/network".source; network = config.home-manager.users.${config.custom.username}.home.file.".local/bin/network".source;
niri = "${config.programs.niri.package}/bin/niri";
nm-connection-editor = "${pkgs.networkmanagerapplet}/bin/nm-connection-editor"; nm-connection-editor = "${pkgs.networkmanagerapplet}/bin/nm-connection-editor";
pgrep = "${pkgs.procps}/bin/pgrep"; pgrep = "${pkgs.procps}/bin/pgrep";
ping = "${pkgs.iputils}/bin/ping"; pwvucontrol = "${pkgs.pwvucontrol}/bin/pwvucontrol";
pkill = "${pkgs.procps}/bin/pkill";
playerctl = "${pkgs.playerctl}/bin/playerctl";
power = config.home-manager.users.${config.custom.username}.home.file.".local/bin/power".source;
remote = config.home-manager.users.${config.custom.username}.home.file.".local/bin/remote".source; remote = config.home-manager.users.${config.custom.username}.home.file.".local/bin/remote".source;
rfkill = "${pkgs.util-linux}/bin/rfkill"; rfkill = "${pkgs.util-linux}/bin/rfkill";
sleep = "${pkgs.coreutils}/bin/sleep";
swaync-client = "${config.home-manager.users.${config.custom.username}.services.swaync.package}/bin/swaync-client"; swaync-client = "${config.home-manager.users.${config.custom.username}.services.swaync.package}/bin/swaync-client";
swayosd-client = "${pkgs.swayosd}/bin/swayosd-client"; swayosd-client = "${pkgs.swayosd}/bin/swayosd-client";
systemctl = "${pkgs.systemd}/bin/systemctl"; systemctl = "${pkgs.systemd}/bin/systemctl";
systemd-inhibit = "${pkgs.systemd}/bin/systemd-inhibit";
tailscale = "${pkgs.tailscale}/bin/tailscale"; tailscale = "${pkgs.tailscale}/bin/tailscale";
tr = "${pkgs.coreutils}/bin/tr"; tr = "${pkgs.coreutils}/bin/tr";
virsh = "${pkgs.libvirt}/bin/virsh";
virt-manager = "${pkgs.virt-manager}/bin/virt-manager";
vpn = config.home-manager.users.${config.custom.username}.home.file.".local/bin/vpn".source; vpn = config.home-manager.users.${config.custom.username}.home.file.".local/bin/vpn".source;
wttrbar = "${pkgs.wttrbar}/bin/wttrbar"; wttrbar = "${pkgs.wttrbar}/bin/wttrbar";
cfg = config.custom.programs.waybar; cfg = config.custom.programs.waybar;
in { in {
options.custom.programs.waybar.enable = mkOption {default = false;}; options.custom.programs.waybar = {
enable = mkOption {default = false;};
desktop = mkOption {default = config.custom.desktops.desktop;};
};
config = mkIf cfg.enable { config = mkIf cfg.enable {
age.secrets = let age.secrets = let
@ -52,86 +54,96 @@ in {
"desktop/vm/myndows.pass" = secret "desktop/vm/myndows.pass"; "desktop/vm/myndows.pass" = secret "desktop/vm/myndows.pass";
}; };
home-manager.users.${config.custom.username} = { home-manager.sharedModules = [
{
# https://github.com/Alexays/Waybar # https://github.com/Alexays/Waybar
# https://www.nerdfonts.com/cheat-sheet #!! Some settings need a restart to take effect
#?? systemctl --user restart waybar
#?? pkill -SIGUSR2 -x waybar
programs.waybar = { programs.waybar = {
enable = true; enable = true;
systemd.enable = true; # Start on login systemd.enable = true;
# ?? waybar --log-level debug # https://github.com/Alexays/Waybar/wiki/Styling
#?? GTK_DEBUG=interactive waybar
style = let style = let
border = toString config.custom.border;
font = config.custom.font.monospace;
gap = toString config.custom.gap; gap = toString config.custom.gap;
in '' in ''
* { * {
border-radius: 50px; border-radius: 50px;
color: #93a1a1; color: #93a1a1;
font: 18px '${config.custom.font.monospace}'; font: 18px '${font}';
margin: 0; margin: 0;
padding: 0; padding: 0;
} }
.horizontal > box { .horizontal > box {
border: ${border} solid #073642;
margin: 0 ${gap}px ${gap}px; margin: 0 ${gap}px ${gap}px;
} }
${readFile ./style.css} ${readFile ./style.css}
''; '';
### SETTINGS ###
# https://github.com/Alexays/Waybar/wiki/Configuration # https://github.com/Alexays/Waybar/wiki/Configuration
# https://docs.gtk.org/Pango/pango_markup.html#pango-markup # https://docs.gtk.org/Pango/pango_markup.html#pango-markup
#?? pkill -SIGUSR2 -x waybar # https://www.nerdfonts.com/cheat-sheet
settings = let settings = let
## INHERIT ## # Common module settings
#!! Some settings are commonly available for use but not documented per module
common = {
# https://github.com/Alexays/Waybar/issues/1800
smooth-scrolling-threshold = 2;
on-scroll-down =
if cfg.desktop == "niri"
then "${niri} msg action focus-workspace-down"
else "";
on-scroll-up =
if cfg.desktop == "niri"
then "${niri} msg action focus-workspace-up"
else "";
};
#!! Module defaults are not accurate to documentation #!! Module defaults are not accurate to documentation
# TODO: Submit pull request to fix in addition to inconsistent hyphen vs underscore cava =
# https://github.com/Alexays/Waybar/wiki/Module:-Cava common
cava-config = { // {
cava_config = null; # Default: null?
framerate = 30; # Default: 30?
autosens = 1; # Default: 1 autosens = 1; # Default: 1
# sensitivity = 0; # Default: 100?
bars = 16; # Default: 2
lower_cutoff_freq = 50; # Default: 50?
higher_cutoff_freq = 10000; # Default: 10000?
sleep_timer = 5; # Default: 0
hide_on_silence = true; # Default: false
method = "pipewire"; # Default: pulse
source = "auto"; # Default: auto?
sample_rate = 44100; # Default: 44100?
sample_bits = 16; # Default: 16?
stereo = false; # Default: true
reverse = false; # Default: false
bar_delimiter = 32; # ASCII code for space, default: 59 or ; bar_delimiter = 32; # ASCII code for space, default: 59 or ;
monstercat = true; # Default: false? bars = 16; # Default: 2
waves = true; # Default: false? cava_config = null; # Default: null?
noise_reduction = 0.2; # Default: 0.77? format-icons = ["" "" "" "" "" "" "" ""]; #!! Required
input_delay = 1; # Default: 4 framerate = 30; # Default 30?
format-icons = [ hide_on_silence = true; # Default false
"" higher_cutoff_freq = 10000; # Default 10000?
"" input_delay = 1; # Default 4
"" lower_cutoff_freq = 50; # Default 50?
"" method = "pipewire"; # Default pulse
"" monstercat = true; # Default false?
"" noise_reduction = 0.2; # Default 0.77?
""
""
]; # !! Required
on-click = easyeffects; on-click = easyeffects;
on-scroll-up = "${swayosd-client} --output-volume raise";
on-scroll-down = "${swayosd-client} --output-volume lower"; on-scroll-down = "${swayosd-client} --output-volume lower";
on-scroll-up = "${swayosd-client} --output-volume raise";
reverse = false; # Default false
rotate = 180; rotate = 180;
sample_bits = 16; # Default 16?
sample_rate = 44100; # Default 44100?
#// sensitivity = 0; # Default 100?
sleep_timer = 5; # Default 0
source = "auto"; # Default auto?
stereo = false; # Default true
waves = true; # Default false?
}; };
in { in {
status = { default = {
reload_style_on_change = true; # Reload CSS when modified
## GLOBAL ##
layer = "top"; layer = "top";
position = "bottom"; position = "bottom";
reload_style_on_change = true;
## POSITION ##
modules-left = [ modules-left = [
"custom/power" "custom/power"
"custom/inhibitor" "custom/inhibitor"
@ -140,11 +152,20 @@ in {
(mkIf config.custom.desktops.hyprland.enable "hyprland/workspaces") (mkIf config.custom.desktops.hyprland.enable "hyprland/workspaces")
(mkIf config.custom.desktops.niri.enable "niri/workspaces") (mkIf config.custom.desktops.niri.enable "niri/workspaces")
]; ];
modules-center = [ modules-center = [
#// "cava#forward"
"clock#date" "clock#date"
"clock#time"
# BUG: Padding modifiers not currently supported, so use custom module
# https://github.com/Alexays/Waybar/issues/1469 et al.
#// "clock#time"
"custom/time"
"custom/weather" "custom/weather"
#// "cava#reverse"
]; ];
modules-right = [ modules-right = [
"mpris" "mpris"
"tray" "tray"
@ -156,53 +177,71 @@ in {
"battery" "battery"
]; ];
## MODULES ## # https://github.com/Alexays/Waybar/wiki/Module:-Battery
# https://github.com/Alexays/Waybar/wiki/Module:-Custom battery =
"custom/power" = { common
format = ""; // {
on-click = "${systemctl} poweroff"; format = "{icon} {power:.0f}W";
on-click-right = "${systemctl} reboot"; format-icons = ["󰂃" "󰁺" "󰁻" "󰁼" "󰁽" "󰁾" "󰁿" "󰂀" "󰂁" "󰂂" "󰁹"];
on-click-middle = "${loginctl} terminate-session ''"; interval = 5; # Seconds
states = {
critical = 15; # Percent
warning = 30; # Percent
};
}; };
"custom/inhibitor" = { # https://github.com/Alexays/Waybar/wiki/Module:-Bluetooth
interval = 5; bluetooth =
exec = "~/.config/waybar/scripts/inhibitor.sh"; common
on-click = inhibit; // {
format-connected = "󰂱";
format-disabled = "󰂲";
format-off = "󰂲";
format-on = "󰂯";
on-click = "${rfkill} toggle bluetooth";
on-click-middle = "${bluetoothctl} disconnect";
on-click-right = blueberry;
}; };
"custom/vm" = { # https://github.com/Alexays/Waybar/wiki/Module:-Cava
interval = 5; "cava#forward" = cava;
exec = "~/.config/waybar/scripts/vm.sh"; "cava#reverse" = cava // {reverse = true;};
on-click = ''${remote} --vm --client xfreerdp --username Myned --password "$(${cat} ${config.age.secrets."desktop/vm/myndows.pass".path})" ${
if config.custom.hidpi # https://github.com/Alexays/Waybar/wiki/Module:-Clock
then "--scale 140" # https://fmt.dev/latest/syntax/#chrono-format-specifications
else "" "clock#date" =
} myndows''; common
// {
format = "{:%a %b %d}";
tooltip-format = "{calendar}";
on-click-right = gnome-calendar;
calendar = {
format = {
months = "<span color='#eee8d5'>{}</span>";
weeks = "<span color='#eee8d5'>{}</span>";
weekdays = "<span color='#93a1a1'>{}</span>";
days = "<span color='#586e75'>{}</span>";
today = "<span color='#eee8d5'>{}</span>";
};
};
}; };
"custom/vpn" = { "clock#time" =
interval = 5; common
exec = "~/.config/waybar/scripts/vpn.sh"; // {
on-click = "${vpn} mypi3"; format = "<span text_transform='lowercase'>{:%-I:%M%p}</span>";
}; on-click = "${swaync-client} --toggle-panel";
on-click-right = gnome-clocks;
# https://github.com/Alexays/Waybar/wiki/Module:-Idle-Inhibitor
# FIXME: Not currently usable
# https://github.com/Alexays/Waybar/issues/690
idle_inhibitor = {
format = "{icon}";
format-icons = {
activated = "󰅶";
deactivated = "󰾪";
};
}; };
# https://github.com/Alexays/Waybar/wiki/Module:-Hyprland # https://github.com/Alexays/Waybar/wiki/Module:-Hyprland
# https://www.nerdfonts.com/cheat-sheet "hyprland/workspaces" =
"hyprland/workspaces" = { common
show-special = true; // {
format = "{icon}"; format = "{icon}";
format-icons = { format-icons = {
android = ""; android = "";
dropdown = "󰞷"; dropdown = "󰞷";
@ -218,11 +257,28 @@ in {
vm = "󰢹"; vm = "󰢹";
wallpaper = "󰏩"; wallpaper = "󰏩";
}; };
show-special = true;
};
# https://github.com/Alexays/Waybar/wiki/Module:-Idle-Inhibitor
# BUG: Not currently compatible with other inhibit activations
# https://github.com/Alexays/Waybar/issues/690
idle_inhibitor =
common
// {
format = "{icon}";
format-icons = {
activated = "󰅶";
deactivated = "󰾪";
};
}; };
# https://github.com/Alexays/Waybar/wiki/Module:-Niri # https://github.com/Alexays/Waybar/wiki/Module:-Niri
# https://www.nerdfonts.com/cheat-sheet "niri/workspaces" =
"niri/workspaces" = { common
// {
format = "{icon}"; format = "{icon}";
format-icons = { format-icons = {
@ -230,127 +286,52 @@ in {
}; };
}; };
cava = cava-config;
# https://github.com/Alexays/Waybar/wiki/Module:-Clock
"clock#date" = {
format = "{:%a %b %d}";
tooltip-format = "{calendar}";
calendar.format = {
months = "<span color='#eee8d5'>{}</span>";
weeks = "<span color='#eee8d5'>{}</span>";
weekdays = "<span color='#93a1a1'>{}</span>";
days = "<span color='#586e75'>{}</span>";
today = "<span color='#eee8d5'>{}</span>";
};
};
"clock#time" = {
# https://fmt.dev/latest/syntax/#chrono-format-specifications
format = "<span text_transform='lowercase'>{:%I:%M%p}</span>";
on-click = "${swaync-client} --toggle-panel";
on-scroll-up = "${swayosd-client} --output-volume raise";
on-scroll-down = "${swayosd-client} --output-volume lower";
};
# https://github.com/bjesus/wttrbar
"custom/weather" = {
format = "{}°";
interval = 60 * 60;
return-type = "json";
exec = lib.strings.concatStringsSep " " [
"${wttrbar}"
"--ampm"
"--fahrenheit"
"--hide-conditions"
"--main-indicator temp_F"
];
};
"cava#reverse" =
cava-config
// {
reverse = true;
};
"custom/equalizer" = {
interval = 5;
on-click = audio;
exec = pkgs.writeShellScript "equalizer.sh" ''
${echo} 󰺢
${echo} "$(${cat} ~/.audio)"
${echo} "$(${cat} ~/.audio | ${tr} '[:upper:]' '[:lower:]')"
'';
};
# https://github.com/Alexays/Waybar/wiki/Module:-MPRIS # https://github.com/Alexays/Waybar/wiki/Module:-MPRIS
mpris = { mpris =
common
// {
format = "{player_icon} {dynamic}"; format = "{player_icon} {dynamic}";
format-paused = "{status_icon} {dynamic}"; format-paused = "{status_icon} {dynamic}";
dynamic-len = 25; dynamic-len = 25; # Characters
dynamic-order = [ dynamic-order = ["title" "artist"];
"title"
"artist"
];
dynamic-separator = " 󰧟 "; dynamic-separator = " 󰧟 ";
player-icons.default = "󰎈"; player-icons.default = "󰎈";
status-icons.paused = ""; status-icons.paused = "";
on-click-middle = ""; # TODO: Close music player
on-scroll-up = "${swayosd-client} --output-volume raise";
on-scroll-down = "${swayosd-client} --output-volume lower";
};
# https://github.com/Alexays/Waybar/wiki/Module:-WirePlumber # TODO: on-click focus currently playing window
wireplumber = { #// on-click = "";
format = "{icon} {volume}%";
format-muted = "󰸈";
format-icons = [
"󰕿"
"󰖀"
"󰕾"
];
on-click = easyeffects;
on-click-right = "${swayosd-client} --output-volume mute-toggle";
on-scroll-up = "${swayosd-client} --output-volume raise";
on-scroll-down = "${swayosd-client} --output-volume lower";
};
# https://github.com/Alexays/Waybar/wiki/Module:-Bluetooth on-click-middle =
bluetooth = { if cfg.desktop == "niri"
format-disabled = "󰂲"; then ''${niri} msg action close-window --id "$(${niri} msg -j windows | ${jq} '.[] | select(.app_id == "YouTube Music").id')"''
format-off = "󰂲"; else "";
format-on = "󰂯";
format-connected = "󰂱"; on-scroll-down = "${swayosd-client} --output-volume lower";
on-click = blueberry; on-scroll-up = "${swayosd-client} --output-volume raise";
on-click-right = "${bluetoothctl} disconnect";
on-click-middle = "${rfkill} toggle bluetooth"; # Toggle bluetooth on/off
}; };
# https://github.com/Alexays/Waybar/wiki/Module:-Network # https://github.com/Alexays/Waybar/wiki/Module:-Network
network = { network =
common
// {
format = "{icon}"; format = "{icon}";
format-icons = { format-icons = {
disabled = ""; disabled = "";
disconnected = ""; disconnected = "";
ethernet = "󰈀"; ethernet = "󰈀";
linked = ""; linked = "";
wifi = [ wifi = ["󰤯" "󰤟" "󰤢" "󰤥" "󰤨"];
"󰤯"
"󰤟"
"󰤢"
"󰤥"
"󰤨"
];
}; };
on-click = nm-connection-editor; on-click = network;
on-click-right = network; # Toggle networking on/off on-click-right = nm-connection-editor;
}; };
# https://github.com/Alexays/Waybar/wiki/Module:-PowerProfilesDaemon # https://github.com/Alexays/Waybar/wiki/Module:-PowerProfilesDaemon
power-profiles-daemon = { power-profiles-daemon =
common
// {
format = "{icon}"; format = "{icon}";
format-icons = { format-icons = {
@ -363,48 +344,38 @@ in {
tooltip = false; tooltip = false;
}; };
# https://github.com/Alexays/Waybar/wiki/Module:-Battery # https://github.com/Alexays/Waybar/wiki/Module:-WirePlumber
"battery" = { wireplumber =
format = "{icon} {power:.0f}W"; common
interval = 5; // {
format = "{icon} {volume}%";
format-icons = [ format-icons = ["󰕿" "󰖀" "󰕾"];
"󰂃" format-muted = "󰸈";
"󰁺" on-click = "${swayosd-client} --output-volume mute-toggle";
"󰁻" on-click-right = pwvucontrol;
"󰁼" on-scroll-down = "${swayosd-client} --output-volume lower";
"󰁽" on-scroll-up = "${swayosd-client} --output-volume raise";
"󰁾"
"󰁿"
"󰂀"
"󰂁"
"󰂂"
"󰁹"
];
states = {
critical = 15;
warning = 30;
}; };
on-click = power; # https://github.com/Alexays/Waybar/wiki/Module:-Custom
}; "custom/equalizer" =
}; common
}; // {
exec = pkgs.writeShellScript "equalizer.sh" ''
${echo} 󰺢
${echo} "$(${cat} ~/.audio)"
${echo} "$(${cat} ~/.audio | ${tr} '[:upper:]' '[:lower:]')"
'';
interval = 5; # Seconds
on-click = audio;
on-click-right = easyeffects;
}; };
# TODO: Convert to writeShellApplication "custom/inhibitor" =
### SCRIPTS ### common
#?? text // {
#?? tooltip exec = pkgs.writeShellScript "inhibitor.sh" ''
#?? class
xdg.configFile = {
# Return inhibit idle status
"waybar/scripts/inhibitor.sh" = {
executable = true;
text = ''
#! /usr/bin/env ${bash}
if ${pgrep} systemd-inhibit &> /dev/null; then if ${pgrep} systemd-inhibit &> /dev/null; then
${echo} 󰅶 ${echo} 󰅶
${echo} Enabled ${echo} Enabled
@ -415,15 +386,34 @@ in {
${echo} disabled ${echo} disabled
fi fi
''; '';
interval = 5; # Seconds
on-click = inhibit;
}; };
# Return tailscale status "custom/power" =
"waybar/scripts/vm.sh" = { common
executable = true; // {
text = '' format = "";
#! /usr/bin/env ${bash} on-click = "${systemctl} poweroff";
on-click-middle = "${loginctl} terminate-session ${config.custom.username}";
on-click-right = "${systemctl} reboot";
};
case "$(virsh domstate myndows)" in "custom/time" =
common
// {
exec = "${date} '+%-I:%M%P'";
interval = 60; # Seconds
on-click = "${swaync-client} --toggle-panel";
on-click-right = gnome-clocks;
};
"custom/vm" =
common
// {
exec = pkgs.writeShellScript "vm.sh" ''
case "$(${virsh} domstate myndows)" in
'running') 'running')
${echo} ${echo}
${echo} Online ${echo} Online
@ -442,14 +432,23 @@ in {
${echo} unknown;; ${echo} unknown;;
esac esac
''; '';
interval = 5;
on-click = ''${remote} --vm --client xfreerdp --username Myned --password "$(${cat} ${config.age.secrets."desktop/vm/myndows.pass".path})" ${
if config.custom.hidpi
then "--scale 140"
else ""
} myndows'';
on-click-middle = "${virsh} shutdown myndows";
on-click-right = virt-manager;
}; };
# Return tailscale status "custom/vpn" =
"waybar/scripts/vpn.sh" = { common
executable = true; // {
text = '' exec = pkgs.writeShellScript "vpn.sh" ''
#! /usr/bin/env ${bash}
if [[ $(${tailscale} status --json | ${jq} .ExitNodeStatus.Online) == 'true' ]]; then if [[ $(${tailscale} status --json | ${jq} .ExitNodeStatus.Online) == 'true' ]]; then
${echo} 󰖂 ${echo} 󰖂
${echo} Connected ${echo} Connected
@ -460,8 +459,32 @@ in {
${echo} disconnected ${echo} disconnected
fi fi
''; '';
interval = 5; # Seconds
on-click = "${vpn} mypi3";
};
# https://github.com/bjesus/wttrbar
"custom/weather" =
common
// {
exec = lib.strings.concatStringsSep " " [
wttrbar
"--ampm"
"--fahrenheit"
"--hide-conditions"
"--main-indicator temp_F"
];
format = "{}°";
interval = 60 * 60; # Seconds
return-type = "json";
on-click-right = gnome-weather;
}; };
}; };
}; };
}; };
}
];
};
} }

View file

@ -42,7 +42,6 @@ tooltip label {
.horizontal > box { .horizontal > box {
background: #002b36; background: #002b36;
/* border: 2px #586e75 solid; */
padding: 4px; padding: 4px;
} }