feat: enhance Waybar configuration for Sway/Hyprland with improved module settings and autostart functionality

This commit is contained in:
2025-10-06 12:08:32 -03:00
parent 86d27b80d8
commit e38480e320

View File

@@ -1,5 +1,21 @@
{pkgs, ...}: let {
waybarStyle = ''* { color: #ffffff; }''; pkgs,
config,
...
}: let
# Safely access system-level stylix targets (may not always be present during some checks)
stylixTargets =
if config.stylix != null && config.stylix ? targets
then config.stylix.targets
else {};
waybarOut =
if stylixTargets ? waybar && stylixTargets.waybar ? stylixTargets.waybar.outPath
then stylixTargets.waybar.outPath
else null;
colors =
if config.lib != null && config.lib.stylix != null && config.lib.stylix.colors != null
then config.lib.stylix.colors
else {base05 = "ffffff";};
in { in {
# Use the programs.waybar home-manager module # Use the programs.waybar home-manager module
programs.waybar = { programs.waybar = {
@@ -7,48 +23,170 @@ in {
package = pkgs.waybar; package = pkgs.waybar;
systemd.enable = true; systemd.enable = true;
# Minimal config as a Nix attribute set; users can override ~/.config/waybar/config if desired # Waybar settings tailored for sway/hyprland-style setups
settings = { settings = {
mainBar = { mainBar = {
layer = "top"; layer = "top";
position = "top"; position = "top";
modules-left = ["niri/workspaces"]; height = 35;
modules-center = []; spacing = 4;
modules-right = ["tray" "clock"];
"niri/workspaces" = { # Add a placeholder for your window manager's workspace module
format = "{name}"; # For Sway/Hyprland: "sway/workspaces" or "hyprland/workspaces"
modules-left = ["sway/workspaces" "sway/mode"];
modules-center = ["sway/window"];
modules-right = [
"bluetooth"
"network"
"pipewire"
"tray"
"battery"
"clock"
];
# --- Module Definitions ---
"sway/workspaces" = {
disable-scroll = true;
all-outputs = true;
format = "{name}: {icon}";
format-icons = {
"1" = "";
"2" = "";
"3" = "";
"focused" = "";
"default" = "";
};
}; };
clock = { clock = {
format = "{:%H:%M}"; format = " {:%I:%M %p}";
tooltip-format = "<big>{:%Y %B}</big>\n<tt><small>{calendar}</small></tt>"; tooltip-format = "<big>{:%A, %B %d, %Y}</big>\n<tt><small>{calendar}</small></tt>";
};
tray = {
"icon-size" = 18;
spacing = 10;
};
pipewire = {
format = "{icon} {volume}%";
format-muted = "󰖁 Muted";
format-icons = {
"default" = ["󰕿" "󰖀" "󰕾"];
};
# Native PipeWire control using wpctl
on-click = "${pkgs.pavucontrol}/bin/pavucontrol";
on-click-right = "wpctl set-mute @DEFAULT_SINK@ toggle";
on-scroll-up = "wpctl set-volume @DEFAULT_SINK@ +5%";
on-scroll-down = "wpctl set-volume @DEFAULT_SINK@ -5%";
scroll-step = 5;
};
network = {
format-wifi = "󰖩 {essid}";
format-ethernet = "󰈀 Wired";
format-disconnected = "󰖪 Off";
on-click = "nm-connection-editor";
};
# Battery module (uses sysfs/upower depending on system)
battery = {
format = "{capacity}% {icon}";
tooltip = true;
format-icons = {
"discharging" = ""; # low battery icon
"charging" = ""; # charging icon
"full" = "";
};
};
bluetooth = {
format = "󰂯 {status}";
format-disabled = "󰂲 Off";
format-connected = "󰂱 {device_alias}";
on-click = "blueman-manager";
}; };
}; };
}; };
# Minimal CSS; consider generating this from config.lib.stylix.colors for richer theming # Use Stylix-generated CSS as a base and override icon/text color to a monochrome value
style = waybarStyle; style = let
importLine =
if waybarOut != null
then ''@import "${toString waybarOut}";''
else ''/* stylix waybar target not available */'';
in
with colors; ''
/* Import the CSS generated by Stylix for Waybar (if available) */
${importLine}
/* Override the color for common modules to a single monochrome color */
#workspaces button label,
#taskbar button label,
#clock,
#tray,
#network,
#pulseaudio,
#battery {
color: #${base05};
}
/* Fallback: target all labels */
label {
color: #${base05};
}
/* Prefer a single icon font for consistent monochrome icons */
* {
font-family: "JetBrainsMono Nerd Font", sans-serif;
}
'';
}; };
# The config file is generated automatically by programs.waybar, so we don't need manual file writes # The config file is generated automatically by programs.waybar, so we don't need manual file writes
# Users can override by setting programs.waybar.settings directly in their config # Users can override by setting programs.waybar.settings directly in their config
# Make sure nm-applet is available and autostarts so its tray icon shows up in the tray module # Keep GUI helper packages but don't autostart applets here.
home.packages = with pkgs; [networkmanagerapplet]; # We prefer Waybar modules (network/pipewire/bluetooth/battery) as the primary
# UI so users don't get duplicate tray icons. GUI tools are still available
# via `home.packages` and the Waybar on-click actions (pavucontrol, nm-connection-editor,
# blueman-manager) will launch them when needed.
home.packages = with pkgs; [networkmanagerapplet blueman pavucontrol pasystray];
# Start nm-applet as a systemd user service for UWSM integration # Hide the nm-applet and blueman tray icons by overriding their icon entries
systemd.user.services.nm-applet = { # in the user's icon theme with a transparent SVG. This lets the applets run
Unit = { # (providing background/autoconnect and secret-service integration) while Waybar
Description = "Network Manager Applet"; # provides the visible UI with nicer icons.
PartOf = ["graphical-session.target"]; home.file."${config.home.homeDirectory}/.local/share/icons/hicolor/scalable/status/nm-applet.svg".text = ''
After = ["graphical-session.target"]; <svg xmlns="http://www.w3.org/2000/svg" width="1" height="1" viewBox="0 0 1 1"></svg>
}; '';
Service = {
ExecStart = "${pkgs.networkmanagerapplet}/bin/nm-applet"; home.file."${config.home.homeDirectory}/.local/share/icons/hicolor/scalable/status/network-wireless.svg".text = ''
Restart = "on-failure"; <svg xmlns="http://www.w3.org/2000/svg" width="1" height="1" viewBox="0 0 1 1"></svg>
}; '';
Install = {
WantedBy = ["graphical-session.target"]; home.file."${config.home.homeDirectory}/.local/share/icons/hicolor/scalable/status/blueman.svg".text = ''
}; <svg xmlns="http://www.w3.org/2000/svg" width="1" height="1" viewBox="0 0 1 1"></svg>
}; '';
# Autostart the applets so they provide background/network/keyring integration
# while their icons remain hidden (Waybar shows the label/text UI).
home.file."${config.home.homeDirectory}/.config/autostart/nm-applet.desktop".text = ''
[Desktop Entry]
Type=Application
Exec=${pkgs.networkmanagerapplet}/bin/nm-applet
Hidden=false
X-GNOME-Autostart-enabled=true
Name=Network Manager Applet
Comment=Autostart nm-applet for network management
'';
home.file."${config.home.homeDirectory}/.config/autostart/blueman-manager.desktop".text = ''
[Desktop Entry]
Type=Application
Exec=${pkgs.blueman}/bin/blueman-applet
Hidden=false
X-GNOME-Autostart-enabled=true
Name=Blueman Applet
Comment=Autostart blueman for bluetooth management
'';
} }