2025-01-08 08:08:07 +00:00
|
|
|
self: {
|
2024-01-11 20:43:27 +00:00
|
|
|
config,
|
|
|
|
pkgs,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}: let
|
2025-01-08 08:08:07 +00:00
|
|
|
inherit (lib.modules) mkIf mkForce;
|
2024-01-11 20:43:27 +00:00
|
|
|
inherit (lib.options) mkOption mkEnableOption;
|
2025-01-08 08:08:07 +00:00
|
|
|
inherit (lib) types;
|
2024-01-11 20:43:27 +00:00
|
|
|
|
2025-01-08 08:08:07 +00:00
|
|
|
format = pkgs.formats.json {};
|
2024-01-11 20:43:27 +00:00
|
|
|
cfg = config.services.batmon;
|
|
|
|
in {
|
|
|
|
options.services.batmon = {
|
|
|
|
enable = mkEnableOption "batmon for real-time battery monitoring";
|
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
description = "The batmon package to use";
|
|
|
|
type = types.package;
|
|
|
|
default = self.packages.${pkgs.stdenv.hostPlatform.system}.batmon;
|
|
|
|
};
|
|
|
|
|
|
|
|
settings = mkOption {
|
2025-01-08 08:08:07 +00:00
|
|
|
type = format.type;
|
2024-01-11 20:43:27 +00:00
|
|
|
default = {};
|
2025-01-08 08:08:07 +00:00
|
|
|
example = {
|
|
|
|
batPaths = [
|
|
|
|
{
|
|
|
|
path = "/sys/class/power_supply/BAT0";
|
|
|
|
extraCommand = "notify-send 'State changed!'";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
description = "Settings for BatmoSettings for Batmonn";
|
2024-01-11 20:43:27 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
systemd.user.services."batmon" = {
|
|
|
|
description = "Power Monitoring Service";
|
2025-01-08 08:08:07 +00:00
|
|
|
wants = ["power-profiles-daemon.service"];
|
|
|
|
wantedBy = ["default.target"];
|
2024-01-11 20:43:27 +00:00
|
|
|
environment.PATH = mkForce "/run/wrappers/bin:${lib.makeBinPath cfg.package}";
|
|
|
|
script = ''
|
|
|
|
${lib.getExe cfg.package} --config ${builtins.toJSON cfg.settings}
|
|
|
|
'';
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "simple";
|
|
|
|
Restart = "on-failure";
|
2025-01-08 08:08:07 +00:00
|
|
|
DynamicUser = true;
|
2024-01-11 20:43:27 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|