From 98282a481df50d357e9cbfa7e6a6d481df37e8c2 Mon Sep 17 00:00:00 2001 From: Anton Plotnikov Date: Fri, 7 Jul 2023 10:15:43 +0200 Subject: [PATCH] swayosd: add module --- modules/misc/news.nix | 8 +++ modules/modules.nix | 1 + modules/services/swayosd.nix | 58 ++++++++++++++++++++++ tests/default.nix | 1 + tests/modules/services/swayosd/default.nix | 1 + tests/modules/services/swayosd/swayosd.nix | 35 +++++++++++++ 6 files changed, 104 insertions(+) create mode 100644 modules/services/swayosd.nix create mode 100644 tests/modules/services/swayosd/default.nix create mode 100644 tests/modules/services/swayosd/swayosd.nix diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 4b432dfa..6d8a4003 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1157,6 +1157,14 @@ in A new module is available: 'programs.pyenv'. ''; } + + { + time = "2023-07-08T09:44:56+00:00"; + condition = hostPlatform.isLinux; + message = '' + A new module is available: 'services.swayosd' + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index 8822eeed..a77b75e6 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -312,6 +312,7 @@ let ./services/stalonetray.nix ./services/status-notifier-watcher.nix ./services/swayidle.nix + ./services/swayosd.nix ./services/sxhkd.nix ./services/syncthing.nix ./services/systembus-notify.nix diff --git a/modules/services/swayosd.nix b/modules/services/swayosd.nix new file mode 100644 index 00000000..067c104c --- /dev/null +++ b/modules/services/swayosd.nix @@ -0,0 +1,58 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.services.swayosd; + +in { + meta.maintainers = [ hm.maintainers.pltanton ]; + + options.services.swayosd = { + enable = mkEnableOption '' + swayosd, a GTK based on screen display for keyboard shortcuts like + caps-lock and volume''; + + package = mkPackageOption pkgs "swayosd" { }; + + maxVolume = mkOption { + type = types.nullOr types.ints.unsigned; + default = null; + example = 120; + description = '' + Sets the maximum volume. + ''; + }; + }; + + config = mkIf cfg.enable { + assertions = [ + (hm.assertions.assertPlatform "services.swayosd" pkgs platforms.linux) + ]; + + home.packages = [ cfg.package ]; + + systemd.user = { + services.swayosd = { + Unit = { + Description = "Volume/backlight OSD indicator"; + PartOf = [ "graphical-session.target" ]; + After = [ "graphical-session.target" ]; + ConditionEnvironment = "WAYLAND_DISPLAY"; + Documentation = "man:swayosd(1)"; + }; + + Service = { + Type = "simple"; + ExecStart = "${cfg.package}/bin/swayosd" + + (optionalString (cfg.maxVolume != null) + " --max-volume ${toString cfg.maxVolume}"); + Restart = "always"; + }; + + Install = { WantedBy = [ "graphical-session.target" ]; }; + }; + }; + }; +} diff --git a/tests/default.nix b/tests/default.nix index c21b4b7e..2fe30989 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -222,6 +222,7 @@ import nmt { ./modules/services/redshift-gammastep ./modules/services/screen-locker ./modules/services/swayidle + ./modules/services/swayosd ./modules/services/sxhkd ./modules/services/syncthing/linux ./modules/services/trayer diff --git a/tests/modules/services/swayosd/default.nix b/tests/modules/services/swayosd/default.nix new file mode 100644 index 00000000..c327610a --- /dev/null +++ b/tests/modules/services/swayosd/default.nix @@ -0,0 +1 @@ +{ swayosd = ./swayosd.nix; } diff --git a/tests/modules/services/swayosd/swayosd.nix b/tests/modules/services/swayosd/swayosd.nix new file mode 100644 index 00000000..b371d86a --- /dev/null +++ b/tests/modules/services/swayosd/swayosd.nix @@ -0,0 +1,35 @@ +{ config, ... }: + +{ + services.swayosd = { + enable = true; + package = config.lib.test.mkStubPackage { + name = "swayosd"; + outPath = "@swayosd@"; + }; + maxVolume = 10; + }; + + nmt.script = '' + assertFileContent \ + home-files/.config/systemd/user/swayosd.service \ + ${ + builtins.toFile "swayosd.service" '' + [Install] + WantedBy=graphical-session.target + + [Service] + ExecStart=@swayosd@/bin/swayosd --max-volume 10 + Restart=always + Type=simple + + [Unit] + After=graphical-session.target + ConditionEnvironment=WAYLAND_DISPLAY + Description=Volume/backlight OSD indicator + Documentation=man:swayosd(1) + PartOf=graphical-session.target + '' + } + ''; +}