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 temperature = lib.mkOption {
35 type = lib.types.bool;
38 Enable temperature monitoring.
41 useIPv6CountryCode = lib.mkOption {
42 type = lib.types.bool;
45 Use ipv6 countrycode to report location.
48 disableCommandExecute = lib.mkOption {
49 type = lib.types.bool;
52 Disable executing the command from dashboard.
55 disableNat = lib.mkOption {
56 type = lib.types.bool;
59 Disable NAT penetration.
62 disableSendQuery = lib.mkOption {
63 type = lib.types.bool;
66 Disable sending TCP/ICMP/HTTP requests.
69 skipConnection = lib.mkOption {
70 type = lib.types.bool;
73 Do not monitor the number of connections.
76 skipProcess = lib.mkOption {
77 type = lib.types.bool;
80 Do not monitor the number of processes.
83 reportDelay = lib.mkOption {
84 type = lib.types.enum [
92 The interval between system status reportings.
93 The value must be an integer from 1 to 4
96 passwordFile = lib.mkOption {
97 type = with lib.types; nullOr str;
100 Path to the file contained the password from dashboard.
103 server = lib.mkOption {
104 type = lib.types.str;
106 Address to the dashboard
109 extraFlags = lib.mkOption {
110 type = lib.types.listOf lib.types.str;
112 example = [ "--gpu" ];
114 Extra command-line flags passed to nezha-agent.
120 config = lib.mkIf cfg.enable {
121 systemd.packages = [ cfg.package ];
123 systemd.services.nezha-agent = {
125 ProtectSystem = "full";
126 PrivateDevices = "yes";
128 NoNewPrivileges = true;
130 path = [ cfg.package ];
131 startLimitIntervalSec = 10;
133 script = lib.concatStringsSep " " (
135 "${lib.getExe cfg.package}"
136 "--disable-auto-update"
137 "--disable-force-update"
138 "--password $(cat ${cfg.passwordFile})"
140 ++ lib.optional cfg.debug "--debug"
141 ++ lib.optional cfg.disableCommandExecute "--disable-command-execute"
142 ++ lib.optional cfg.disableNat "--disable-nat"
143 ++ lib.optional cfg.disableSendQuery "--disable-send-query"
144 ++ lib.optional (cfg.reportDelay != null) "--report-delay ${toString cfg.reportDelay}"
145 ++ lib.optional (cfg.server != null) "--server ${cfg.server}"
146 ++ lib.optional cfg.skipConnection "--skip-conn"
147 ++ lib.optional cfg.skipProcess "--skip-procs"
148 ++ lib.optional cfg.tls "--tls"
149 ++ lib.optional cfg.gpu "--gpu"
150 ++ lib.optional cfg.temperature "--temperature"
151 ++ lib.optional cfg.useIPv6CountryCode "--use-ipv6-countrycode"
154 wantedBy = [ "multi-user.target" ];