system/home/modules/window_manager/polybar.nix

191 lines
5.2 KiB
Nix
Raw Normal View History

2022-10-12 01:41:32 +03:00
{ lib, config, pkgs, ... }:
with lib;
let
cfg = config.local.polybar;
2022-10-12 01:41:32 +03:00
inherit (config.services.polybar) package;
themeCfg = config.local.theme;
exchangerate = import ./scripts/exchangerate.nix { inherit themeCfg pkgs; };
external_ip = import ./scripts/external_ip.nix { inherit themeCfg pkgs; };
2022-10-12 01:41:32 +03:00
in
{
2022-10-28 15:33:26 +03:00
options.local.polybar = with lib; {
wifiDevice = mkOption {
type = types.str;
example = "wlp11s0f3u2";
description = "Set your wifi device";
};
2022-10-28 15:33:26 +03:00
};
2022-10-12 01:41:32 +03:00
config = {
systemd.user.services.polybar = {
# Add additional /usr/bin to run custom scripts
Service.Environment = mkForce "PATH=${package}/bin:/run/current-system/sw/bin";
};
services.polybar = {
enable = true;
script = "MONITOR=$(xrandr | grep \"connected primary\" | awk '{print $1;}') polybar &";
settings =
let
padding = 1;
# See: https://github.com/polybar/polybar/issues/478
fontVerticalOffset = 2;
mkFont = fontconfig: fontconfig + ";${toString fontVerticalOffset}";
in
{
settings = {
pseudo-transparency = true;
};
"bar/main" = {
monitor = "\${env:MONITOR:DisplayPort-1}";
font = map mkFont [
"Fira Code:size=9:antialias=true"
"Fira Code:bold:size=9:antialias=true"
"FiraCode Nerd Font Mono:size=9:antialias=true"
"FiraCode Nerd Font Mono:size=14:antialias=true"
];
modules = {
left = "xmonad";
center = "date wifi external_ip";
right = "exchangerate volume battery lang time";
};
offset-x = "6px";
offset-y = "6px";
width = "100%:-12px";
height = "26px";
padding = 1;
radius = 6.0;
background = themeCfg.bar.background;
foreground = themeCfg.bar.mainText;
2022-10-28 23:46:40 +03:00
enable-ipc = true;
2022-10-12 01:41:32 +03:00
};
"module/date" = {
type = "internal/date";
interval = 10;
date = "%a %d %b %Y";
label = "%date%";
format = { inherit padding; };
2022-10-12 01:41:32 +03:00
};
"module/time" = {
type = "internal/date";
time = "%H:%M:%S";
label = {
text = "%time%";
font = 2;
foreground = themeCfg.highlights.warning;
};
2022-10-12 01:41:32 +03:00
};
"module/lang" = {
type = "internal/xkeyboard";
format = {
inherit padding;
text = "<label-layout>";
};
label.layout.font = 2;
2022-10-12 01:41:32 +03:00
};
"module/volume" = {
type = "custom/script";
exec = "${./scripts/get_volume.sh}";
interval = 1;
format = {
inherit padding;
prefix = "%{T4}%{T-} ";
};
2022-10-12 01:41:32 +03:00
};
"module/battery" = {
type = "internal/battery";
full-at = 99;
low-at = 10;
battery = "BAT0";
adapter = "AC0";
format.charging = {
inherit padding;
text = "%{T3}%{T-} <label-charging>";
foreground = themeCfg.highlights.success;
};
format.discharging = {
inherit padding;
text = "%{T3}<ramp-capacity>%{T-} <label-discharging>";
foreground = themeCfg.highlights.warning;
};
format.full = {
inherit padding;
text = "%{T3}%{T-} <label-full>";
foreground = themeCfg.highlights.success;
};
format.low = {
inherit padding;
text = "%{T3}%{T-} <label-low>";
foreground = themeCfg.highlights.critical;
};
# Only applies if <ramp-capacity> is used
ramp.capacity = [ "" "" "" "" "" ];
2022-10-12 01:41:32 +03:00
};
"module/wifi" = {
type = "internal/network";
interval = 3;
interface = {
type = "wireless";
text = cfg.wifiDevice;
};
label.connected = "%essid% %local_ip%";
format.connected = {
2022-10-19 18:28:59 +03:00
prefix = "| %{T4}%{T-} ";
suffix = " |";
};
};
"module/external_ip" = {
type = "custom/script";
2023-06-16 05:06:23 +03:00
exec = "${external_ip}/bin/external_ip";
interval = 60;
format = {
inherit padding;
};
2022-10-12 01:41:32 +03:00
};
"module/xmonad" = mkIf config.xsession.windowManager.xmonad.enable {
type = "custom/script";
exec = "${pkgs.xmonad-log}/bin/xmonad-log";
tail = true;
2022-10-12 01:41:32 +03:00
};
"module/exchangerate" = {
type = "custom/script";
exec = "${exchangerate}/bin/exchangerate";
interval = 60;
format = {
inherit padding;
prefix = "USD: ";
};
2022-10-12 01:41:32 +03:00
};
"global/wm" = {
margin = {
bottom = 0;
top = 0;
};
2022-10-12 01:41:32 +03:00
};
}
;
};
2022-10-12 01:41:32 +03:00
};
}