1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2024-12-14 11:57:55 +00:00

wlogout: add module (#3629)

This commit is contained in:
Sefa Eyeoglu 2023-01-31 17:06:18 +01:00 committed by GitHub
parent 08a778d803
commit 69696fe539
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 316 additions and 0 deletions

View file

@ -893,6 +893,13 @@ in
A new module is available: 'programs.papis'.
'';
}
{
time = "2023-01-30T10:39:11+00:00";
message = ''
A new module is available: 'programs.wlogout'.
'';
}
];
};
}

View file

@ -192,6 +192,7 @@ let
./programs/watson.nix
./programs/waybar.nix
./programs/wezterm.nix
./programs/wlogout.nix
./programs/xmobar.nix
./programs/yt-dlp.nix
./programs/z-lua.nix

View file

@ -0,0 +1,151 @@
{ config, lib, pkgs, ... }:
let
inherit (lib) all filterAttrs isStorePath literalExpression types;
inherit (lib.options) mkEnableOption mkPackageOption mkOption;
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";
description = "CSS label of button.";
};
action = mkOption {
type = either path str;
default = "";
example = "systemctl poweroff";
description = "Command to execute when clicked.";
};
text = mkOption {
type = str;
default = "";
example = "Shutdown";
description = "Text displayed on button.";
};
keybind = mkOption {
type = str;
default = "";
example = "s";
description = "Keyboard character to trigger this action.";
};
height = mkOption {
type = nullOr (numbers.between 0 1);
default = null;
example = 0.5;
description = "Relative height of tile.";
};
width = mkOption {
type = nullOr (numbers.between 0 1);
default = null;
example = 0.5;
description = "Relative width of tile.";
};
circular = mkOption {
type = nullOr bool;
default = null;
example = true;
description = "Make button circular.";
};
};
};
in {
meta.maintainers = [ lib.maintainers.Scrumplex ];
options.programs.wlogout = with lib.types; {
enable = mkEnableOption "wlogout";
package = mkPackageOption pkgs "wlogout" { };
layout = mkOption {
type = listOf wlogoutLayoutConfig;
default = [ ];
description = ''
Layout configuration for wlogout, see <link
xlink:href="https://github.com/ArtsyMacaw/wlogout#config"/>
for supported values.
'';
example = literalExpression ''
[
{
label = "shutdown";
action = "systemctl poweroff";
text = "Shutdown";
keybind = "s";
}
]
'';
};
style = mkOption {
type = nullOr (either path str);
default = null;
description = ''
CSS style of the bar.
</para>
<para>
See <link xlink:href="https://github.com/ArtsyMacaw/wlogout#style"/>
for the documentation.
</para>
<para>
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;
};
};
}

View file

@ -163,6 +163,7 @@ import nmt {
./modules/programs/terminator
./modules/programs/thunderbird
./modules/programs/waybar
./modules/programs/wlogout
./modules/programs/xmobar
./modules/programs/yt-dlp
./modules/services/barrier

View file

@ -0,0 +1,5 @@
{
wlogout-styling = ./styling.nix;
wlogout-layout-single = ./layout-single.nix;
wlogout-layout-multiple = ./layout-multiple.nix;
}

View file

@ -0,0 +1,6 @@
{"action":"systemctl poweroff","keybind":"s","label":"shutdown","text":"Shutdown"}
{"action":"systemctl hibernate","height":0.5,"keybind":"h","label":"hibernate","text":"Hibernate","width":0.5}
{"action":"systemctl suspend","circular":true,"keybind":"u","label":"suspend","text":"Suspend"}
{"action":"swaymsg exit","keybind":"e","label":"exit","text":"Exit"}
{"action":"systemctl reboot","keybind":"r","label":"reboot","text":"Reboot"}
{"action":"gtklock","keybind":"l","label":"lock","text":"Lock"}

View file

@ -0,0 +1,62 @@
{ config, lib, pkgs, ... }:
with lib;
{
config = {
home.stateVersion = "22.11";
programs.wlogout = {
package = config.lib.test.mkStubPackage { outPath = "@wlogout@"; };
enable = true;
layout = [
{
label = "shutdown";
action = "systemctl poweroff";
text = "Shutdown";
keybind = "s";
}
{
label = "hibernate";
action = "systemctl hibernate";
text = "Hibernate";
keybind = "h";
height = 0.5;
width = 0.5;
}
{
label = "suspend";
action = "systemctl suspend";
text = "Suspend";
keybind = "u";
circular = true;
}
{
label = "exit";
action = "swaymsg exit";
text = "Exit";
keybind = "e";
}
{
label = "reboot";
action = "systemctl reboot";
text = "Reboot";
keybind = "r";
}
{
label = "lock";
action = "gtklock";
text = "Lock";
keybind = "l";
}
];
};
nmt.script = ''
assertPathNotExists home-files/.config/wlogout/style.css
assertFileContent \
home-files/.config/wlogout/layout \
${./layout-multiple-expected.json}
'';
};
}

View file

@ -0,0 +1 @@
{"action":"systemctl poweroff","keybind":"s","label":"shutdown","text":"Shutdown"}

View file

@ -0,0 +1,27 @@
{ config, lib, pkgs, ... }:
with lib;
{
config = {
home.stateVersion = "22.11";
programs.wlogout = {
package = config.lib.test.mkStubPackage { outPath = "@wlogout@"; };
enable = true;
layout = [{
label = "shutdown";
action = "systemctl poweroff";
text = "Shutdown";
keybind = "s";
}];
};
nmt.script = ''
assertPathNotExists home-files/.config/wlogout/style.css
assertFileContent \
home-files/.config/wlogout/layout \
${./layout-single-expected.json}
'';
};
}

View file

@ -0,0 +1,16 @@
* {
border: none;
border-radius: 0;
font-family: Source Code Pro;
font-weight: bold;
color: #abb2bf;
font-size: 18px;
min-height: 0px;
}
window {
background: #16191C;
color: #aab2bf;
}
#window {
padding: 0 0px;
}

View file

@ -0,0 +1,39 @@
{ config, lib, pkgs, ... }:
with lib;
{
config = {
home.stateVersion = "22.11";
programs.wlogout = {
package = config.lib.test.mkStubPackage { outPath = "@wlogout@"; };
enable = true;
style = ''
* {
border: none;
border-radius: 0;
font-family: Source Code Pro;
font-weight: bold;
color: #abb2bf;
font-size: 18px;
min-height: 0px;
}
window {
background: #16191C;
color: #aab2bf;
}
#window {
padding: 0 0px;
}
'';
};
nmt.script = ''
assertPathNotExists home-files/.config/wlogout/layout
assertFileContent \
home-files/.config/wlogout/style.css \
${./styling-expected.css}
'';
};
}