From 15ae861e1bfad90e0d14106551544e9e07cbcb10 Mon Sep 17 00:00:00 2001 From: polykernel <81340136+polykernel@users.noreply.github.com> Date: Sat, 20 Nov 2021 23:06:12 -0500 Subject: [PATCH] swaynag: add module Swaynag is a replacement of i3-nag for sway. Swaynag is embedded in Sway's build process albeit it is not an integral part of Sway, therefore it has been added under `wayland.windowManager.sway` instead of `programs`. It can be moved at a later time if necessary. Two unit tests were added validate the module behavior for an empty configuration and the example configuration. --- .github/CODEOWNERS | 2 + modules/misc/news.nix | 8 +++ modules/modules.nix | 1 + .../window-managers/i3-sway/swaynag.nix | 70 +++++++++++++++++++ .../services/window-managers/sway/default.nix | 2 + .../sway/swaynag-empty-settings.nix | 15 ++++ .../swaynag-example-settings-expected.conf | 10 +++ .../sway/swaynag-example-settings.nix | 30 ++++++++ 8 files changed, 138 insertions(+) create mode 100644 modules/services/window-managers/i3-sway/swaynag.nix create mode 100644 tests/modules/services/window-managers/sway/swaynag-empty-settings.nix create mode 100644 tests/modules/services/window-managers/sway/swaynag-example-settings-expected.conf create mode 100644 tests/modules/services/window-managers/sway/swaynag-example-settings.nix diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index a12d9d95..316c3636 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -353,6 +353,8 @@ /modules/services/window-managers/i3-sway/sway.nix @alexarice @sumnerevans /tests/modules/services/window-managers/sway @sumnerevans +/modules/services/window-managers/i3-sway/swaynag.nix @polykernel + /modules/services/wlsunset.nix @matrss /tests/modules/services/wlsunset @matrss diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 5bdb31f8..09e6a235 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -2233,6 +2233,14 @@ in A new module is available: 'programs.hexchat'. ''; } + + { + time = "2021-11-21T17:21:04+00:00"; + condition = config.wayland.windowManager.sway.enable; + message = '' + A new module is available: 'wayland.windowManager.sway.swaynag'. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index ab2761f8..cb8d2bdb 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -227,6 +227,7 @@ let ./services/window-managers/bspwm/default.nix ./services/window-managers/i3-sway/i3.nix ./services/window-managers/i3-sway/sway.nix + ./services/window-managers/i3-sway/swaynag.nix ./services/window-managers/xmonad.nix ./services/wlsunset.nix ./services/xcape.nix diff --git a/modules/services/window-managers/i3-sway/swaynag.nix b/modules/services/window-managers/i3-sway/swaynag.nix new file mode 100644 index 00000000..97d6f473 --- /dev/null +++ b/modules/services/window-managers/i3-sway/swaynag.nix @@ -0,0 +1,70 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.wayland.windowManager.sway.swaynag; + + iniFormat = pkgs.formats.ini { }; + + confFormat = with types; + let + confAtom = nullOr (oneOf [ bool int float str ]) // { + description = "Swaynag config atom (null, bool, int, float, str)"; + }; + in attrsOf confAtom; +in { + meta.maintainers = with maintainers; [ polykernel ]; + + options = { + wayland.windowManager.sway.swaynag = { + enable = mkEnableOption + "configuration of swaynag, a lightweight error bar for sway"; + + settings = mkOption { + type = types.attrsOf confFormat; + default = { }; + description = '' + Configuration written to + $XDG_CONFIG_HOME/swaynag/config. + + See + + swaynag + 5 + + for a list of avaliable options and an example configuration. + Note, configurations declared under <config> + will override the default type values of swaynag. + ''; + example = literalExpression '' + { + "" = { + edge = "bottom"; + font = "Dina 12"; + }; + + green = { + edge = "top"; + background = "00AA00"; + text = "FFFFFF"; + button-background = "00CC00"; + message-padding = 10; + }; + } + ''; + }; + }; + }; + + config = mkIf cfg.enable { + assertions = [ + (hm.assertions.assertPlatform "wayland.windowManager.sway.swaynag" pkgs + platforms.linux) + ]; + + xdg.configFile."swaynag/config" = mkIf (cfg.settings != { }) { + source = iniFormat.generate "swaynag.conf" cfg.settings; + }; + }; +} diff --git a/tests/modules/services/window-managers/sway/default.nix b/tests/modules/services/window-managers/sway/default.nix index 9ee47987..6ad673b1 100644 --- a/tests/modules/services/window-managers/sway/default.nix +++ b/tests/modules/services/window-managers/sway/default.nix @@ -10,4 +10,6 @@ sway-post-2003 = ./sway-post-2003.nix; sway-workspace-default = ./sway-workspace-default.nix; sway-workspace-output = ./sway-workspace-output.nix; + swaynag-example-settings = ./swaynag-example-settings.nix; + swaynag-empty-settings = ./swaynag-empty-settings.nix; } diff --git a/tests/modules/services/window-managers/sway/swaynag-empty-settings.nix b/tests/modules/services/window-managers/sway/swaynag-empty-settings.nix new file mode 100644 index 00000000..0180852a --- /dev/null +++ b/tests/modules/services/window-managers/sway/swaynag-empty-settings.nix @@ -0,0 +1,15 @@ +{ config, lib, pkgs, ... }: + +{ + config = { + wayland.windowManager.sway.swaynag = { + enable = true; + + settings = { }; + }; + + nmt.script = '' + assertPathNotExists home-files/.config/swaynag + ''; + }; +} diff --git a/tests/modules/services/window-managers/sway/swaynag-example-settings-expected.conf b/tests/modules/services/window-managers/sway/swaynag-example-settings-expected.conf new file mode 100644 index 00000000..4e0f5d5e --- /dev/null +++ b/tests/modules/services/window-managers/sway/swaynag-example-settings-expected.conf @@ -0,0 +1,10 @@ +[] +edge=bottom +font=Dina 12 + +[green] +background=00AA00 +button-background=00CC00 +edge=top +message-padding=10 +text=FFFFFF diff --git a/tests/modules/services/window-managers/sway/swaynag-example-settings.nix b/tests/modules/services/window-managers/sway/swaynag-example-settings.nix new file mode 100644 index 00000000..513d185d --- /dev/null +++ b/tests/modules/services/window-managers/sway/swaynag-example-settings.nix @@ -0,0 +1,30 @@ +{ config, lib, pkgs, ... }: + +{ + config = { + wayland.windowManager.sway.swaynag = { + enable = true; + + settings = { + "" = { + edge = "bottom"; + font = "Dina 12"; + }; + + green = { + edge = "top"; + background = "00AA00"; + text = "FFFFFF"; + button-background = "00CC00"; + message-padding = 10; + }; + }; + }; + + nmt.script = '' + assertFileContent \ + home-files/.config/swaynag/config \ + ${./swaynag-example-settings-expected.conf} + ''; + }; +}