1 { config, lib, options, pkgs, ... }:
7 cfg = config.services.ntopng;
8 opt = options.services.ntopng;
10 createRedis = cfg.redis.createInstance != null;
12 if cfg.redis.createInstance == "" then
15 "redis-${cfg.redis.createInstance}.service";
17 configFile = if cfg.configText != "" then
18 pkgs.writeText "ntopng.conf" ''
22 pkgs.writeText "ntopng.conf" ''
23 ${concatStringsSep "\n" (map (e: "--interface=${e}") cfg.interfaces)}
24 --http-port=${toString cfg.httpPort}
25 --redis=${cfg.redis.address}
26 --data-dir=/var/lib/ntopng
36 (mkRenamedOptionModule [ "services" "ntopng" "http-port" ] [ "services" "ntopng" "httpPort" ])
47 Enable ntopng, a high-speed web-based traffic analysis and flow
50 With the default configuration, ntopng monitors all network
51 interfaces and displays its findings at http://localhost:''${toString
52 config.${opt.http-port}}. Default username and password is admin/admin.
54 See the ntopng(8) manual page and http://www.ntop.org/products/ntop/
57 Note that enabling ntopng will also enable redis (key-value
58 database server) for persistent data storage.
62 interfaces = mkOption {
64 example = [ "eth0" "wlan0" ];
65 type = types.listOf types.str;
67 List of interfaces to monitor. Use "any" to monitor all interfaces.
75 Sets the HTTP port of the embedded web server.
79 redis.address = mkOption {
81 example = literalExpression "config.services.redis.ntopng.unixSocket";
83 Redis address - may be a Unix socket or a network host and port.
87 redis.createInstance = mkOption {
88 type = types.nullOr types.str;
89 default = optionalString (versionAtLeast config.system.stateVersion "22.05") "ntopng";
91 Local Redis instance name. Set to `null` to disable
92 local Redis instance. Defaults to `""` for
93 `system.stateVersion` older than 22.05.
97 configText = mkOption {
106 Overridable configuration file contents to use for ntopng. By
107 default, use the contents automatically generated by NixOS.
111 extraConfig = mkOption {
115 Configuration lines that will be appended to the generated ntopng
116 configuration file. Note that this mechanism does not work when the
117 manual {option}`configText` option is used.
125 config = mkIf cfg.enable {
127 # ntopng uses redis for data storage
128 services.ntopng.redis.address =
129 mkIf createRedis config.services.redis.servers.${cfg.redis.createInstance}.unixSocket;
131 services.redis.servers = mkIf createRedis {
132 ${cfg.redis.createInstance} = {
134 user = mkIf (cfg.redis.createInstance == "ntopng") "ntopng";
138 # nice to have manual page and ntopng command in PATH
139 environment.systemPackages = [ pkgs.ntopng ];
141 systemd.tmpfiles.rules = [ "d /var/lib/ntopng 0700 ntopng ntopng -" ];
143 systemd.services.ntopng = {
144 description = "Ntopng Network Monitor";
145 requires = optional createRedis redisService;
146 after = [ "network.target" ] ++ optional createRedis redisService;
147 wantedBy = [ "multi-user.target" ];
148 serviceConfig.ExecStart = "${pkgs.ntopng}/bin/ntopng ${configFile}";
149 unitConfig.Documentation = "man:ntopng(8)";
152 users.extraUsers.ntopng = {
157 users.extraGroups.ntopng = { };