Files
nixdots/modules/home-manager/polybar.nix
T
2026-10-03 12:00:24 -05:00

104 lines
2.8 KiB
Nix

{ pkgs, ... }:
let
polybar = pkgs.polybar.override { pulseSupport = true; };
in
{
home.packages = [
polybar
pkgs.nerd-fonts.jetbrains-mono
];
fonts.fontconfig.enable = true;
xdg.configFile."polybar/config.ini".text = ''
[colors]
background = #1a1b26
foreground = #c0caf5
primary = #7aa2f7
dim = #565f89
[bar/main]
monitor = ''${env:MONITOR:}
width = 100%
height = 22pt
background = ''${colors.background}
foreground = ''${colors.foreground}
font-0 = JetBrainsMono Nerd Font:size=10;2
padding = 1
module-margin = 1
separator = |
separator-foreground = ''${colors.dim}
wm-restack = bspwm
enable-ipc = true
modules-left = bspwm
modules-center = date
modules-right = pulseaudio cpu memory
tray-position = right
# Second monitor: same look, no tray, fewer modules (it's narrow when rotated)
[bar/secondary]
inherit = bar/main
modules-right = cpu memory
tray-position = none
[module/bspwm]
type = internal/bspwm
pin-workspaces = true
label-focused = %name%
label-focused-background = ''${colors.primary}
label-focused-foreground = ''${colors.background}
label-focused-padding = 1
label-occupied = %name%
label-occupied-padding = 1
label-empty = %name%
label-empty-foreground = ''${colors.dim}
label-empty-padding = 1
label-urgent = %name%
label-urgent-background = #f7768e
label-urgent-padding = 1
[module/date]
type = internal/date
interval = 5
date = %a %b %d %H:%M
[module/cpu]
type = internal/cpu
interval = 2
label = CPU %percentage%%
[module/memory]
type = internal/memory
interval = 5
label = RAM %percentage_used%%
[module/pulseaudio]
type = internal/pulseaudio
label-volume = VOL %percentage%%
label-muted = muted
label-muted-foreground = ''${colors.dim}
'';
# One bar per monitor. The primary monitor gets "main" (with tray), others get "secondary".
# If no monitor is marked primary, the first one listed gets "main".
xdg.configFile."polybar/launch.sh" = {
executable = true;
text = ''
#!/bin/sh
${pkgs.procps}/bin/pkill -x polybar
while ${pkgs.procps}/bin/pgrep -x polybar >/dev/null; do sleep 0.2; done
LIST=$(${polybar}/bin/polybar --list-monitors)
PRIMARY=$(echo "$LIST" | ${pkgs.gnugrep}/bin/grep '(primary)' | ${pkgs.coreutils}/bin/cut -d: -f1)
[ -z "$PRIMARY" ] && PRIMARY=$(echo "$LIST" | ${pkgs.coreutils}/bin/head -n1 | ${pkgs.coreutils}/bin/cut -d: -f1)
for m in $(echo "$LIST" | ${pkgs.coreutils}/bin/cut -d: -f1); do
if [ "$m" = "$PRIMARY" ]; then bar=main; else bar=secondary; fi
MONITOR=$m ${pkgs.util-linux}/bin/setsid -f ${polybar}/bin/polybar $bar
done
'';
};
}