From 5514ed321087f0b5af42564352d135acad4ff055 Mon Sep 17 00:00:00 2001 From: Akiyoshi Suda Date: Tue, 25 Oct 2022 21:31:46 +0900 Subject: [PATCH] yambar: add module --- modules/misc/news.nix | 14 +++++ modules/modules.nix | 1 + modules/programs/yambar.nix | 55 +++++++++++++++++++ tests/default.nix | 1 + tests/modules/programs/yambar/default.nix | 4 ++ .../programs/yambar/empty-settings.nix | 11 ++++ .../yambar/example-settings-expected.yml | 9 +++ .../programs/yambar/example-settings.nix | 35 ++++++++++++ 8 files changed, 130 insertions(+) create mode 100644 modules/programs/yambar.nix create mode 100644 tests/modules/programs/yambar/default.nix create mode 100644 tests/modules/programs/yambar/empty-settings.nix create mode 100644 tests/modules/programs/yambar/example-settings-expected.yml create mode 100644 tests/modules/programs/yambar/example-settings.nix diff --git a/modules/misc/news.nix b/modules/misc/news.nix index b83d0858..2164d66a 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1642,6 +1642,20 @@ in { https://github.com/hyprwm/hyprpaper for more. ''; } + + { + time = "2024-05-10T21:28:38+00:00"; + condition = hostPlatform.isLinux; + message = '' + A new module is available: 'programs.yambar'. + + Yambar is a lightweight and configurable status panel for X11 and + Wayland, that goes to great lengths to be both CPU and battery + efficient - polling is only done when absolutely necessary. + + See https://codeberg.org/dnkl/yambar for more. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index e1b08087..4e1f0e20 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -254,6 +254,7 @@ let ./programs/wpaperd.nix ./programs/xmobar.nix ./programs/xplr.nix + ./programs/yambar.nix ./programs/yazi.nix ./programs/yt-dlp.nix ./programs/z-lua.nix diff --git a/modules/programs/yambar.nix b/modules/programs/yambar.nix new file mode 100644 index 00000000..f4e0a434 --- /dev/null +++ b/modules/programs/yambar.nix @@ -0,0 +1,55 @@ +{ config, lib, pkgs, ... }: + +let + + cfg = config.programs.yambar; + yamlFormat = pkgs.formats.yaml { }; + +in { + meta.maintainers = [ lib.maintainers.carpinchomug ]; + + options.programs.yambar = { + enable = lib.mkEnableOption "Yambar"; + + package = lib.mkPackageOption pkgs "yambar" { }; + + settings = lib.mkOption { + type = yamlFormat.type; + default = { }; + example = lib.literalExpression '' + bar = { + location = "top"; + height = 26; + background = "00000066"; + + right = [ + { + clock.content = [ + { + string.text = "{time}"; + } + ]; + } + ]; + }; + ''; + description = '' + Configuration written to {file}`$XDG_CONFIG_HOME/yambar/config.yml`. + See {manpage}`yambar(5)` for options. + ''; + }; + }; + + config = lib.mkIf cfg.enable { + assertions = [ + (lib.hm.assertions.assertPlatform "programs.yambar" pkgs + lib.platforms.linux) + ]; + + home.packages = [ cfg.package ]; + + xdg.configFile."yambar/config.yml" = lib.mkIf (cfg.settings != { }) { + source = yamlFormat.generate "config.yml" cfg.settings; + }; + }; +} diff --git a/tests/default.nix b/tests/default.nix index 3b52ff40..4d8d49d4 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -219,6 +219,7 @@ in import nmtSrc { ./modules/programs/wofi ./modules/programs/wpaperd ./modules/programs/xmobar + ./modules/programs/yambar ./modules/programs/yt-dlp ./modules/services/activitywatch ./modules/services/avizo diff --git a/tests/modules/programs/yambar/default.nix b/tests/modules/programs/yambar/default.nix new file mode 100644 index 00000000..26de5673 --- /dev/null +++ b/tests/modules/programs/yambar/default.nix @@ -0,0 +1,4 @@ +{ + yambar-empty-settings = ./empty-settings.nix; + yambar-example-settings = ./example-settings.nix; +} diff --git a/tests/modules/programs/yambar/empty-settings.nix b/tests/modules/programs/yambar/empty-settings.nix new file mode 100644 index 00000000..56cdf27d --- /dev/null +++ b/tests/modules/programs/yambar/empty-settings.nix @@ -0,0 +1,11 @@ +{ ... }: + +{ + programs.yambar.enable = true; + + test.stubs.yambar = { }; + + nmt.script = '' + assertPathNotExists home-files/.config/yambar + ''; +} diff --git a/tests/modules/programs/yambar/example-settings-expected.yml b/tests/modules/programs/yambar/example-settings-expected.yml new file mode 100644 index 00000000..0bd9120a --- /dev/null +++ b/tests/modules/programs/yambar/example-settings-expected.yml @@ -0,0 +1,9 @@ +bar: + background: '00000066' + height: 26 + location: top + right: + - clock: + content: + - string: + text: '{time}' diff --git a/tests/modules/programs/yambar/example-settings.nix b/tests/modules/programs/yambar/example-settings.nix new file mode 100644 index 00000000..de572090 --- /dev/null +++ b/tests/modules/programs/yambar/example-settings.nix @@ -0,0 +1,35 @@ +{ config, ... }: + +{ + programs.yambar = { + enable = true; + package = config.lib.test.mkStubPackage { }; + + settings = { + bar = { + location = "top"; + height = 26; + background = "00000066"; + right = [{ clock.content = [{ string.text = "{time}"; }]; }]; + }; + }; + }; + + nmt.script = '' + assertFileContent \ + home-files/.config/yambar/config.yml \ + ${ + builtins.toFile "yambar-expected.yml" '' + bar: + background: '00000066' + height: 26 + location: top + right: + - clock: + content: + - string: + text: '{time}' + '' + } + ''; +}