57 lines
1.8 KiB
Nix
57 lines
1.8 KiB
Nix
{ config, lib, pkgs, ... }:
|
|
let
|
|
cfg = config.programs.ai-usage;
|
|
in {
|
|
options.programs.ai-usage = {
|
|
enable = lib.mkEnableOption "AI Usage Monitor for Waybar";
|
|
package = lib.mkOption {
|
|
type = lib.types.package;
|
|
description = "ai-usage package from this flake.";
|
|
};
|
|
};
|
|
|
|
config = lib.mkIf cfg.enable (lib.mkMerge [
|
|
{
|
|
home.packages = [ cfg.package ];
|
|
|
|
systemd.user.services.ai-usage = {
|
|
Unit = {
|
|
Description = "AI Usage Monitor";
|
|
PartOf = [ "graphical-session.target" ];
|
|
After = [ "graphical-session.target" ];
|
|
};
|
|
Service = {
|
|
ExecStart = "${lib.getExe cfg.package} daemon";
|
|
Restart = "on-failure";
|
|
RestartSec = 2;
|
|
Environment = [
|
|
"DBUS_SESSION_BUS_ADDRESS=unix:path=%t/bus"
|
|
"SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt"
|
|
"PATH=${lib.makeBinPath [ pkgs.sqlite ]}:%h/.local/bin:%h/.nix-profile/bin:/etc/profiles/per-user/%u/bin:/run/current-system/sw/bin"
|
|
];
|
|
};
|
|
Install.WantedBy = [ "graphical-session.target" ];
|
|
};
|
|
}
|
|
(lib.mkIf config.programs.waybar.enable {
|
|
programs.waybar.settings.mainBar = {
|
|
"custom/ai-usage" = {
|
|
exec = "${lib.getExe cfg.package} waybar";
|
|
return-type = "json";
|
|
interval = 60;
|
|
signal = 1;
|
|
on-click = "${lib.getExe cfg.package} refresh";
|
|
tooltip = true;
|
|
};
|
|
modules-right = lib.mkBefore [ "custom/ai-usage" ];
|
|
};
|
|
programs.waybar.style = lib.mkAfter ''
|
|
#custom-ai-usage.ok { color: #a6e3a1; }
|
|
#custom-ai-usage.warning { color: #fab387; }
|
|
#custom-ai-usage.critical { color: #f38ba8; }
|
|
#custom-ai-usage.unknown { color: #cdd6f4; }
|
|
'';
|
|
})
|
|
]);
|
|
}
|