From f4f9f1a618eb7c19b765b02c235e13657b5aa150 Mon Sep 17 00:00:00 2001 From: Nicolas Berbiche Date: Wed, 29 Jul 2020 16:29:51 -0400 Subject: waybar: add module PR #1329 --- tests/default.nix | 1 + tests/modules/programs/waybar/broken-settings.nix | 80 ++++++++++++++++++++++ tests/modules/programs/waybar/default.nix | 8 +++ .../programs/waybar/settings-complex-expected.json | 46 +++++++++++++ tests/modules/programs/waybar/settings-complex.nix | 59 ++++++++++++++++ tests/modules/programs/waybar/styling-expected.css | 23 +++++++ tests/modules/programs/waybar/styling.nix | 46 +++++++++++++ .../systemd-with-graphical-session-target.nix | 24 +++++++ .../systemd-with-graphical-session-target.service | 16 +++++ 9 files changed, 303 insertions(+) create mode 100644 tests/modules/programs/waybar/broken-settings.nix create mode 100644 tests/modules/programs/waybar/default.nix create mode 100644 tests/modules/programs/waybar/settings-complex-expected.json create mode 100644 tests/modules/programs/waybar/settings-complex.nix create mode 100644 tests/modules/programs/waybar/styling-expected.css create mode 100644 tests/modules/programs/waybar/styling.nix create mode 100644 tests/modules/programs/waybar/systemd-with-graphical-session-target.nix create mode 100644 tests/modules/programs/waybar/systemd-with-graphical-session-target.service (limited to 'tests') diff --git a/tests/default.nix b/tests/default.nix index 53c221bcf69..939a50e2d83 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -82,6 +82,7 @@ import nmt { ./modules/programs/getmail ./modules/services/lieer ./modules/programs/rofi + ./modules/programs/waybar ./modules/services/polybar ./modules/services/sxhkd ./modules/services/fluidsynth diff --git a/tests/modules/programs/waybar/broken-settings.nix b/tests/modules/programs/waybar/broken-settings.nix new file mode 100644 index 00000000000..68f0b90bfca --- /dev/null +++ b/tests/modules/programs/waybar/broken-settings.nix @@ -0,0 +1,80 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + package = pkgs.writeScriptBin "dummy-waybar" "" // { outPath = "@waybar@"; }; + expected = pkgs.writeText "expected-json" '' + [ + { + "height": 26, + "layer": "top", + "modules-center": [ + "sway/window" + ], + "modules-left": [ + "sway/workspaces", + "sway/mode" + ], + "modules-right": [ + "idle_inhibitor", + "pulseaudio", + "network", + "cpu", + "memory", + "backlight", + "tray", + "clock" + ], + "output": [ + "DP-1", + "eDP-1", + "HEADLESS-1" + ], + "position": "top", + "sway/workspaces": { + "all-outputs": true + } + } + ] + ''; +in { + config = { + programs.waybar = { + inherit package; + enable = true; + systemd.enable = true; + settings = [{ + layer = "top"; + position = "top"; + height = 26; + output = [ "DP-1" "eDP-1" "HEADLESS-1" ]; + modules-left = [ "sway/workspaces" "sway/mode" ]; + modules-center = [ "sway/window" ]; + modules-right = [ + "idle_inhibitor" + "pulseaudio" + "network" + "cpu" + "memory" + "backlight" + "tray" + "clock" + ]; + + modules = { "sway/workspaces".all-outputs = true; }; + }]; + }; + + nmt.description = '' + Test for the broken configuration + https://github.com/rycee/home-manager/pull/1329#issuecomment-653253069 + ''; + nmt.script = '' + assertPathNotExists home-files/.config/waybar/style.css + assertFileContent \ + home-files/.config/waybar/config \ + ${expected} + ''; + }; +} diff --git a/tests/modules/programs/waybar/default.nix b/tests/modules/programs/waybar/default.nix new file mode 100644 index 00000000000..d50b1b8d368 --- /dev/null +++ b/tests/modules/programs/waybar/default.nix @@ -0,0 +1,8 @@ +{ + waybar-systemd-with-graphical-session-target = + ./systemd-with-graphical-session-target.nix; + waybar-styling = ./styling.nix; + waybar-settings-complex = ./settings-complex.nix; + # Broken configuration from https://github.com/rycee/home-manager/pull/1329#issuecomment-653253069 + waybar-broken-settings = ./broken-settings.nix; +} diff --git a/tests/modules/programs/waybar/settings-complex-expected.json b/tests/modules/programs/waybar/settings-complex-expected.json new file mode 100644 index 00000000000..0d020c19c97 --- /dev/null +++ b/tests/modules/programs/waybar/settings-complex-expected.json @@ -0,0 +1,46 @@ +[ + { + "custom/my-module": { + "exec": "@dummy@/bin/dummy", + "format": "hello from {}" + }, + "height": 30, + "idle_inhibitor": { + "format": "{icon}" + }, + "layer": "top", + "modules-center": [ + "sway/window" + ], + "modules-left": [ + "sway/workspaces", + "sway/mode", + "custom/my-module" + ], + "modules-right": [ + "idle_inhibitor", + "pulseaudio", + "network", + "cpu", + "memory", + "backlight", + "tray", + "battery", + "clock" + ], + "output": [ + "DP-1" + ], + "position": "top", + "sway/mode": { + "tooltip": false + }, + "sway/window": { + "max-length": 120 + }, + "sway/workspaces": { + "all-outputs": true, + "disable-scroll": true + } + } +] diff --git a/tests/modules/programs/waybar/settings-complex.nix b/tests/modules/programs/waybar/settings-complex.nix new file mode 100644 index 00000000000..750e52f4581 --- /dev/null +++ b/tests/modules/programs/waybar/settings-complex.nix @@ -0,0 +1,59 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + package = pkgs.writeScriptBin "dummy-waybar" "" // { outPath = "@waybar@"; }; +in { + config = { + programs.waybar = { + inherit package; + enable = true; + settings = [{ + layer = "top"; + position = "top"; + height = 30; + output = [ "DP-1" ]; + modules-left = [ "sway/workspaces" "sway/mode" "custom/my-module" ]; + modules-center = [ "sway/window" ]; + modules-right = [ + "idle_inhibitor" + "pulseaudio" + "network" + "cpu" + "memory" + "backlight" + "tray" + "battery" + "clock" + ]; + + modules = { + "sway/workspaces" = { + disable-scroll = true; + all-outputs = true; + }; + "sway/mode" = { tooltip = false; }; + "sway/window" = { max-length = 120; }; + "idle_inhibitor" = { format = "{icon}"; }; + "custom/my-module" = { + format = "hello from {}"; + exec = let + dummyScript = + pkgs.writeShellScriptBin "dummy" "echo within waybar" // { + outPath = "@dummy@"; + }; + in "${dummyScript}/bin/dummy"; + }; + }; + }]; + }; + + nmt.script = '' + assertPathNotExists home-files/.config/waybar/style.css + assertFileContent \ + home-files/.config/waybar/config \ + ${./settings-complex-expected.json} + ''; + }; +} diff --git a/tests/modules/programs/waybar/styling-expected.css b/tests/modules/programs/waybar/styling-expected.css new file mode 100644 index 00000000000..dc779e58770 --- /dev/null +++ b/tests/modules/programs/waybar/styling-expected.css @@ -0,0 +1,23 @@ +* { + border: none; + border-radius: 0; + font-family: Source Code Pro; + font-weight: bold; + color: #abb2bf; + font-size: 18px; + min-height: 0px; +} +window#waybar { + background: #16191C; + color: #aab2bf; +} +#window { + padding: 0 0px; +} +#workspaces button:hover { + box-shadow: inherit; + text-shadow: inherit; + background: #16191C; + border: #16191C; + padding: 0 3px; +} diff --git a/tests/modules/programs/waybar/styling.nix b/tests/modules/programs/waybar/styling.nix new file mode 100644 index 00000000000..bd73f2aafd2 --- /dev/null +++ b/tests/modules/programs/waybar/styling.nix @@ -0,0 +1,46 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + package = pkgs.writeScriptBin "dummy-waybar" "" // { outPath = "@waybar@"; }; +in { + config = { + programs.waybar = { + inherit package; + 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#waybar { + background: #16191C; + color: #aab2bf; + } + #window { + padding: 0 0px; + } + #workspaces button:hover { + box-shadow: inherit; + text-shadow: inherit; + background: #16191C; + border: #16191C; + padding: 0 3px; + } + ''; + }; + + nmt.script = '' + assertPathNotExists home-files/.config/waybar/config + assertFileContent \ + home-files/.config/waybar/style.css \ + ${./styling-expected.css} + ''; + }; +} diff --git a/tests/modules/programs/waybar/systemd-with-graphical-session-target.nix b/tests/modules/programs/waybar/systemd-with-graphical-session-target.nix new file mode 100644 index 00000000000..e751d804dab --- /dev/null +++ b/tests/modules/programs/waybar/systemd-with-graphical-session-target.nix @@ -0,0 +1,24 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + package = pkgs.writeScriptBin "dummy-waybar" "" // { outPath = "@waybar@"; }; +in { + config = { + programs.waybar = { + inherit package; + enable = true; + systemd.enable = true; + }; + + nmt.script = '' + assertPathNotExists home-files/.config/waybar/config + assertPathNotExists home-files/.config/waybar/style.css + + assertFileContent \ + home-files/.config/systemd/user/waybar.service \ + ${./systemd-with-graphical-session-target.service} + ''; + }; +} diff --git a/tests/modules/programs/waybar/systemd-with-graphical-session-target.service b/tests/modules/programs/waybar/systemd-with-graphical-session-target.service new file mode 100644 index 00000000000..7d4c65214e8 --- /dev/null +++ b/tests/modules/programs/waybar/systemd-with-graphical-session-target.service @@ -0,0 +1,16 @@ +[Install] +WantedBy=graphical-session.target + +[Service] +BusName=fr.arouillard.waybar +ExecStart=@waybar@/bin/waybar +Restart=always +RestartSec=1sec +Type=dbus + +[Unit] +After=dbus.service +Description=Highly customizable Wayland bar for Sway and Wlroots based compositors. +Documentation=https://github.com/Alexays/Waybar/wiki +PartOf=graphical-session.target +Requisite=dbus.service -- cgit v1.2.3