refactor(waybar): produce core registry entries

This commit is contained in:
2026-10-11 19:51:05 -04:00
parent 12304a0951
commit 64f1db737d
3 changed files with 105 additions and 105 deletions

View File

@@ -54,6 +54,11 @@ in
registry.waybar.${config.networking.hostName}."custom/dnd" = { registry.waybar.${config.networking.hostName}."custom/dnd" = {
order = 80; order = 80;
style = ''
#custom-dnd {
margin-right: 8px;
}
'';
settings = { settings = {
return-type = "json"; return-type = "json";
exec = "${dndStatus}"; exec = "${dndStatus}";

View File

@@ -6,47 +6,20 @@
}: }:
# Waybar: a top status bar reading system state at a glance. # Waybar: a top status bar reading system state at a glance.
let let
registeredWaybarStyles = lib.concatStringsSep "\n" (
lib.filter (style: style != "") (lib.mapAttrsToList (_name: module: module.style) hostWaybarModules)
);
hostWaybarModules = lib.attrByPath [ config.networking.hostName ] { } config.registry.waybar;
waybarModulesFor = waybarModulesFor =
position: position:
map (module: module.name) ( map (module: module.name) (
lib.sort (a: b: a.order < b.order) ( lib.sort (a: b: a.order < b.order) (
lib.filter (module: module.position == position) (staticWaybarModules ++ registeredWaybarModules) lib.filter (module: module.position == position) registeredWaybarModules
) )
); );
staticWaybarModules = [
{
name = "hyprland/workspaces";
position = "left";
order = 10;
}
{
name = "clock";
position = "center";
order = 10;
}
{
name = "mpris";
position = "right";
order = 30;
}
{
name = "wireplumber";
position = "right";
order = 40;
}
{
name = "custom/network";
position = "right";
order = 60;
}
{
name = "battery";
position = "right";
order = 70;
}
];
registeredWaybarModules = lib.mapAttrsToList ( registeredWaybarModules = lib.mapAttrsToList (
name: module: name: module:
module module
@@ -55,14 +28,12 @@ let
} }
) hostWaybarModules; ) hostWaybarModules;
hostWaybarModules = lib.attrByPath [ config.networking.hostName ] { } config.registry.waybar; registeredWaybarModuleSettings = lib.mapAttrs (_name: module: module.settings) hostWaybarModules;
# A Nerd Font Private-Use-Area codepoint as a literal character, decoded # A Nerd Font Private-Use-Area codepoint as a literal character, decoded
# through JSON so the glyph survives as bytes rather than an editor paste. # through JSON so the glyph survives as bytes rather than an editor paste.
g = code: builtins.fromJSON ''"\u${code}"''; g = code: builtins.fromJSON ''"\u${code}"'';
registeredWaybarModuleSettings = lib.mapAttrs (_name: module: module.settings) hostWaybarModules;
networkStatus = pkgs.writeShellScript "waybar-network-status" '' networkStatus = pkgs.writeShellScript "waybar-network-status" ''
active=$( active=$(
${lib.getExe' pkgs.networkmanager "nmcli"} -t -f DEVICE,TYPE,STATE,CONNECTION device status \ ${lib.getExe' pkgs.networkmanager "nmcli"} -t -f DEVICE,TYPE,STATE,CONNECTION device status \
@@ -114,11 +85,8 @@ in
.modules-right { .modules-right {
margin-right: 8px; margin-right: 8px;
} }
''
#custom-dnd { + registeredWaybarStyles;
margin-right: 8px;
}
'';
settings.mainBar = lib.mkMerge [ settings.mainBar = lib.mkMerge [
{ {
@@ -131,72 +99,93 @@ in
modules-center = waybarModulesFor "center"; modules-center = waybarModulesFor "center";
modules-right = waybarModulesFor "right"; modules-right = waybarModulesFor "right";
# Per-application icons for the windows on each workspace, mapped from
# window class with a neutral glyph for anything unlisted.
"hyprland/workspaces" = {
on-click = "activate";
format = "{id} {windows}";
format-window-separator = " ";
window-rewrite-default = g "f2d0";
window-rewrite = lib.mapAttrs' (
_name: windowIcon: lib.nameValuePair "class<${windowIcon.class}>" (g windowIcon.icon)
) (lib.attrByPath [ config.networking.hostName ] { } config.registry.window-icon);
};
clock = {
format = "{:%a %d %b %H:%M}";
tooltip-format = "<tt>{calendar}</tt>";
calendar = {
mode = "month";
# Underline the current day so it stands out in the grid.
format.today = "<b><u>{}</u></b>";
};
};
mpris = {
format = "${g "f001"} {title}";
format-paused = "${g "f04c"} {title}";
max-length = 40;
on-click = "play-pause";
on-scroll-up = "next";
on-scroll-down = "previous";
};
wireplumber = {
format = "{icon} {volume}%";
format-muted = "${g "f026"} muted";
format-icons = [
(g "f026")
(g "f027")
(g "f028")
];
on-click = "${lib.getExe' pkgs.wireplumber "wpctl"} set-mute @DEFAULT_AUDIO_SINK@ toggle";
};
"custom/network" = {
return-type = "json";
exec = "${networkStatus}";
interval = 5;
};
battery = {
format = "{icon} {capacity}%";
format-charging = "${g "f0e7"} {capacity}%";
format-icons = [
(g "f244")
(g "f243")
(g "f242")
(g "f241")
(g "f240")
];
states = {
warning = 20;
critical = 10;
};
};
} }
registeredWaybarModuleSettings registeredWaybarModuleSettings
]; ];
}; };
registry.waybar.${config.networking.hostName} = {
"hyprland/workspaces" = {
position = "left";
order = 10;
settings = {
on-click = "activate";
format = "{id} {windows}";
format-window-separator = " ";
window-rewrite-default = g "f2d0";
window-rewrite = lib.mapAttrs' (
_name: windowIcon: lib.nameValuePair "class<${windowIcon.class}>" (g windowIcon.icon)
) (lib.attrByPath [ config.networking.hostName ] { } config.registry.window-icon);
};
};
clock = {
position = "center";
order = 10;
settings = {
format = "{:%a %d %b %H:%M}";
tooltip-format = "<tt>{calendar}</tt>";
calendar = {
mode = "month";
# Underline the current day so it stands out in the grid.
format.today = "<b><u>{}</u></b>";
};
};
};
mpris = {
order = 30;
settings = {
format = "${g "f001"} {title}";
format-paused = "${g "f04c"} {title}";
max-length = 40;
on-click = "play-pause";
on-scroll-up = "next";
on-scroll-down = "previous";
};
};
wireplumber = {
order = 40;
settings = {
format = "{icon} {volume}%";
format-muted = "${g "f026"} muted";
format-icons = [
(g "f026")
(g "f027")
(g "f028")
];
on-click = "${lib.getExe' pkgs.wireplumber "wpctl"} set-mute @DEFAULT_AUDIO_SINK@ toggle";
};
};
"custom/network" = {
order = 60;
settings = {
return-type = "json";
exec = "${networkStatus}";
interval = 5;
};
};
battery = {
order = 70;
settings = {
format = "{icon} {capacity}%";
format-charging = "${g "f0e7"} {capacity}%";
format-icons = [
(g "f244")
(g "f243")
(g "f242")
(g "f241")
(g "f240")
];
states = {
warning = 20;
critical = 10;
};
};
};
};
}; };
} }

View File

@@ -19,6 +19,12 @@
description = "Sorts the module within its Waybar section."; description = "Sorts the module within its Waybar section.";
}; };
style = lib.mkOption {
type = lib.types.lines;
default = "";
description = "Adds CSS for the Waybar module.";
};
settings = lib.mkOption { settings = lib.mkOption {
type = lib.types.attrsOf lib.types.anything; type = lib.types.attrsOf lib.types.anything;
default = { }; default = { };