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

345 lines
9.2 KiB
Nix

{ 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)
battery_icons=( )
battery_charging=""
if [ "''${battery_level}" -eq -1 ]; then
printf "%s " "''${battery_charging}"
else
idx=$(((battery_level / 10)))
if [ "''${idx}" -eq 10 ]; then
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 {
# systemd.user.services.polybar = {
# Install = { WantedBy = [ "graphical-session.target" ]; };
# };
services.polybar = {
enable = true;
package = pkgs.polybarFull.override {
i3GapsSupport = true;
};
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.coreutils}/bin/cut -d ':' -f 1)
primary=$(${pkgs.polybar}/bin/polybar -m | ${pkgs.gnugrep}/bin/grep primary | ${pkgs.coreutils}/bin/cut -d ':' -f 1)
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 = [
"Monofur Nerd Font:style=Bold:size=16;2"
"Monofur Nerd Font:size=18;3"
"Monofur Nerd Font:size=20;4"
];
modules = {
left = "launcher workspaces playerctl";
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/launcher" = {
type = "custom/text";
content.text = "";
content.padding = 2;
click.left = "${pkgs.rofi}/bin/rofi -show drun -no-lazy-grab";
};
"module/workspaces" = {
# type = "internal/xworkspaces";
# pin.workspaces = true;
# enable.click = true;
# enable.scroll = true;
# icon.text = [ "1;" "2;" "3;" "4;" "5;" ];
# icon.default = "";
# format.text = "<label-state>";
# format.padding = 1;
# label.active.text = "";
# label.occupied.text = "";
# label.empty.text = "";
# label.urgent.text = "";
# label.urgent.background = "${colors.urgent}";
# label.active.padding = 1;
# label.urgent.padding = 1;
# label.occupied.padding = 1;
# label.empty.padding = 1;
type = "internal/i3";
pin.workspaces = true;
strip.wsnumbers = true;
enable.click = true;
enable.scroll = true;
# ws.icon.text = [ "1;" "2;" "3;" "4;" "5;" "6;" "7;" "8;" "9;" "10;" ];
# ws.icon.text = [ "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" ];
# ws.icon.default = "";
format = "<label-state> <label-mode>";
label.mode.text = "%mode%";
label.mode.padding = 1;
# label.focused.text = "";
label.focused.text = "%index%";
label.focused.padding = 1;
label.focused.background = "#333333";
label.focused.underline = "#ffffff";
# label.unfocused.text = "";
label.unfocused.text = "%index%";
label.unfocused.padding = 1;
# label.visible.text = "";
label.visible.text = "%index%";
label.visible.padding = 1;
# label.urgent.text = "";
label.urgent.text = "%index%";
label.urgent.background = "${colors.urgent}";
label.urgent.padding = 1;
};
"module/playerctl" = {
type = "custom/script";
exec = "${polybar-playerctl}/bin/polybar-playerctl";
interval = 1;
click.left = "${polybar-playerctl}/bin/polybar-playerctl play-pause";
click.middle = "${polybar-playerctl}/bin/polybar-playerctl next";
click.right = "${polybar-playerctl}/bin/polybar-playerctl prevous";
format.padding = 2;
scroll.up = "${polybar-playerctl}/bin/polybar-playerctl next-player";
};
"module/date" = {
type = "internal/date";
interval = 1.0;
time.text = " %H:%M:%S";
time.alt = " %a, %d %b %Y";
format.text = "<label>";
format.padding = 2;
label.text = "%time%";
};
"module/headset-battery" = {
type = "custom/script";
exec = "${headset-battery}";
interval = 5;
format.prefix = " ";
format.padding = 2;
label.text = "%output%";
click.left = "${pkgs.headsetcontrol}/bin/headsetcontrol -s 128";
click.right = "${pkgs.headsetcontrol}/bin/headsetcontrol -s 0";
};
"module/memory" = {
type = "internal/memory";
interval = 1;
format.text = "<label>";
format.prefix = " ";
format.padding = 2;
label.text = "%mb_used% (%percentage_used%%)";
};
"module/cpu" = {
type = "internal/cpu";
interval = 1;
format.text = "<label>";
format.prefix = "";
format.padding = 2;
label = "%percentage:3%%";
};
"module/pulseaudio" = {
type = "internal/pulseaudio";
interval = 5;
use.ui.max = false;
format.volume.text = "<ramp-volume> <label-volume>";
format.volume.padding = 2;
format.muted.text = "<label-muted>";
format.muted.prefix = "";
format.muted.background = "${colors.urgent}";
format.muted.padding = 2;
label.volume.text = "%percentage%%";
label.muted.text = " Muted";
ramp.volume = [ "" "奔" "" ];
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;
format.connected.text = "<label-connected>";
format.connected.padding = 2;
format.disconnected.text = "<label-disconnected>";
format.disconnected.padding = 2;
format.packetloss.text = "<animation-packetloss> <label-connected>";
label.connected.text = " %local_ip% %upspeed:9% %downspeed:9%";
label.disconnected.text = "%{A1:networkmanager_dmenu &:} Offline%{A}";
animation.packetloss.text = [
{
text = "";
foreground = "${colors.urgent}";
}
{
text = "";
foreground = "${colors.foreground}";
}
];
animation.packetloss.framerate = 500;
};
};
};
};
}