2020-07-29 22:29:51 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
let
|
2020-11-15 23:29:36 +01:00
|
|
|
inherit (lib)
|
2021-11-18 23:59:20 +01:00
|
|
|
all filterAttrs hasAttr isStorePath literalExpression optionalAttrs types;
|
2021-10-09 11:14:08 +02:00
|
|
|
inherit (lib.options) mkEnableOption mkOption;
|
2020-11-15 23:29:36 +01:00
|
|
|
inherit (lib.modules) mkIf mkMerge;
|
|
|
|
|
2020-07-29 22:29:51 +02:00
|
|
|
cfg = config.programs.waybar;
|
|
|
|
|
2020-11-15 23:29:36 +01:00
|
|
|
jsonFormat = pkgs.formats.json { };
|
|
|
|
|
2021-11-18 23:59:20 +01:00
|
|
|
mkMargin = name:
|
|
|
|
mkOption {
|
|
|
|
type = types.nullOr types.int;
|
|
|
|
default = null;
|
|
|
|
example = 10;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "Margin value without unit.";
|
2020-07-29 22:29:51 +02:00
|
|
|
};
|
|
|
|
|
2021-11-18 23:59:20 +01:00
|
|
|
waybarBarConfig = with types;
|
2020-07-29 22:29:51 +02:00
|
|
|
submodule {
|
2021-11-18 23:59:20 +01:00
|
|
|
freeformType = jsonFormat.type;
|
|
|
|
|
2020-07-29 22:29:51 +02:00
|
|
|
options = {
|
|
|
|
layer = mkOption {
|
|
|
|
type = nullOr (enum [ "top" "bottom" ]);
|
|
|
|
default = null;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2023-07-01 01:30:13 +02:00
|
|
|
Decide if the bar is displayed in front (`"top"`)
|
|
|
|
of the windows or behind (`"bottom"`).
|
2020-07-29 22:29:51 +02:00
|
|
|
'';
|
|
|
|
example = "top";
|
|
|
|
};
|
|
|
|
|
|
|
|
output = mkOption {
|
|
|
|
type = nullOr (either str (listOf str));
|
|
|
|
default = null;
|
2021-10-09 11:14:08 +02:00
|
|
|
example = literalExpression ''
|
2020-07-29 22:29:51 +02:00
|
|
|
[ "DP-1" "!DP-2" "!DP-3" ]
|
|
|
|
'';
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2020-07-29 22:29:51 +02:00
|
|
|
Specifies on which screen this bar will be displayed.
|
|
|
|
Exclamation mark(!) can be used to exclude specific output.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
position = mkOption {
|
|
|
|
type = nullOr (enum [ "top" "bottom" "left" "right" ]);
|
|
|
|
default = null;
|
|
|
|
example = "right";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "Bar position relative to the output.";
|
2020-07-29 22:29:51 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
height = mkOption {
|
|
|
|
type = nullOr ints.unsigned;
|
|
|
|
default = null;
|
|
|
|
example = 5;
|
2023-07-02 01:45:18 +02:00
|
|
|
description =
|
2020-07-29 22:29:51 +02:00
|
|
|
"Height to be used by the bar if possible. Leave blank for a dynamic value.";
|
|
|
|
};
|
|
|
|
|
|
|
|
width = mkOption {
|
|
|
|
type = nullOr ints.unsigned;
|
|
|
|
default = null;
|
|
|
|
example = 5;
|
2023-07-02 01:45:18 +02:00
|
|
|
description =
|
2020-07-29 22:29:51 +02:00
|
|
|
"Width to be used by the bar if possible. Leave blank for a dynamic value.";
|
|
|
|
};
|
|
|
|
|
|
|
|
modules-left = mkOption {
|
2024-06-09 13:14:04 +02:00
|
|
|
type = nullOr (listOf str);
|
|
|
|
default = null;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "Modules that will be displayed on the left.";
|
2021-10-09 11:14:08 +02:00
|
|
|
example = literalExpression ''
|
2020-07-29 22:29:51 +02:00
|
|
|
[ "sway/workspaces" "sway/mode" "wlr/taskbar" ]
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
modules-center = mkOption {
|
2024-06-09 13:14:04 +02:00
|
|
|
type = nullOr (listOf str);
|
|
|
|
default = null;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "Modules that will be displayed in the center.";
|
2021-10-09 11:14:08 +02:00
|
|
|
example = literalExpression ''
|
2020-07-29 22:29:51 +02:00
|
|
|
[ "sway/window" ]
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
modules-right = mkOption {
|
2024-06-09 13:14:04 +02:00
|
|
|
type = nullOr (listOf str);
|
|
|
|
default = null;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "Modules that will be displayed on the right.";
|
2021-10-09 11:14:08 +02:00
|
|
|
example = literalExpression ''
|
2020-07-29 22:29:51 +02:00
|
|
|
[ "mpd" "custom/mymodule#with-css-id" "temperature" ]
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
modules = mkOption {
|
2020-11-15 23:29:36 +01:00
|
|
|
type = jsonFormat.type;
|
2022-01-17 22:38:22 +01:00
|
|
|
visible = false;
|
|
|
|
default = null;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "Modules configuration.";
|
2021-10-09 11:14:08 +02:00
|
|
|
example = literalExpression ''
|
2020-07-29 22:29:51 +02:00
|
|
|
{
|
|
|
|
"sway/window" = {
|
|
|
|
max-length = 50;
|
|
|
|
};
|
|
|
|
"clock" = {
|
|
|
|
format-alt = "{:%a, %d. %b %H:%M}";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
margin = mkOption {
|
|
|
|
type = nullOr str;
|
|
|
|
default = null;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "Margins value using the CSS format without units.";
|
2020-07-29 22:29:51 +02:00
|
|
|
example = "20 5";
|
|
|
|
};
|
|
|
|
|
2021-11-18 23:59:20 +01:00
|
|
|
margin-left = mkMargin "left";
|
|
|
|
margin-right = mkMargin "right";
|
|
|
|
margin-bottom = mkMargin "bottom";
|
|
|
|
margin-top = mkMargin "top";
|
2020-07-29 22:29:51 +02:00
|
|
|
|
|
|
|
name = mkOption {
|
|
|
|
type = nullOr str;
|
|
|
|
default = null;
|
2023-07-02 01:45:18 +02:00
|
|
|
description =
|
2020-07-29 22:29:51 +02:00
|
|
|
"Optional name added as a CSS class, for styling multiple waybars.";
|
|
|
|
example = "waybar-1";
|
|
|
|
};
|
|
|
|
|
|
|
|
gtk-layer-shell = mkOption {
|
|
|
|
type = nullOr bool;
|
|
|
|
default = null;
|
|
|
|
example = false;
|
2023-07-02 01:45:18 +02:00
|
|
|
description =
|
2020-07-29 22:29:51 +02:00
|
|
|
"Option to disable the use of gtk-layer-shell for popups.";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in {
|
2020-10-22 17:07:14 +02:00
|
|
|
meta.maintainers = with lib.maintainers; [ berbiche ];
|
2020-07-29 22:29:51 +02:00
|
|
|
|
|
|
|
options.programs.waybar = with lib.types; {
|
2023-07-02 01:45:18 +02:00
|
|
|
enable = mkEnableOption "Waybar";
|
2020-07-29 22:29:51 +02:00
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = package;
|
|
|
|
default = pkgs.waybar;
|
2021-11-18 23:59:20 +01:00
|
|
|
defaultText = literalExpression "pkgs.waybar";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2023-07-01 01:30:13 +02:00
|
|
|
Waybar package to use. Set to `null` to use the default package.
|
2020-07-29 22:29:51 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
settings = mkOption {
|
2021-12-19 06:21:15 +01:00
|
|
|
type = either (listOf waybarBarConfig) (attrsOf waybarBarConfig);
|
2020-07-29 22:29:51 +02:00
|
|
|
default = [ ];
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2023-07-01 01:30:13 +02:00
|
|
|
Configuration for Waybar, see <https://github.com/Alexays/Waybar/wiki/Configuration>
|
2020-07-29 22:29:51 +02:00
|
|
|
for supported values.
|
|
|
|
'';
|
2021-10-09 11:14:08 +02:00
|
|
|
example = literalExpression ''
|
2021-12-19 06:21:15 +01:00
|
|
|
{
|
|
|
|
mainBar = {
|
2020-07-29 22:29:51 +02:00
|
|
|
layer = "top";
|
|
|
|
position = "top";
|
|
|
|
height = 30;
|
|
|
|
output = [
|
|
|
|
"eDP-1"
|
|
|
|
"HDMI-A-1"
|
|
|
|
];
|
|
|
|
modules-left = [ "sway/workspaces" "sway/mode" "wlr/taskbar" ];
|
|
|
|
modules-center = [ "sway/window" "custom/hello-from-waybar" ];
|
|
|
|
modules-right = [ "mpd" "custom/mymodule#with-css-id" "temperature" ];
|
2022-01-17 22:38:22 +01:00
|
|
|
|
|
|
|
"sway/workspaces" = {
|
|
|
|
disable-scroll = true;
|
|
|
|
all-outputs = true;
|
|
|
|
};
|
|
|
|
"custom/hello-from-waybar" = {
|
|
|
|
format = "hello {}";
|
|
|
|
max-length = 40;
|
|
|
|
interval = "once";
|
|
|
|
exec = pkgs.writeShellScript "hello-from-waybar" '''
|
|
|
|
echo "from within waybar"
|
|
|
|
''';
|
2020-07-29 22:29:51 +02:00
|
|
|
};
|
2021-12-19 06:21:15 +01:00
|
|
|
};
|
|
|
|
}
|
2020-07-29 22:29:51 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-07-02 01:45:18 +02:00
|
|
|
systemd.enable = mkEnableOption "Waybar systemd integration";
|
2020-07-29 22:29:51 +02:00
|
|
|
|
2021-12-23 23:00:31 +01:00
|
|
|
systemd.target = mkOption {
|
|
|
|
type = str;
|
|
|
|
default = "graphical-session.target";
|
|
|
|
example = "sway-session.target";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2021-12-23 23:00:31 +01:00
|
|
|
The systemd target that will automatically start the Waybar service.
|
2023-07-01 01:30:13 +02:00
|
|
|
|
|
|
|
When setting this value to `"sway-session.target"`,
|
|
|
|
make sure to also enable {option}`wayland.windowManager.sway.systemd.enable`,
|
2021-12-23 23:00:31 +01:00
|
|
|
otherwise the service may never be started.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-07-29 22:29:51 +02:00
|
|
|
style = mkOption {
|
2023-05-30 23:06:24 +02:00
|
|
|
type = nullOr (either path lines);
|
2020-07-29 22:29:51 +02:00
|
|
|
default = null;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2020-07-29 22:29:51 +02:00
|
|
|
CSS style of the bar.
|
2023-07-01 01:30:13 +02:00
|
|
|
|
|
|
|
See <https://github.com/Alexays/Waybar/wiki/Configuration>
|
2020-07-29 22:29:51 +02:00
|
|
|
for the documentation.
|
2023-07-01 01:30:13 +02:00
|
|
|
|
2021-11-18 23:59:20 +01:00
|
|
|
If the value is set to a path literal, then the path will be used as the css file.
|
2020-07-29 22:29:51 +02:00
|
|
|
'';
|
|
|
|
example = ''
|
|
|
|
* {
|
|
|
|
border: none;
|
|
|
|
border-radius: 0;
|
|
|
|
font-family: Source Code Pro;
|
|
|
|
}
|
|
|
|
window#waybar {
|
|
|
|
background: #16191C;
|
|
|
|
color: #AAB2BF;
|
|
|
|
}
|
|
|
|
#workspaces button {
|
|
|
|
padding: 0 5px;
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = let
|
2021-11-18 23:59:20 +01:00
|
|
|
# Removes nulls because Waybar ignores them.
|
|
|
|
# This is not recursive.
|
2022-01-17 22:38:22 +01:00
|
|
|
removeTopLevelNulls = filterAttrs (_: v: v != null);
|
2021-11-18 23:59:20 +01:00
|
|
|
|
|
|
|
# Makes the actual valid configuration Waybar accepts
|
|
|
|
# (strips our custom settings before converting to JSON)
|
|
|
|
makeConfiguration = configuration:
|
|
|
|
let
|
|
|
|
# The "modules" option is not valid in the JSON
|
|
|
|
# as its descendants have to live at the top-level
|
|
|
|
settingsWithoutModules = removeAttrs configuration [ "modules" ];
|
|
|
|
settingsModules =
|
2022-01-17 22:38:22 +01:00
|
|
|
optionalAttrs (configuration.modules != null) configuration.modules;
|
|
|
|
in removeTopLevelNulls (settingsWithoutModules // settingsModules);
|
2021-12-19 06:21:15 +01:00
|
|
|
|
|
|
|
# Allow using attrs for settings instead of a list in order to more easily override
|
|
|
|
settings = if builtins.isAttrs cfg.settings then
|
|
|
|
lib.attrValues cfg.settings
|
|
|
|
else
|
|
|
|
cfg.settings;
|
|
|
|
|
2021-11-18 23:59:20 +01:00
|
|
|
# The clean list of configurations
|
2021-12-19 06:21:15 +01:00
|
|
|
finalConfiguration = map makeConfiguration settings;
|
2021-11-18 23:59:20 +01:00
|
|
|
|
|
|
|
configSource = jsonFormat.generate "waybar-config.json" finalConfiguration;
|
2020-07-29 22:29:51 +02:00
|
|
|
|
|
|
|
in mkIf cfg.enable (mkMerge [
|
2021-07-07 23:24:27 +02:00
|
|
|
{
|
|
|
|
assertions = [
|
|
|
|
(lib.hm.assertions.assertPlatform "programs.waybar" pkgs
|
|
|
|
lib.platforms.linux)
|
2021-11-18 23:59:20 +01:00
|
|
|
({
|
|
|
|
assertion =
|
|
|
|
if lib.versionAtLeast config.home.stateVersion "22.05" then
|
2022-01-17 22:38:22 +01:00
|
|
|
all (x: !hasAttr "modules" x || x.modules == null) settings
|
2021-11-18 23:59:20 +01:00
|
|
|
else
|
|
|
|
true;
|
|
|
|
message = ''
|
|
|
|
The `programs.waybar.settings.[].modules` option has been removed.
|
|
|
|
It is now possible to declare modules in the configuration without nesting them under the `modules` option.
|
|
|
|
'';
|
|
|
|
})
|
2021-07-07 23:24:27 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
home.packages = [ cfg.package ];
|
2020-07-29 22:29:51 +02:00
|
|
|
|
2021-12-19 06:21:15 +01:00
|
|
|
xdg.configFile."waybar/config" = mkIf (settings != [ ]) {
|
2021-08-19 05:31:11 +02:00
|
|
|
source = configSource;
|
|
|
|
onChange = ''
|
|
|
|
${pkgs.procps}/bin/pkill -u $USER -USR2 waybar || true
|
|
|
|
'';
|
|
|
|
};
|
2021-07-07 23:24:27 +02:00
|
|
|
|
2021-11-18 23:59:20 +01:00
|
|
|
xdg.configFile."waybar/style.css" = mkIf (cfg.style != null) {
|
|
|
|
source = if builtins.isPath cfg.style || isStorePath cfg.style then
|
|
|
|
cfg.style
|
|
|
|
else
|
|
|
|
pkgs.writeText "waybar/style.css" cfg.style;
|
2021-08-19 05:31:11 +02:00
|
|
|
onChange = ''
|
|
|
|
${pkgs.procps}/bin/pkill -u $USER -USR2 waybar || true
|
|
|
|
'';
|
|
|
|
};
|
2021-11-18 23:59:20 +01:00
|
|
|
}
|
2021-07-07 23:24:27 +02:00
|
|
|
|
2020-07-29 22:29:51 +02:00
|
|
|
(mkIf cfg.systemd.enable {
|
|
|
|
systemd.user.services.waybar = {
|
|
|
|
Unit = {
|
|
|
|
Description =
|
|
|
|
"Highly customizable Wayland bar for Sway and Wlroots based compositors.";
|
|
|
|
Documentation = "https://github.com/Alexays/Waybar/wiki";
|
|
|
|
PartOf = [ "graphical-session.target" ];
|
2023-09-19 20:54:45 +02:00
|
|
|
After = [ "graphical-session-pre.target" ];
|
2020-07-29 22:29:51 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
Service = {
|
|
|
|
ExecStart = "${cfg.package}/bin/waybar";
|
2022-04-17 00:31:03 +02:00
|
|
|
ExecReload = "${pkgs.coreutils}/bin/kill -SIGUSR2 $MAINPID";
|
2021-05-01 22:26:10 +02:00
|
|
|
Restart = "on-failure";
|
2021-03-06 08:09:51 +01:00
|
|
|
KillMode = "mixed";
|
2020-07-29 22:29:51 +02:00
|
|
|
};
|
|
|
|
|
2021-12-23 23:00:31 +01:00
|
|
|
Install = { WantedBy = [ cfg.systemd.target ]; };
|
2020-07-29 22:29:51 +02:00
|
|
|
};
|
|
|
|
})
|
|
|
|
]);
|
|
|
|
}
|