13 cfg = config.services.ntopng;
14 opt = options.services.ntopng;
16 createRedis = cfg.redis.createInstance != null;
18 if cfg.redis.createInstance == "" then
21 "redis-${cfg.redis.createInstance}.service";
24 if cfg.configText != "" then
25 pkgs.writeText "ntopng.conf" ''
29 pkgs.writeText "ntopng.conf" ''
30 ${concatStringsSep "\n" (map (e: "--interface=${e}") cfg.interfaces)}
31 --http-port=${toString cfg.httpPort}
32 --redis=${cfg.redis.address}
33 --data-dir=/var/lib/ntopng
43 (mkRenamedOptionModule [ "services" "ntopng" "http-port" ] [ "services" "ntopng" "httpPort" ])
54 Enable ntopng, a high-speed web-based traffic analysis and flow
57 With the default configuration, ntopng monitors all network
58 interfaces and displays its findings at http://localhost:''${toString
59 config.${opt.http-port}}. Default username and password is admin/admin.
61 See the ntopng(8) manual page and http://www.ntop.org/products/ntop/
64 Note that enabling ntopng will also enable redis (key-value
65 database server) for persistent data storage.
69 interfaces = mkOption {
75 type = types.listOf types.str;
77 List of interfaces to monitor. Use "any" to monitor all interfaces.
85 Sets the HTTP port of the embedded web server.
89 redis.address = mkOption {
91 example = literalExpression "config.services.redis.ntopng.unixSocket";
93 Redis address - may be a Unix socket or a network host and port.
97 redis.createInstance = mkOption {
98 type = types.nullOr types.str;
99 default = optionalString (versionAtLeast config.system.stateVersion "22.05") "ntopng";
101 Local Redis instance name. Set to `null` to disable
102 local Redis instance. Defaults to `""` for
103 `system.stateVersion` older than 22.05.
107 configText = mkOption {
116 Overridable configuration file contents to use for ntopng. By
117 default, use the contents automatically generated by NixOS.
121 extraConfig = mkOption {
125 Configuration lines that will be appended to the generated ntopng
126 configuration file. Note that this mechanism does not work when the
127 manual {option}`configText` option is used.
135 config = mkIf cfg.enable {
137 # ntopng uses redis for data storage
138 services.ntopng.redis.address =
140 config.services.redis.servers.${cfg.redis.createInstance}.unixSocket;
142 services.redis.servers = mkIf createRedis {
143 ${cfg.redis.createInstance} = {
145 user = mkIf (cfg.redis.createInstance == "ntopng") "ntopng";
149 # nice to have manual page and ntopng command in PATH
150 environment.systemPackages = [ pkgs.ntopng ];
152 systemd.tmpfiles.rules = [ "d /var/lib/ntopng 0700 ntopng ntopng -" ];
154 systemd.services.ntopng = {
155 description = "Ntopng Network Monitor";
156 requires = optional createRedis redisService;
157 after = [ "network.target" ] ++ optional createRedis redisService;
158 wantedBy = [ "multi-user.target" ];
159 serviceConfig.ExecStart = "${pkgs.ntopng}/bin/ntopng ${configFile}";
160 unitConfig.Documentation = "man:ntopng(8)";
163 users.extraUsers.ntopng = {
168 users.extraGroups.ntopng = { };