at 17.09-beta 1.8 kB view raw
1{ config, pkgs, lib, ... }: 2 3with lib; 4 5let 6 cfg = config.services.netdata; 7 8 configFile = pkgs.writeText "netdata.conf" cfg.configText; 9 10 defaultUser = "netdata"; 11 12in { 13 options = { 14 services.netdata = { 15 enable = mkOption { 16 default = false; 17 type = types.bool; 18 description = "Whether to enable netdata monitoring."; 19 }; 20 21 user = mkOption { 22 type = types.str; 23 default = "netdata"; 24 description = "User account under which netdata runs."; 25 }; 26 27 group = mkOption { 28 type = types.str; 29 default = "netdata"; 30 description = "Group under which netdata runs."; 31 }; 32 33 configText = mkOption { 34 type = types.lines; 35 default = ""; 36 description = "netdata.conf configuration."; 37 example = '' 38 [global] 39 debug log = syslog 40 access log = syslog 41 error log = syslog 42 ''; 43 }; 44 45 }; 46 }; 47 48 config = mkIf cfg.enable { 49 systemd.services.netdata = { 50 description = "Real time performance monitoring"; 51 after = [ "network.target" ]; 52 wantedBy = [ "multi-user.target" ]; 53 preStart = concatStringsSep "\n" (map (dir: '' 54 mkdir -vp ${dir} 55 chmod 750 ${dir} 56 chown -R ${cfg.user}:${cfg.group} ${dir} 57 '') [ "/var/cache/netdata" 58 "/var/log/netdata" 59 "/var/lib/netdata" ]); 60 serviceConfig = { 61 User = cfg.user; 62 Group = cfg.group; 63 PermissionsStartOnly = true; 64 ExecStart = "${pkgs.netdata}/bin/netdata -D -c ${configFile}"; 65 TimeoutStopSec = 60; 66 }; 67 }; 68 69 users.extraUsers = optional (cfg.user == defaultUser) { 70 name = defaultUser; 71 }; 72 73 users.extraGroups = optional (cfg.group == defaultUser) { 74 name = defaultUser; 75 }; 76 77 }; 78}