diff options
author | Michael Raskin <7c6f434c@mail.ru> | 2013-12-14 22:46:49 -0800 |
---|---|---|
committer | Michael Raskin <7c6f434c@mail.ru> | 2013-12-14 22:46:49 -0800 |
commit | 152f7666af668fe484fd5d03b582691bb89796b3 (patch) | |
tree | ffd51717983ae250edc0c210a9ebc3d94086c6e3 /nixos | |
parent | d2c57ddabbf074bd96a54cefc0d06867526527ba (diff) | |
parent | 9474fbae65556933538076709332f11d40234b2e (diff) | |
download | nixlib-152f7666af668fe484fd5d03b582691bb89796b3.tar nixlib-152f7666af668fe484fd5d03b582691bb89796b3.tar.gz nixlib-152f7666af668fe484fd5d03b582691bb89796b3.tar.bz2 nixlib-152f7666af668fe484fd5d03b582691bb89796b3.tar.lz nixlib-152f7666af668fe484fd5d03b582691bb89796b3.tar.xz nixlib-152f7666af668fe484fd5d03b582691bb89796b3.tar.zst nixlib-152f7666af668fe484fd5d03b582691bb89796b3.zip |
Merge pull request #1340 from bjornfor/ntopng
Add ntopng package and nixos service module
Diffstat (limited to 'nixos')
-rw-r--r-- | nixos/modules/module-list.nix | 1 | ||||
-rw-r--r-- | nixos/modules/services/networking/ntopng.nix | 116 |
2 files changed, 117 insertions, 0 deletions
diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 078ea225e167..684850df2aec 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -170,6 +170,7 @@ ./services/networking/minidlna.nix ./services/networking/nat.nix ./services/networking/networkmanager.nix + ./services/networking/ntopng.nix ./services/networking/ntpd.nix ./services/networking/oidentd.nix ./services/networking/openfire.nix diff --git a/nixos/modules/services/networking/ntopng.nix b/nixos/modules/services/networking/ntopng.nix new file mode 100644 index 000000000000..156a6b32a6ab --- /dev/null +++ b/nixos/modules/services/networking/ntopng.nix @@ -0,0 +1,116 @@ +{ config, pkgs, ... }: + +with pkgs.lib; + +let + + cfg = config.services.ntopng; + redisCfg = config.services.redis; + + configFile = if cfg.configText != "" then + pkgs.writeText "ntopng.conf" '' + ${cfg.configText} + '' + else + pkgs.writeText "ntopng.conf" '' + ${concatStringsSep " " (map (e: "--interface=" + e) cfg.interfaces)} + --http-port=${toString cfg.http-port} + --redis=localhost:${toString redisCfg.port} + ${cfg.extraConfig} + ''; + +in + +{ + + options = { + + services.ntopng = { + + enable = mkOption { + default = false; + type = types.bool; + description = '' + Enable ntopng, a high-speed web-based traffic analysis and flow + collection tool. + + With the default configuration, ntopng monitors all network + interfaces and displays its findings at http://localhost:${toString + cfg.http-port}. Default username and password is admin/admin. + + 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; + description = '' + List of interfaces to monitor. Use "any" to monitor all interfaces. + ''; + }; + + http-port = mkOption { + default = 3000; + type = types.uniq types.int; + description = '' + Sets the HTTP port of the embedded web server. + ''; + }; + + configText = mkOption { + default = ""; + example = '' + --interface=any + --http-port=3000 + --disable-login + ''; + type = types.lines; + description = '' + Overridable configuration file contents to use for ntopng. By + default, use the contents automatically generated by NixOS. + ''; + }; + + extraConfig = mkOption { + default = ""; + type = types.lines; + description = '' + Configuration lines that will be appended to the generated ntopng + configuration file. Note that this mechanism does not work when the + manual <option>configText</option> option is used. + ''; + }; + + }; + + }; + + config = mkIf cfg.enable { + + # ntopng uses redis for data storage + services.redis.enable = true; + + # nice to have manual page and ntopng command in PATH + environment.systemPackages = [ pkgs.ntopng ]; + + systemd.services.ntopng = { + description = "Ntopng Network Monitor"; + requires = [ "redis.service" ]; + after = [ "network.target" "redis.service" ]; + wantedBy = [ "multi-user.target" ]; + preStart = "mkdir -p /var/lib/ntopng/"; + serviceConfig.ExecStart = "${pkgs.ntopng}/bin/ntopng ${configFile}"; + unitConfig.Documentation = "man:ntopng(8)"; + }; + + # ntopng drops priveleges to user "nobody" and that user is already defined + # in users-groups.nix. + }; + +} |