at 17.09-beta 1.1 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 cfg = config.services.vnstat; 7in { 8 options.services.vnstat = { 9 enable = mkOption { 10 type = types.bool; 11 default = false; 12 description = '' 13 Whether to enable update of network usage statistics via vnstatd. 14 ''; 15 }; 16 }; 17 18 config = mkIf cfg.enable { 19 users.extraUsers.vnstatd = { 20 isSystemUser = true; 21 description = "vnstat daemon user"; 22 home = "/var/lib/vnstat"; 23 createHome = true; 24 }; 25 26 systemd.services.vnstat = { 27 description = "vnStat network traffic monitor"; 28 path = [ pkgs.coreutils ]; 29 after = [ "network.target" ]; 30 wantedBy = [ "multi-user.target" ]; 31 unitConfig.documentation = "man:vnstatd(1) man:vnstat(1) man:vnstat.conf(5)"; 32 preStart = "chmod 755 /var/lib/vnstat"; 33 serviceConfig = { 34 ExecStart = "${pkgs.vnstat}/bin/vnstatd -n"; 35 ExecReload = "${pkgs.procps}/bin/kill -HUP $MAINPID"; 36 ProtectHome = true; 37 PrivateDevices = true; 38 PrivateTmp = true; 39 User = "vnstatd"; 40 }; 41 }; 42 }; 43}