2016-11-05 13:09:29 +01:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.netdata;
|
|
|
|
|
2017-10-18 01:51:41 +02:00
|
|
|
wrappedPlugins = pkgs.runCommand "wrapped-plugins" {} ''
|
|
|
|
mkdir -p $out/libexec/netdata/plugins.d
|
|
|
|
ln -s /run/wrappers/bin/apps.plugin $out/libexec/netdata/plugins.d/apps.plugin
|
|
|
|
'';
|
|
|
|
|
|
|
|
localConfig = {
|
|
|
|
global = {
|
2018-10-12 10:57:45 +02:00
|
|
|
"plugins directory" = "${pkgs.netdata}/libexec/netdata/plugins.d ${wrappedPlugins}/libexec/netdata/plugins.d";
|
2017-10-18 01:51:41 +02:00
|
|
|
};
|
2018-08-05 00:05:48 +02:00
|
|
|
web = {
|
|
|
|
"web files owner" = "root";
|
|
|
|
"web files group" = "root";
|
|
|
|
};
|
2017-10-18 01:51:41 +02:00
|
|
|
};
|
|
|
|
mkConfig = generators.toINI {} (recursiveUpdate localConfig cfg.config);
|
|
|
|
configFile = pkgs.writeText "netdata.conf" (if cfg.configText != null then cfg.configText else mkConfig);
|
2016-11-05 13:09:29 +01:00
|
|
|
|
|
|
|
defaultUser = "netdata";
|
|
|
|
|
|
|
|
in {
|
|
|
|
options = {
|
|
|
|
services.netdata = {
|
2017-10-18 01:51:41 +02:00
|
|
|
enable = mkEnableOption "netdata";
|
2016-11-05 13:09:29 +01:00
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "netdata";
|
|
|
|
description = "User account under which netdata runs.";
|
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "netdata";
|
|
|
|
description = "Group under which netdata runs.";
|
|
|
|
};
|
|
|
|
|
|
|
|
configText = mkOption {
|
2017-10-18 01:51:41 +02:00
|
|
|
type = types.nullOr types.lines;
|
|
|
|
description = "Verbatim netdata.conf, cannot be combined with config.";
|
|
|
|
default = null;
|
2016-11-05 13:09:29 +01:00
|
|
|
example = ''
|
|
|
|
[global]
|
|
|
|
debug log = syslog
|
|
|
|
access log = syslog
|
|
|
|
error log = syslog
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-11-17 16:11:46 +01:00
|
|
|
python = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whether to enable python-based plugins
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
extraPackages = mkOption {
|
|
|
|
default = ps: [];
|
|
|
|
defaultText = "ps: []";
|
|
|
|
example = literalExample ''
|
|
|
|
ps: [
|
|
|
|
ps.psycopg2
|
|
|
|
ps.docker
|
|
|
|
ps.dnspython
|
|
|
|
]
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Extra python packages available at runtime
|
|
|
|
to enable additional python plugins.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-10-18 01:51:41 +02:00
|
|
|
config = mkOption {
|
|
|
|
type = types.attrsOf types.attrs;
|
|
|
|
default = {};
|
|
|
|
description = "netdata.conf configuration as nix attributes. cannot be combined with configText.";
|
|
|
|
example = literalExample ''
|
|
|
|
global = {
|
|
|
|
"debug log" = "syslog";
|
|
|
|
"access log" = "syslog";
|
|
|
|
"error log" = "syslog";
|
|
|
|
};
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2016-11-05 13:09:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2017-10-18 01:51:41 +02:00
|
|
|
assertions =
|
|
|
|
[ { assertion = cfg.config != {} -> cfg.configText == null ;
|
|
|
|
message = "Cannot specify both config and configText";
|
|
|
|
}
|
|
|
|
];
|
2018-11-21 23:58:02 +01:00
|
|
|
|
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
"d /var/cache/netdata 0755 ${cfg.user} ${cfg.group} -"
|
|
|
|
"Z /var/cache/netdata - ${cfg.user} ${cfg.group} -"
|
|
|
|
"d /var/log/netdata 0755 ${cfg.user} ${cfg.group} -"
|
|
|
|
"Z /var/log/netdata - ${cfg.user} ${cfg.group} -"
|
|
|
|
"d /var/lib/netdata 0755 ${cfg.user} ${cfg.group} -"
|
|
|
|
"Z /var/lib/netdata - ${cfg.user} ${cfg.group} -"
|
|
|
|
"d /etc/netdata 0755 ${cfg.user} ${cfg.group} -"
|
|
|
|
"Z /etc/netdata - ${cfg.user} ${cfg.group} -"
|
|
|
|
];
|
2016-11-05 13:09:29 +01:00
|
|
|
systemd.services.netdata = {
|
|
|
|
description = "Real time performance monitoring";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2018-11-17 16:11:46 +01:00
|
|
|
path = (with pkgs; [ gawk curl ]) ++ lib.optional cfg.python.enable
|
|
|
|
(pkgs.python3.withPackages cfg.python.extraPackages);
|
2016-11-05 13:09:29 +01:00
|
|
|
serviceConfig = {
|
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
2018-11-17 16:11:46 +01:00
|
|
|
Environment="PYTHONPATH=${pkgs.netdata}/libexec/netdata/python.d/python_modules";
|
2016-11-05 13:09:29 +01:00
|
|
|
PermissionsStartOnly = true;
|
|
|
|
ExecStart = "${pkgs.netdata}/bin/netdata -D -c ${configFile}";
|
|
|
|
TimeoutStopSec = 60;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-10-18 01:51:41 +02:00
|
|
|
security.wrappers."apps.plugin" = {
|
2018-10-12 10:57:45 +02:00
|
|
|
source = "${pkgs.netdata}/libexec/netdata/plugins.d/apps.plugin.org";
|
2017-10-18 01:51:41 +02:00
|
|
|
capabilities = "cap_dac_read_search,cap_sys_ptrace+ep";
|
|
|
|
owner = cfg.user;
|
|
|
|
group = cfg.group;
|
|
|
|
permissions = "u+rx,g+rx,o-rwx";
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-06-30 01:58:35 +02:00
|
|
|
users.users = optional (cfg.user == defaultUser) {
|
2016-11-05 13:09:29 +01:00
|
|
|
name = defaultUser;
|
|
|
|
};
|
|
|
|
|
2018-06-30 01:58:35 +02:00
|
|
|
users.groups = optional (cfg.group == defaultUser) {
|
2016-11-05 13:09:29 +01:00
|
|
|
name = defaultUser;
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|