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;
|
|
|
|
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;
|
|
|
|
description = ''
|
|
|
|
Decide if the bar is displayed in front (<code>"top"</code>)
|
|
|
|
of the windows or behind (<code>"bottom"</code>).
|
|
|
|
'';
|
|
|
|
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" ]
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
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";
|
|
|
|
description = "Bar position relative to the output.";
|
|
|
|
};
|
|
|
|
|
|
|
|
height = mkOption {
|
|
|
|
type = nullOr ints.unsigned;
|
|
|
|
default = null;
|
|
|
|
example = 5;
|
|
|
|
description =
|
|
|
|
"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;
|
|
|
|
description =
|
|
|
|
"Width to be used by the bar if possible. Leave blank for a dynamic value.";
|
|
|
|
};
|
|
|
|
|
|
|
|
modules-left = mkOption {
|
2020-11-15 23:29:36 +01:00
|
|
|
type = listOf str;
|
|
|
|
default = [ ];
|
2020-07-29 22:29:51 +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 {
|
2020-11-15 23:29:36 +01:00
|
|
|
type = listOf str;
|
|
|
|
default = [ ];
|
2020-07-29 22:29:51 +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 {
|
2020-11-15 23:29:36 +01:00
|
|
|
type = listOf str;
|
|
|
|
default = [ ];
|
2020-07-29 22:29:51 +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;
|
2020-07-29 22:29:51 +02:00
|
|
|
default = { };
|
|
|
|
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;
|
|
|
|
description = "Margins value using the CSS format without units.";
|
|
|
|
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;
|
|
|
|
description =
|
|
|
|
"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;
|
|
|
|
description =
|
|
|
|
"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; {
|
|
|
|
enable = mkEnableOption "Waybar";
|
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = package;
|
|
|
|
default = pkgs.waybar;
|
2021-11-18 23:59:20 +01:00
|
|
|
defaultText = literalExpression "pkgs.waybar";
|
2020-07-29 22:29:51 +02:00
|
|
|
description = ''
|
2021-11-18 23:59:20 +01:00
|
|
|
Waybar package to use. Set to <code>null</code> to use the default package.
|
2020-07-29 22:29:51 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
settings = mkOption {
|
|
|
|
type = listOf waybarBarConfig;
|
|
|
|
default = [ ];
|
|
|
|
description = ''
|
|
|
|
Configuration for Waybar, see <link
|
|
|
|
xlink:href="https://github.com/Alexays/Waybar/wiki/Configuration"/>
|
|
|
|
for supported values.
|
|
|
|
'';
|
2021-10-09 11:14:08 +02:00
|
|
|
example = literalExpression ''
|
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" ];
|
|
|
|
modules = {
|
|
|
|
"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"
|
|
|
|
''';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
]
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.enable = mkEnableOption "Waybar systemd integration";
|
|
|
|
|
|
|
|
style = mkOption {
|
2021-11-18 23:59:20 +01:00
|
|
|
type = nullOr (either path str);
|
2020-07-29 22:29:51 +02:00
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
CSS style of the bar.
|
2021-11-18 23:59:20 +01:00
|
|
|
</para>
|
|
|
|
<para>
|
2020-07-29 22:29:51 +02:00
|
|
|
See <link xlink:href="https://github.com/Alexays/Waybar/wiki/Configuration"/>
|
|
|
|
for the documentation.
|
2021-11-18 23:59:20 +01:00
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
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.
|
|
|
|
removeNulls = filterAttrs (_: v: v != null);
|
|
|
|
|
|
|
|
# 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 =
|
|
|
|
optionalAttrs (configuration.modules != { }) configuration.modules;
|
|
|
|
in removeNulls (settingsWithoutModules // settingsModules);
|
|
|
|
# The clean list of configurations
|
|
|
|
finalConfiguration = map makeConfiguration cfg.settings;
|
|
|
|
|
|
|
|
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
|
|
|
|
all (x: !hasAttr "modules" x) cfg.settings
|
|
|
|
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-11-18 23:59:20 +01:00
|
|
|
xdg.configFile."waybar/config" = mkIf (cfg.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" ];
|
2021-05-01 22:26:10 +02:00
|
|
|
After = [ "graphical-session.target" ];
|
2020-07-29 22:29:51 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
Service = {
|
|
|
|
ExecStart = "${cfg.package}/bin/waybar";
|
2021-05-01 22:26:10 +02:00
|
|
|
ExecReload = "kill -SIGUSR2 $MAINPID";
|
|
|
|
Restart = "on-failure";
|
2021-03-06 08:09:51 +01:00
|
|
|
KillMode = "mixed";
|
2020-07-29 22:29:51 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
Install = { WantedBy = [ "graphical-session.target" ]; };
|
|
|
|
};
|
|
|
|
})
|
|
|
|
]);
|
|
|
|
}
|