From fa980cc98529111c7aad713574d307e9b4f3e5ed Mon Sep 17 00:00:00 2001 From: Ilan Joselevich Date: Mon, 20 Mar 2023 01:06:39 +0200 Subject: [PATCH] batsignal: add module --- .github/CODEOWNERS | 2 ++ modules/misc/news.nix | 8 ++++++ modules/modules.nix | 1 + modules/services/batsignal.nix | 50 ++++++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+) create mode 100644 modules/services/batsignal.nix diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index faa4a31f..4ad9b375 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -376,6 +376,8 @@ Makefile @thiagokokada /modules/services/barrier.nix @Kritnich /tests/modules/services/barrier @Kritnich +/modules/services/batsignal.nix @Kranzes + /modules/services/betterlockscreen.nix @SebTM /modules/programs/borgmatic.nix @DamienCassou diff --git a/modules/misc/news.nix b/modules/misc/news.nix index c3335fcb..c2bbedd4 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -979,6 +979,14 @@ in A new module is available: 'programs.hstr'. ''; } + + { + time = "2023-04-18T06:28:31+00:00"; + condition = hostPlatform.isLinux; + message = '' + A new module is available: 'services.batsignal'. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index 0e60bb59..a6312bfd 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -208,6 +208,7 @@ let ./services/autorandr.nix ./services/avizo.nix ./services/barrier.nix + ./services/batsignal.nix ./services/betterlockscreen.nix ./services/blueman-applet.nix ./services/borgmatic.nix diff --git a/modules/services/batsignal.nix b/modules/services/batsignal.nix new file mode 100644 index 00000000..4f209f1e --- /dev/null +++ b/modules/services/batsignal.nix @@ -0,0 +1,50 @@ +{ config, lib, pkgs, ... }: + +let + + cfg = config.services.batsignal; + +in { + meta.maintainers = with lib.maintainers; [ kranzes ]; + + options = { + services.batsignal = { + enable = lib.mkEnableOption "Batsignal Battery Daemon"; + + package = lib.mkPackageOption pkgs "batsignal" { }; + + extraArgs = lib.mkOption { + type = with lib.types; listOf str; + default = [ ]; + description = '' + Extra arguments to be passed to the batsignal executable. + ''; + }; + }; + }; + + config = lib.mkIf cfg.enable { + assertions = [ + (lib.hm.assertions.assertPlatform "services.batsignal" pkgs + lib.platforms.linux) + ]; + + systemd.user.services.batsignal = { + Unit = { + Description = "batsignal - battery monitor daemon"; + After = [ "graphical-session-pre.target" ]; + PartOf = [ "graphical-session.target" ]; + }; + + Service = { + Type = "simple"; + ExecStart = + "${lib.getExe cfg.package} ${lib.escapeShellArgs cfg.extraArgs}"; + Restart = "on-failure"; + RestartSec = 1; + }; + + Install.WantedBy = [ "graphical-session.target" ]; + }; + }; +}