nix: modernize

This commit is contained in:
raf 2025-01-08 11:08:07 +03:00
commit 0e6979f684
No known key found for this signature in database
GPG key ID: EED98D11B85A2819
5 changed files with 48 additions and 39 deletions

View file

@ -1,13 +1,14 @@
{
self,
self: {
config,
pkgs,
lib,
...
}: let
inherit (lib) mkIf mkForce types;
inherit (lib.modules) mkIf mkForce;
inherit (lib.options) mkOption mkEnableOption;
inherit (lib) types;
format = pkgs.formats.json {};
cfg = config.services.batmon;
in {
options.services.batmon = {
@ -20,25 +21,26 @@ in {
};
settings = mkOption {
description = "Settings for Batmon";
type = types.attrs;
type = format.type;
default = {};
example = lib.literalExpression ''
{
batPaths = [
{
path = "/sys/class/power_supply/BAT0";
extraCommand = "notify-send 'State changed!'";
}
];
}
'';
example = {
batPaths = [
{
path = "/sys/class/power_supply/BAT0";
extraCommand = "notify-send 'State changed!'";
}
];
};
description = "Settings for BatmoSettings for Batmonn";
};
};
config = mkIf cfg.enable {
systemd.user.services."batmon" = {
description = "Power Monitoring Service";
wants = ["power-profiles-daemon.service"];
wantedBy = ["default.target"];
environment.PATH = mkForce "/run/wrappers/bin:${lib.makeBinPath cfg.package}";
script = ''
${lib.getExe cfg.package} --config ${builtins.toJSON cfg.settings}
@ -47,10 +49,8 @@ in {
serviceConfig = {
Type = "simple";
Restart = "on-failure";
DynamicUser = true;
};
wants = ["power-profiles-daemon.service"];
wantedBy = ["default.target"];
};
};
}