2023-09-12 08:44:05 -06:00
|
|
|
{ config
|
|
|
|
, lib
|
|
|
|
, pkgs
|
|
|
|
, inputs
|
|
|
|
, ...
|
2023-07-11 09:12:50 -06:00
|
|
|
}:
|
|
|
|
with pkgs; let
|
2022-11-17 16:09:05 -07:00
|
|
|
cfg = config.services.tsvnstat;
|
|
|
|
inherit (inputs.tsvnstat.packages.${pkgs.system}) tsvnstat;
|
2023-09-12 08:44:05 -06:00
|
|
|
in
|
|
|
|
{
|
2022-11-17 16:09:05 -07:00
|
|
|
options = with lib; {
|
|
|
|
services.tsvnstat = {
|
|
|
|
enable = mkEnableOption "Enable tsvnstat";
|
|
|
|
|
|
|
|
user = mkOption {
|
2023-09-12 08:44:05 -06:00
|
|
|
type = with types; oneOf [ str int ];
|
2022-11-17 16:09:05 -07:00
|
|
|
default = "tsvnstat";
|
|
|
|
description = ''
|
|
|
|
The user the service will use.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
keyPath = mkOption {
|
2023-09-25 14:36:25 -06:00
|
|
|
type = with types; oneOf [ path str ];
|
2022-11-17 16:09:05 -07:00
|
|
|
default = "";
|
|
|
|
description = ''
|
|
|
|
Path to the TS API key file
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
nodeName = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "${config.networking.hostName}-stats";
|
|
|
|
description = ''
|
|
|
|
The name of the TS node.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
2023-09-12 08:44:05 -06:00
|
|
|
type = with types; oneOf [ str int ];
|
2022-11-17 16:09:05 -07:00
|
|
|
default = "tsvnstat";
|
|
|
|
description = ''
|
|
|
|
The user the service will use.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = tsvnstat;
|
|
|
|
defaultText = literalExpression "pkgs.tsvnstat";
|
|
|
|
description = "The package to use for tsvnstat";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
config = lib.mkIf cfg.enable {
|
2023-09-12 08:44:05 -06:00
|
|
|
users.groups.${cfg.group} = { };
|
2022-11-17 16:09:05 -07:00
|
|
|
users.users.${cfg.user} = {
|
|
|
|
description = "tsvnstat service user";
|
|
|
|
isSystemUser = true;
|
|
|
|
home = "/var/lib/tsvnstat";
|
|
|
|
createHome = true;
|
|
|
|
group = "${cfg.group}";
|
|
|
|
};
|
|
|
|
|
|
|
|
services.vnstat.enable = true;
|
|
|
|
|
|
|
|
systemd.services.tsvnstat = {
|
|
|
|
enable = true;
|
|
|
|
description = "tsvnstat server";
|
2024-06-14 09:04:26 -06:00
|
|
|
wants = [ "network-online.target" ];
|
2022-11-17 16:09:05 -07:00
|
|
|
|
2023-09-12 08:44:05 -06:00
|
|
|
path = [ pkgs.vnstat ];
|
2022-11-17 16:09:05 -07:00
|
|
|
|
|
|
|
environment = {
|
|
|
|
HOME = "/var/lib/tsvnstat";
|
|
|
|
HOSTNAME = config.networking.hostName;
|
|
|
|
};
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
|
|
|
|
|
|
|
RuntimeDirectory = "tsvnstat";
|
|
|
|
StateDirectory = "tsvnstat";
|
|
|
|
StateDirectoryMode = "0755";
|
2022-11-21 11:11:57 -07:00
|
|
|
CacheDirectory = "tsvnstat";
|
2022-11-17 16:09:05 -07:00
|
|
|
CacheDirectoryMode = "0755";
|
|
|
|
|
2023-09-25 14:36:25 -06:00
|
|
|
ExecStart = ''
|
|
|
|
${cfg.package}/bin/tsvnstat -vnstati ${pkgs.vnstat}/bin/vnstati -name ${cfg.nodeName} ${lib.optionalString (cfg.keyPath != "") "-key ${cfg.keyPath}"}
|
|
|
|
'';
|
2022-11-17 16:09:05 -07:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|