2021-12-05 20:58:27 +00:00
|
|
|
{ config, lib, options, pkgs, ... }:
|
2013-12-05 21:21:12 +00:00
|
|
|
|
2014-04-14 15:26:48 +01:00
|
|
|
with lib;
|
2013-12-05 21:21:12 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.ntopng;
|
2021-12-05 20:58:27 +00:00
|
|
|
opt = options.services.ntopng;
|
2022-02-12 12:45:57 +00:00
|
|
|
|
|
|
|
createRedis = cfg.redis.createInstance != null;
|
|
|
|
redisService =
|
|
|
|
if cfg.redis.createInstance == "" then
|
|
|
|
"redis.service"
|
|
|
|
else
|
|
|
|
"redis-${cfg.redis.createInstance}.service";
|
2013-12-05 21:21:12 +00:00
|
|
|
|
|
|
|
configFile = if cfg.configText != "" then
|
|
|
|
pkgs.writeText "ntopng.conf" ''
|
|
|
|
${cfg.configText}
|
|
|
|
''
|
|
|
|
else
|
|
|
|
pkgs.writeText "ntopng.conf" ''
|
|
|
|
${concatStringsSep " " (map (e: "--interface=" + e) cfg.interfaces)}
|
2022-02-16 18:33:19 +00:00
|
|
|
--http-port=${toString cfg.httpPort}
|
2022-02-12 12:45:57 +00:00
|
|
|
--redis=${cfg.redis.address}
|
|
|
|
--data-dir=/var/lib/ntopng
|
|
|
|
--user=ntopng
|
2013-12-05 21:21:12 +00:00
|
|
|
${cfg.extraConfig}
|
|
|
|
'';
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
2022-02-16 18:33:19 +00:00
|
|
|
imports = [
|
|
|
|
(mkRenamedOptionModule [ "services" "ntopng" "http-port" ] [ "services" "ntopng" "httpPort" ])
|
|
|
|
];
|
|
|
|
|
2013-12-05 21:21:12 +00:00
|
|
|
options = {
|
|
|
|
|
|
|
|
services.ntopng = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2013-12-05 21:21:12 +00:00
|
|
|
Enable ntopng, a high-speed web-based traffic analysis and flow
|
|
|
|
collection tool.
|
|
|
|
|
|
|
|
With the default configuration, ntopng monitors all network
|
2021-12-05 20:58:27 +00:00
|
|
|
interfaces and displays its findings at http://localhost:''${toString
|
|
|
|
config.${opt.http-port}}. Default username and password is admin/admin.
|
2013-12-05 21:21:12 +00:00
|
|
|
|
|
|
|
See the ntopng(8) manual page and http://www.ntop.org/products/ntop/
|
|
|
|
for more info.
|
|
|
|
|
|
|
|
Note that enabling ntopng will also enable redis (key-value
|
|
|
|
database server) for persistent data storage.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
interfaces = mkOption {
|
|
|
|
default = [ "any" ];
|
|
|
|
example = [ "eth0" "wlan0" ];
|
|
|
|
type = types.listOf types.str;
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2013-12-05 21:21:12 +00:00
|
|
|
List of interfaces to monitor. Use "any" to monitor all interfaces.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2022-02-16 18:33:19 +00:00
|
|
|
httpPort = mkOption {
|
2013-12-05 21:21:12 +00:00
|
|
|
default = 3000;
|
2015-06-15 17:11:32 +01:00
|
|
|
type = types.int;
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2013-12-05 21:21:12 +00:00
|
|
|
Sets the HTTP port of the embedded web server.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2022-02-12 12:45:57 +00:00
|
|
|
redis.address = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = literalExpression "config.services.redis.ntopng.unixSocket";
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2022-02-12 12:45:57 +00:00
|
|
|
Redis address - may be a Unix socket or a network host and port.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
redis.createInstance = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = if versionAtLeast config.system.stateVersion "22.05" then "ntopng" else "";
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
Local Redis instance name. Set to `null` to disable
|
|
|
|
local Redis instance. Defaults to `""` for
|
|
|
|
`system.stateVersion` older than 22.05.
|
2022-02-12 12:45:57 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2013-12-05 21:21:12 +00:00
|
|
|
configText = mkOption {
|
|
|
|
default = "";
|
|
|
|
example = ''
|
|
|
|
--interface=any
|
|
|
|
--http-port=3000
|
|
|
|
--disable-login
|
|
|
|
'';
|
|
|
|
type = types.lines;
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2013-12-05 21:21:12 +00:00
|
|
|
Overridable configuration file contents to use for ntopng. By
|
|
|
|
default, use the contents automatically generated by NixOS.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
default = "";
|
|
|
|
type = types.lines;
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2013-12-05 21:21:12 +00:00
|
|
|
Configuration lines that will be appended to the generated ntopng
|
|
|
|
configuration file. Note that this mechanism does not work when the
|
2022-07-28 22:19:15 +01:00
|
|
|
manual {option}`configText` option is used.
|
2013-12-05 21:21:12 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
# ntopng uses redis for data storage
|
2022-02-12 12:45:57 +00:00
|
|
|
services.ntopng.redis.address =
|
|
|
|
mkIf createRedis config.services.redis.servers.${cfg.redis.createInstance}.unixSocket;
|
|
|
|
|
|
|
|
services.redis.servers = mkIf createRedis {
|
|
|
|
${cfg.redis.createInstance} = {
|
|
|
|
enable = true;
|
|
|
|
user = mkIf (cfg.redis.createInstance == "ntopng") "ntopng";
|
|
|
|
};
|
|
|
|
};
|
2013-12-05 21:21:12 +00:00
|
|
|
|
|
|
|
# nice to have manual page and ntopng command in PATH
|
|
|
|
environment.systemPackages = [ pkgs.ntopng ];
|
|
|
|
|
2022-02-12 12:45:57 +00:00
|
|
|
systemd.tmpfiles.rules = [ "d /var/lib/ntopng 0700 ntopng ntopng -" ];
|
|
|
|
|
2013-12-05 21:21:12 +00:00
|
|
|
systemd.services.ntopng = {
|
|
|
|
description = "Ntopng Network Monitor";
|
2022-02-12 12:45:57 +00:00
|
|
|
requires = optional createRedis redisService;
|
|
|
|
after = [ "network.target" ] ++ optional createRedis redisService;
|
2013-12-05 21:21:12 +00:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
serviceConfig.ExecStart = "${pkgs.ntopng}/bin/ntopng ${configFile}";
|
|
|
|
unitConfig.Documentation = "man:ntopng(8)";
|
|
|
|
};
|
|
|
|
|
2022-02-12 12:45:57 +00:00
|
|
|
users.extraUsers.ntopng = {
|
|
|
|
group = "ntopng";
|
|
|
|
isSystemUser = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
users.extraGroups.ntopng = { };
|
2013-12-05 21:21:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|