summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikolay Amiantov <ab@fmap.me>2022-02-12 15:45:57 +0300
committerNikolay Amiantov <ab@fmap.me>2022-02-19 14:03:33 +0300
commit41f4d999ad6ea5233e0852daea33d3c375b5a5ee (patch)
tree77c66d2fde6e8196c710396d1c2d795579c0f9e4
parent6a91c56637e58e3dd4b7c2ff05998169e5c43f37 (diff)
nixos/ntopng: update user and redis configuration
New ntopng version supports running as specified user. Create a separate user for ntopng with a separate Redis instance. Separate instance is only used for new `system.stateVersion`s to avoid breaking existing setups. To configure that we add two new options, `redis.address` and `redis.createInstance`. They can also be used to specify your own Redis address.
-rw-r--r--nixos/doc/manual/from_md/release-notes/rl-2205.section.xml9
-rw-r--r--nixos/doc/manual/release-notes/rl-2205.section.md2
-rw-r--r--nixos/modules/services/networking/ntopng.nix55
3 files changed, 58 insertions, 8 deletions
diff --git a/nixos/doc/manual/from_md/release-notes/rl-2205.section.xml b/nixos/doc/manual/from_md/release-notes/rl-2205.section.xml
index 42db2d060be6..5d0a9dc76ea7 100644
--- a/nixos/doc/manual/from_md/release-notes/rl-2205.section.xml
+++ b/nixos/doc/manual/from_md/release-notes/rl-2205.section.xml
@@ -320,6 +320,15 @@
</listitem>
<listitem>
<para>
+ Ntopng (<literal>services.ntopng</literal>) is updated to
+ 5.2.1 and uses a separate Redis instance if
+ <literal>system.stateVersion</literal> is at least
+ <literal>22.05</literal>. Existing setups shouldn’t be
+ affected.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
The backward compatibility in
<literal>services.wordpress</literal> to configure sites with
the old interface has been removed. Please use
diff --git a/nixos/doc/manual/release-notes/rl-2205.section.md b/nixos/doc/manual/release-notes/rl-2205.section.md
index 7bb7b1c33b16..7846513c6070 100644
--- a/nixos/doc/manual/release-notes/rl-2205.section.md
+++ b/nixos/doc/manual/release-notes/rl-2205.section.md
@@ -104,6 +104,8 @@ In addition to numerous new and upgraded packages, this release has the followin
- If you previously used `/etc/docker/daemon.json`, you need to incorporate the changes into the new option `virtualisation.docker.daemon.settings`.
+- Ntopng (`services.ntopng`) is updated to 5.2.1 and uses a separate Redis instance if `system.stateVersion` is at least `22.05`. Existing setups shouldn't be affected.
+
- The backward compatibility in `services.wordpress` to configure sites with
the old interface has been removed. Please use `services.wordpress.sites`
instead.
diff --git a/nixos/modules/services/networking/ntopng.nix b/nixos/modules/services/networking/ntopng.nix
index 77a004e8ab3a..2c45d418a0db 100644
--- a/nixos/modules/services/networking/ntopng.nix
+++ b/nixos/modules/services/networking/ntopng.nix
@@ -6,7 +6,13 @@ let
cfg = config.services.ntopng;
opt = options.services.ntopng;
- redisCfg = config.services.redis;
+
+ createRedis = cfg.redis.createInstance != null;
+ redisService =
+ if cfg.redis.createInstance == "" then
+ "redis.service"
+ else
+ "redis-${cfg.redis.createInstance}.service";
configFile = if cfg.configText != "" then
pkgs.writeText "ntopng.conf" ''
@@ -16,7 +22,9 @@ let
pkgs.writeText "ntopng.conf" ''
${concatStringsSep " " (map (e: "--interface=" + e) cfg.interfaces)}
--http-port=${toString cfg.http-port}
- --redis=localhost:${toString redisCfg.port}
+ --redis=${cfg.redis.address}
+ --data-dir=/var/lib/ntopng
+ --user=ntopng
${cfg.extraConfig}
'';
@@ -64,6 +72,24 @@ in
'';
};
+ redis.address = mkOption {
+ type = types.str;
+ example = literalExpression "config.services.redis.ntopng.unixSocket";
+ description = ''
+ 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 "";
+ description = ''
+ Local Redis instance name. Set to <literal>null</literal> to disable
+ local Redis instance. Defaults to <literal>""</literal> for
+ <literal>system.stateVersion</literal> older than 22.05.
+ '';
+ };
+
configText = mkOption {
default = "";
example = ''
@@ -95,23 +121,36 @@ in
config = mkIf cfg.enable {
# ntopng uses redis for data storage
- services.redis.enable = true;
+ 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";
+ };
+ };
# nice to have manual page and ntopng command in PATH
environment.systemPackages = [ pkgs.ntopng ];
+ systemd.tmpfiles.rules = [ "d /var/lib/ntopng 0700 ntopng ntopng -" ];
+
systemd.services.ntopng = {
description = "Ntopng Network Monitor";
- requires = [ "redis.service" ];
- after = [ "network.target" "redis.service" ];
+ requires = optional createRedis redisService;
+ after = [ "network.target" ] ++ optional createRedis redisService;
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.
+ users.extraUsers.ntopng = {
+ group = "ntopng";
+ isSystemUser = true;
+ };
+
+ users.extraGroups.ntopng = { };
};
}