nixos-config/home-manager/modules/polybar/default.nix

363 lines
9 KiB
Nix
Raw Normal View History

2022-11-11 11:54:21 +01:00
{ pkgs
, config
, lib
, ...
}:
with lib; let
cfg = config.eboskma.programs.polybar;
colors = {
background = "#cc000000";
foreground = "#ffffffff";
urgent = "#c9545d";
};
polybar-playerctl =
let
pythonWithPackages = pkgs.python3.withPackages (pythonPackages: [
pythonPackages.pygobject3
]);
in
pkgs.stdenv.mkDerivation {
name = "polybar-playerctl";
buildInputs = [
pythonWithPackages
pkgs.playerctl
];
propagatedBuildInputs = [
pythonWithPackages
pkgs.python3Packages.pygobject3
pkgs.playerctl
];
nativeBuildInputs = [
pkgs.gobject-introspection
pkgs.wrapGAppsHook
];
strictDeps = false;
dontUnpack = true;
installPhase = ''
mkdir -p $out/bin
cp ${./scripts/polybar-playerctl} $out/bin/polybar-playerctl
chmod +x $out/bin/polybar-playerctl
'';
};
headset-battery = pkgs.writeShellScript "headset-battery" ''
battery_level=$(${pkgs.headsetcontrol}/bin/headsetcontrol -c -b 2> /dev/null)
if [[ $? -ne 0 ]]; then
printf "󰂑"
exit
fi
2022-11-11 11:54:21 +01:00
2023-06-01 16:58:04 +02:00
battery_icons=(󰁺 󰁻 󰁼 󰁽 󰁾 󰁿 󰂀 󰂁 󰂂 󰁹 )
battery_charging="󰂄"
2022-11-11 11:54:21 +01:00
if [[ "''${battery_level}" -eq -1 ]]; then
2022-11-11 11:54:21 +01:00
printf "%s " "''${battery_charging}"
else
idx=$(((battery_level / 10)))
if [[ "''${idx}" -eq 10 ]]; then
2022-11-11 11:54:21 +01:00
idx=9
fi
battery_icon="''${battery_icons[''${idx}]}"
printf "%s %i%%" "''${battery_icon}" "''${battery_level}"
fi
'';
in
{
options.eboskma.programs.polybar = { enable = mkEnableOption "activate polybar"; };
config = mkIf cfg.enable {
2022-11-11 11:54:21 +01:00
# systemd.user.services.polybar = {
# Install = { WantedBy = [ "graphical-session.target" ]; };
# };
services.polybar = {
enable = true;
package = pkgs.polybarFull.override {
i3Support = true;
pulseSupport = true;
mpdSupport = true;
};
2022-11-11 11:54:21 +01:00
script = ''
${pkgs.polybar}/bin/polybar-msg cmd quit
while ${pkgs.procps}/bin/pgrep -u ''${UID} -x polybar > /dev/null; do sleep 0.1; done
outputs=$(${pkgs.polybar}/bin/polybar -m | ${pkgs.gnugrep}/bin/grep -v primary | ${pkgs.coreutils}/bin/cut -d ':' -f 1)
2022-11-11 11:54:21 +01:00
primary=$(${pkgs.polybar}/bin/polybar -m | ${pkgs.gnugrep}/bin/grep primary | ${pkgs.coreutils}/bin/cut -d ':' -f 1)
MONITOR=''${primary} polybar -q main & disown
sleep 0.5 # Make sure the primary bar is started so the tray appears here
2022-11-11 11:54:21 +01:00
for m in ''${outputs}; do
MONITOR=''${m} polybar -q main & disown
done
'';
settings = {
"global/wm" = {
margin.bottom = 0;
margin.top = 0;
};
"bar/main" = {
monitor = ''''${env:MONITOR:DP-0}'';
fixed.center = true;
width = "100%";
height = 48;
# offset.x = "1%";
# offset.y = "2%";
offset.x = 0;
offset.y = 0;
background = "${colors.background}";
foreground = "${colors.foreground}";
line.size = 2;
font = [
2023-06-01 16:58:04 +02:00
"Iosevka Nerd Font:style=Bold:size=16;2"
"Iosevka Nerd Font:size=18;3"
"Iosevka Nerd Font:size=20;4"
2022-11-11 11:54:21 +01:00
];
modules = {
left = "workspaces playerctl";
2022-11-11 11:54:21 +01:00
center = "date";
right = "headset-battery memory cpu pulseaudio network";
};
dim.value = 0.8;
tray = {
position = "right";
detached = false;
maxsize = 24;
background = "${colors.background}";
offset.x = 0;
offset.y = 0;
padding = 0;
scale = 1.0;
};
enable.ipc = true;
cursor = {
click = "pointer";
};
};
settings = {
screenchange.reload = false;
throttle.output.text = 5;
throttle.output.for = 10;
compositing = {
background = "source";
foreground = "over";
overline = "over";
underline = "over";
border = "over";
};
pseudo.transparency = false;
};
"module/workspaces" = {
type = "internal/i3";
pin.workspaces = true;
strip.wsnumbers = true;
enable.click = true;
enable.scroll = true;
format = "<label-state> <label-mode>";
2023-09-13 14:50:03 +02:00
label = {
mode = {
text = "󰁌 %mode%"; # Icon: arrow_expand_all
padding = 1;
};
focused = {
text = " %index%"; # Icon: fa-circle
padding = 1;
background = "#333333";
underline = "#ffffff";
};
unfocused = {
text = " %index%"; # Icon: fa-circle_o
padding = 1;
};
visible = {
text = " %index%"; # Icon: fa-dot_circle_o
padding = 1;
};
urgent = {
text = " %index%"; # Icon: fa-exclamation_circle
background = "${colors.urgent}";
padding = 1;
};
};
2022-11-11 11:54:21 +01:00
};
"module/playerctl" = {
type = "custom/script";
exec = "${polybar-playerctl}/bin/polybar-playerctl";
interval = 1;
2023-09-13 14:50:03 +02:00
click = {
left = "${polybar-playerctl}/bin/polybar-playerctl play-pause";
middle = "${polybar-playerctl}/bin/polybar-playerctl next";
right = "${polybar-playerctl}/bin/polybar-playerctl prevous";
};
2022-11-11 11:54:21 +01:00
format.padding = 2;
scroll.up = "${polybar-playerctl}/bin/polybar-playerctl next-player";
};
"module/date" = {
type = "internal/date";
interval = 1.0;
2023-09-13 14:50:03 +02:00
time = {
text = " %H:%M:%S";
alt = " %a, %d %b %Y";
};
2022-11-11 11:54:21 +01:00
2023-09-13 14:50:03 +02:00
format = {
text = "<label>";
padding = 2;
};
2022-11-11 11:54:21 +01:00
label.text = "%time%";
};
"module/headset-battery" = {
type = "custom/script";
exec = "${headset-battery}";
interval = 1;
2022-11-11 11:54:21 +01:00
2023-09-13 14:50:03 +02:00
format = {
prefix = " ";
padding = 2;
};
2022-11-11 11:54:21 +01:00
label.text = "%output%";
2023-09-13 14:50:03 +02:00
click = {
left = "${pkgs.headsetcontrol}/bin/headsetcontrol -s 128";
right = "${pkgs.headsetcontrol}/bin/headsetcontrol -s 0";
};
2022-11-11 11:54:21 +01:00
};
"module/memory" = {
type = "internal/memory";
interval = 1;
2023-09-13 14:50:03 +02:00
format = {
text = "<label>";
prefix = "󰍛 "; # Icon: memory
padding = 2;
};
2022-11-11 11:54:21 +01:00
label.text = "%mb_used% (%percentage_used%%)";
};
"module/cpu" = {
type = "internal/cpu";
interval = 1;
2023-09-13 14:50:03 +02:00
format = {
text = "<label>";
prefix = "󰻠 "; # Icon: cpu_64_bit
padding = 2;
};
2022-11-11 11:54:21 +01:00
label = "%percentage:3%%";
};
"module/pulseaudio" = {
type = "internal/pulseaudio";
interval = 5;
use.ui.max = false;
2023-09-13 14:50:03 +02:00
format = {
volume = {
text = "<ramp-volume> <label-volume>";
padding = 2;
};
muted = {
text = "<label-muted>";
prefix = "󰖁"; # Icon: volume_off
background = "${colors.urgent}";
padding = 2;
};
};
2022-11-11 11:54:21 +01:00
2023-09-13 14:50:03 +02:00
label = {
volume.text = "%percentage%%";
2022-11-11 11:54:21 +01:00
2023-09-13 14:50:03 +02:00
muted.text = " Muted";
};
2022-11-11 11:54:21 +01:00
2023-06-01 16:58:04 +02:00
ramp.volume = [ "󰕿" "󰖀" "󰕾" ]; # Icons: volume_low volume_medium volume_high
2022-11-11 11:54:21 +01:00
click.right = "${pkgs.pavucontrol}/bin/pavucontrol";
};
"module/network" = {
type = "internal/network";
interval = 1;
interface = "enp4s0";
click-left = "${pkgs.networkmanagerapplet}/bin/nm-connection-editor";
accumulate.stats = true;
unknown.as.up = true;
2023-09-13 14:50:03 +02:00
format = {
connected = {
text = "<label-connected>";
padding = 2;
};
2022-11-11 11:54:21 +01:00
2023-09-13 14:50:03 +02:00
disconnected = {
text = "<label-disconnected>";
padding = 2;
};
2022-11-11 11:54:21 +01:00
2023-09-13 14:50:03 +02:00
packetloss.text = "<animation-packetloss> <label-connected>";
};
2022-11-11 11:54:21 +01:00
2023-09-13 14:50:03 +02:00
label = {
connected.text = "󰈀 %local_ip% %upspeed:9% %downspeed:9%"; # Icon: ethernet
disconnected.text = "󰲜 %{A1:networkmanager_dmenu &:} Offline%{A}"; # Icon: network_off_outline
};
2022-11-11 11:54:21 +01:00
2023-09-13 14:50:03 +02:00
animation = {
packetloss.text = [
{
text = "";
foreground = "${colors.urgent}";
}
{
text = "";
foreground = "${colors.foreground}";
}
];
packetloss.framerate = 500;
};
2022-11-11 11:54:21 +01:00
};
};
};
};
}