{ inputs, povSelf, config, lib, pkgs, ... }: let inherit (lib) types; cfg = lib.getAttrFromPath povSelf config; in { options = { enable = { type = types.bool; default = false; }; vnstati.enable = { type = types.bool; default = false; }; }; config = lib.mkIf cfg.enable { services.vnstat.enable = true; modules.filesystem.impermanence.system.dirs = [ "/var/lib/vnstat" ]; services.nginx.virtualHosts."${config.networking.fqdn}" = lib.mkIf cfg.vnstati.enable { locations."/vnstat/" = { alias = "/var/run/vnstati/"; index = "index.html"; }; }; systemd.services.vnstati = lib.mkIf cfg.vnstati.enable { wantedBy = [ "multi-user.target" ]; after = [ "vnstat.service" ]; startAt = "*-*-* *:0/10:00"; serviceConfig = { User = "vnstatd"; Group = "vnstatd"; RuntimeDirectoryPreserve = true; RuntimeDirectory = "vnstati"; RuntimeDirectoryMode = 775; PrivateTmp = true; ProtectHome = true; ProtectSystem = "strict"; }; path = with pkgs; [ vnstat jq nix ]; script = '' set -x ifaces=$(vnstat --json | jq -r .interfaces[].name | grep -v "^lo$") echo $ifaces cat > /var/run/vnstati/index.html << EOF ${config.networking.hostName} - stats

${config.networking.hostName}

EOF for iface in $ifaces do cat >> /var/run/vnstati/index.html << EOF

''${iface}

Summary
Hourly
Daily
Monthly
Top 10
EOF vnstati -s -nh -i $iface -o /var/run/vnstati/$iface-summary.png vnstati -h -nh -i $iface -o /var/run/vnstati/$iface-hourly.png vnstati -d -nh -i $iface -o /var/run/vnstati/$iface-daily.png vnstati -m -nh -i $iface -o /var/run/vnstati/$iface-monthly.png vnstati -t -nh -i $iface -o /var/run/vnstati/$iface-top10.png done cat >> /var/run/vnstati/index.html << EOF
EOF ''; }; }; }