nix: modernize
This commit is contained in:
parent
514eb6617e
commit
0e6979f684
5 changed files with 48 additions and 39 deletions
|
@ -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"];
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
Reference in a new issue