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 + '' + } + ''; +}