2019-12-29 11:26:24 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.cbatticon;
|
|
|
|
|
|
|
|
package = pkgs.cbatticon;
|
|
|
|
|
|
|
|
makeCommand = commandName: commandArg:
|
2020-02-02 00:39:17 +01:00
|
|
|
optional (commandArg != null)
|
|
|
|
(let cmd = pkgs.writeShellScript commandName commandArg;
|
|
|
|
in "--${commandName} ${cmd}");
|
|
|
|
|
|
|
|
commandLine = concatStringsSep " " ([ "${package}/bin/cbatticon" ]
|
2019-12-29 11:26:24 +01:00
|
|
|
++ makeCommand "command-critical-level" cfg.commandCriticalLevel
|
|
|
|
++ makeCommand "command-left-click" cfg.commandLeftClick
|
2020-02-02 00:39:17 +01:00
|
|
|
++ optional (cfg.iconType != null) "--icon-type ${cfg.iconType}"
|
|
|
|
++ optional (cfg.lowLevelPercent != null)
|
|
|
|
"--low-level ${toString cfg.lowLevelPercent}"
|
|
|
|
++ optional (cfg.criticalLevelPercent != null)
|
|
|
|
"--critical-level ${toString cfg.criticalLevelPercent}"
|
|
|
|
++ optional (cfg.updateIntervalSeconds != null)
|
|
|
|
"--update-interval ${toString cfg.updateIntervalSeconds}"
|
|
|
|
++ optional (cfg.hideNotification != null && cfg.hideNotification)
|
|
|
|
"--hide-notification");
|
|
|
|
|
|
|
|
in {
|
2019-12-29 11:26:24 +01:00
|
|
|
meta.maintainers = [ maintainers.pmiddend ];
|
|
|
|
|
|
|
|
options = {
|
|
|
|
services.cbatticon = {
|
|
|
|
enable = mkEnableOption "cbatticon";
|
|
|
|
|
|
|
|
commandCriticalLevel = mkOption {
|
|
|
|
type = types.nullOr types.lines;
|
|
|
|
default = null;
|
|
|
|
example = ''
|
|
|
|
notify-send "battery critical!"
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Command to execute when the critical battery level is reached.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
commandLeftClick = mkOption {
|
|
|
|
type = types.nullOr types.lines;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
Command to execute when left clicking on the tray icon.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
iconType = mkOption {
|
2020-02-02 00:39:17 +01:00
|
|
|
type =
|
|
|
|
types.nullOr (types.enum [ "standard" "notification" "symbolic" ]);
|
2019-12-29 11:26:24 +01:00
|
|
|
default = null;
|
|
|
|
example = "symbolic";
|
|
|
|
description = "Icon type to display in the system tray.";
|
|
|
|
};
|
|
|
|
|
|
|
|
lowLevelPercent = mkOption {
|
|
|
|
type = types.nullOr (types.ints.between 0 100);
|
|
|
|
default = null;
|
|
|
|
example = 20;
|
|
|
|
description = ''
|
|
|
|
Low level percentage of the battery in percent (without the
|
|
|
|
percent symbol).
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
criticalLevelPercent = mkOption {
|
|
|
|
type = types.nullOr (types.ints.between 0 100);
|
|
|
|
default = null;
|
|
|
|
example = 5;
|
|
|
|
description = ''
|
|
|
|
Critical level percentage of the battery in percent (without
|
|
|
|
the percent symbol).
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
updateIntervalSeconds = mkOption {
|
|
|
|
type = types.nullOr types.ints.positive;
|
|
|
|
default = null;
|
|
|
|
example = 5;
|
|
|
|
description = ''
|
|
|
|
Number of seconds between updates of the battery information.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
hideNotification = mkOption {
|
|
|
|
type = types.nullOr types.bool;
|
|
|
|
default = null;
|
|
|
|
description = "Hide the notification popups.";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2021-07-07 23:24:27 +02:00
|
|
|
assertions = [
|
|
|
|
(lib.hm.assertions.assertPlatform "services.cbatticon" pkgs
|
|
|
|
lib.platforms.linux)
|
|
|
|
];
|
|
|
|
|
2019-12-29 11:26:24 +01:00
|
|
|
home.packages = [ package ];
|
|
|
|
|
|
|
|
systemd.user.services.cbatticon = {
|
|
|
|
Unit = {
|
|
|
|
Description = "cbatticon system tray battery icon";
|
2021-05-22 04:15:12 +02:00
|
|
|
Requires = [ "tray.target" ];
|
|
|
|
After = [ "graphical-session-pre.target" "tray.target" ];
|
2019-12-29 11:26:24 +01:00
|
|
|
PartOf = [ "graphical-session.target" ];
|
|
|
|
};
|
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
Install = { WantedBy = [ "graphical-session.target" ]; };
|
2019-12-29 11:26:24 +01:00
|
|
|
|
|
|
|
Service = {
|
|
|
|
ExecStart = commandLine;
|
|
|
|
Restart = "on-abort";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|