8 cfg = config.services.nezha-agent;
12 maintainers = with lib.maintainers; [ moraxyc ];
15 services.nezha-agent = {
16 enable = lib.mkEnableOption "Agent of Nezha Monitoring";
18 package = lib.mkPackageOption pkgs "nezha-agent" { };
19 debug = lib.mkEnableOption "verbose log";
21 type = lib.types.bool;
24 Enable SSL/TLS encryption.
28 type = lib.types.bool;
31 Enable GPU monitoring.
34 disableCommandExecute = lib.mkOption {
35 type = lib.types.bool;
38 Disable executing the command from dashboard.
41 skipConnection = lib.mkOption {
42 type = lib.types.bool;
45 Do not monitor the number of connections.
48 skipProcess = lib.mkOption {
49 type = lib.types.bool;
52 Do not monitor the number of processes.
55 reportDelay = lib.mkOption {
56 type = lib.types.enum [
64 The interval between system status reportings.
65 The value must be an integer from 1 to 4
68 passwordFile = lib.mkOption {
69 type = with lib.types; nullOr str;
72 Path to the file contained the password from dashboard.
75 server = lib.mkOption {
78 Address to the dashboard
84 config = lib.mkIf cfg.enable {
85 systemd.packages = [ cfg.package ];
87 systemd.services.nezha-agent = {
89 ProtectSystem = "full";
90 PrivateDevices = "yes";
92 NoNewPrivileges = true;
94 path = [ cfg.package ];
95 startLimitIntervalSec = 10;
97 script = lib.concatStringsSep " " (
99 "${cfg.package}/bin/agent"
100 "--disable-auto-update"
101 "--disable-force-update"
102 "--password $(cat ${cfg.passwordFile})"
104 ++ lib.optional cfg.debug "--debug"
105 ++ lib.optional cfg.disableCommandExecute "--disable-command-execute"
106 ++ lib.optional (cfg.reportDelay != null) "--report-delay ${toString cfg.reportDelay}"
107 ++ lib.optional (cfg.server != null) "--server ${cfg.server}"
108 ++ lib.optional cfg.skipConnection "--skip-conn"
109 ++ lib.optional cfg.skipProcess "--skip-procs"
110 ++ lib.optional cfg.tls "--tls"
111 ++ lib.optional cfg.gpu "--gpu"
113 wantedBy = [ "multi-user.target" ];