1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-11-08 11:36:05 +01:00
home-manager/modules/services/poweralertd.nix
Austin Horstman 03fdb31290
treewide: add missing package options (#7575)
Add options to support more flexible module configurations.

Signed-off-by: Austin Horstman <khaneliman12@gmail.com>
2025-07-29 12:20:22 -05:00

71 lines
1.7 KiB
Nix

{
config,
lib,
pkgs,
...
}:
let
inherit (lib) types;
inherit (lib.strings) toJSON;
cfg = config.services.poweralertd;
escapeSystemdExecArg =
arg:
let
s =
if lib.isPath arg then
"${arg}"
else if lib.isString arg then
arg
else if lib.isInt arg || lib.isFloat arg || lib.isDerivation arg then
toString arg
else
throw "escapeSystemdExecArg only allows strings, paths, numbers and derivations";
in
lib.replaceStrings [ "%" "$" ] [ "%%" "$$" ] (toJSON s);
escapeSystemdExecArgs = lib.concatMapStringsSep " " escapeSystemdExecArg;
in
{
meta.maintainers = [ lib.maintainers.thibautmarty ];
options.services.poweralertd = {
enable = lib.mkEnableOption "the Upower-powered power alertd";
package = lib.mkPackageOption pkgs "poweralertd" { };
extraArgs = lib.mkOption {
type = with types; listOf str;
default = [ ];
example = [
"-s"
"-S"
];
description = ''
Extra command line arguments to pass to poweralertd.
'';
};
};
config = lib.mkIf cfg.enable {
assertions = [
(lib.hm.assertions.assertPlatform "services.poweralertd" pkgs lib.platforms.linux)
];
systemd.user.services.poweralertd = {
Unit = {
Description = "UPower-powered power alerter";
Documentation = "man:poweralertd(1)";
After = [ "graphical-session.target" ];
PartOf = [ "graphical-session.target" ];
};
Install.WantedBy = [ "graphical-session.target" ];
Service = {
Type = "simple";
ExecStart = "${lib.getExe cfg.package} ${escapeSystemdExecArgs cfg.extraArgs}";
Restart = "always";
};
};
};
}