2023-01-31 17:06:18 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
inherit (lib) all filterAttrs isStorePath literalExpression types;
|
2023-07-02 01:45:18 +02:00
|
|
|
inherit (lib.options) mkEnableOption mkPackageOption mkOption;
|
2023-01-31 17:06:18 +01:00
|
|
|
inherit (lib.modules) mkIf;
|
|
|
|
inherit (lib.strings) concatMapStrings;
|
|
|
|
inherit (builtins) toJSON;
|
|
|
|
|
|
|
|
cfg = config.programs.wlogout;
|
|
|
|
|
|
|
|
jsonFormat = pkgs.formats.json { };
|
|
|
|
|
|
|
|
wlogoutLayoutConfig = with types;
|
|
|
|
submodule {
|
|
|
|
freeformType = jsonFormat.type;
|
|
|
|
|
|
|
|
options = {
|
|
|
|
label = mkOption {
|
|
|
|
type = str;
|
|
|
|
default = "";
|
|
|
|
example = "shutdown";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "CSS label of button.";
|
2023-01-31 17:06:18 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
action = mkOption {
|
|
|
|
type = either path str;
|
|
|
|
default = "";
|
|
|
|
example = "systemctl poweroff";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "Command to execute when clicked.";
|
2023-01-31 17:06:18 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
text = mkOption {
|
|
|
|
type = str;
|
|
|
|
default = "";
|
|
|
|
example = "Shutdown";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "Text displayed on button.";
|
2023-01-31 17:06:18 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
keybind = mkOption {
|
|
|
|
type = str;
|
|
|
|
default = "";
|
|
|
|
example = "s";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "Keyboard character to trigger this action.";
|
2023-01-31 17:06:18 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
height = mkOption {
|
|
|
|
type = nullOr (numbers.between 0 1);
|
|
|
|
default = null;
|
|
|
|
example = 0.5;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "Relative height of tile.";
|
2023-01-31 17:06:18 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
width = mkOption {
|
|
|
|
type = nullOr (numbers.between 0 1);
|
|
|
|
default = null;
|
|
|
|
example = 0.5;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "Relative width of tile.";
|
2023-01-31 17:06:18 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
circular = mkOption {
|
|
|
|
type = nullOr bool;
|
|
|
|
default = null;
|
|
|
|
example = true;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "Make button circular.";
|
2023-01-31 17:06:18 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
meta.maintainers = [ lib.maintainers.Scrumplex ];
|
|
|
|
|
|
|
|
options.programs.wlogout = with lib.types; {
|
2023-07-02 01:45:18 +02:00
|
|
|
enable = mkEnableOption "wlogout";
|
2023-01-31 17:06:18 +01:00
|
|
|
|
2023-07-02 01:45:18 +02:00
|
|
|
package = mkPackageOption pkgs "wlogout" { };
|
2023-01-31 17:06:18 +01:00
|
|
|
|
|
|
|
layout = mkOption {
|
|
|
|
type = listOf wlogoutLayoutConfig;
|
|
|
|
default = [ ];
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2023-07-01 01:30:13 +02:00
|
|
|
Layout configuration for wlogout, see <https://github.com/ArtsyMacaw/wlogout#config>
|
2023-01-31 17:06:18 +01:00
|
|
|
for supported values.
|
|
|
|
'';
|
|
|
|
example = literalExpression ''
|
|
|
|
[
|
|
|
|
{
|
|
|
|
label = "shutdown";
|
|
|
|
action = "systemctl poweroff";
|
|
|
|
text = "Shutdown";
|
|
|
|
keybind = "s";
|
|
|
|
}
|
|
|
|
]
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
style = mkOption {
|
|
|
|
type = nullOr (either path str);
|
|
|
|
default = null;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2023-01-31 17:06:18 +01:00
|
|
|
CSS style of the bar.
|
2023-07-01 01:30:13 +02:00
|
|
|
|
|
|
|
See <https://github.com/ArtsyMacaw/wlogout#style>
|
2023-01-31 17:06:18 +01:00
|
|
|
for the documentation.
|
2023-07-01 01:30:13 +02:00
|
|
|
|
2023-01-31 17:06:18 +01:00
|
|
|
If the value is set to a path literal, then the path will be used as the css file.
|
|
|
|
'';
|
|
|
|
example = ''
|
|
|
|
window {
|
|
|
|
background: #16191C;
|
|
|
|
}
|
|
|
|
|
|
|
|
button {
|
|
|
|
color: #AAB2BF;
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = let
|
|
|
|
# Removes nulls because wlogout ignores them.
|
|
|
|
# This is not recursive.
|
|
|
|
removeTopLevelNulls = filterAttrs (_: v: v != null);
|
|
|
|
cleanJSON = foo: toJSON (removeTopLevelNulls foo);
|
|
|
|
|
|
|
|
# wlogout doesn't want a JSON array, it just wants a list of JSON objects
|
|
|
|
layoutJsons = map cleanJSON cfg.layout;
|
|
|
|
layoutContent = concatMapStrings (l: l + "\n") layoutJsons;
|
|
|
|
|
|
|
|
in mkIf cfg.enable {
|
|
|
|
assertions = [
|
|
|
|
(lib.hm.assertions.assertPlatform "programs.wlogout" pkgs
|
|
|
|
lib.platforms.linux)
|
|
|
|
];
|
|
|
|
|
|
|
|
home.packages = [ cfg.package ];
|
|
|
|
|
|
|
|
xdg.configFile."wlogout/layout" = mkIf (cfg.layout != [ ]) {
|
|
|
|
source = pkgs.writeText "wlogout/layout" layoutContent;
|
|
|
|
};
|
|
|
|
|
|
|
|
xdg.configFile."wlogout/style.css" = mkIf (cfg.style != null) {
|
|
|
|
source = if builtins.isPath cfg.style || isStorePath cfg.style then
|
|
|
|
cfg.style
|
|
|
|
else
|
|
|
|
pkgs.writeText "wlogout/style.css" cfg.style;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|