From c778861ff8fd7978cb7ac8226b32f497a52d6413 Mon Sep 17 00:00:00 2001 From: Moraxyc Date: Thu, 10 Oct 2024 00:51:03 +0800 Subject: [PATCH 1/2] nezha-agent: 0.18.5 -> 0.20.2 --- pkgs/by-name/ne/nezha-agent/package.nix | 45 ++++++++++++++++++------- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/pkgs/by-name/ne/nezha-agent/package.nix b/pkgs/by-name/ne/nezha-agent/package.nix index 629b906d822e..9dbdb0848eef 100644 --- a/pkgs/by-name/ne/nezha-agent/package.nix +++ b/pkgs/by-name/ne/nezha-agent/package.nix @@ -1,45 +1,66 @@ { lib, buildGoModule, + stdenv, fetchFromGitHub, nezha-agent, + versionCheckHook, testers, }: buildGoModule rec { pname = "nezha-agent"; - version = "0.18.5"; + version = "0.20.2"; src = fetchFromGitHub { owner = "nezhahq"; repo = "agent"; rev = "refs/tags/v${version}"; - hash = "sha256-LmWfs3aL+1lsX4ix2FjDP5g+A0wgcfziXdw5SaKlAdk="; + hash = "sha256-BM3FhCf9zfccC2xC/Fhz2/andZmPYsJojMRUA3M9NOQ="; }; - vendorHash = "sha256-frPAhiexFSt+KobMbf32h8xv7HMcPl5koEgSs8Nz3cs="; + vendorHash = "sha256-q6/265vVg6jCnDvs825nni8QFHkJpQz4xxC9MlJH2do="; ldflags = [ "-s" "-w" "-X main.version=${version}" + "-X main.arch=${stdenv.hostPlatform.system}" ]; - # The test failed due to a geoip request in the sandbox. Remove it to avoid network requirement - preCheck = '' - rm ./pkg/monitor/myip_test.go + checkFlags = + let + # Skip tests that require network access + skippedTests = [ + "TestLookupIP" + "TestGeoIPApi" + "TestFetchGeoIP" + "TestCloudflareDetection" + ]; + in + [ "-skip=^${builtins.concatStringsSep "$|^" skippedTests}$" ]; + + postInstall = '' + pushd $out/bin + mv agent nezha-agent + + # for compatibility + ln -sr nezha-agent agent + popd ''; - passthru.tests = { - version = testers.testVersion { - package = nezha-agent; - command = "${nezha-agent}/bin/agent -v"; - }; - }; + doInstallCheck = true; + + versionCheckProgramArg = "-v"; + + nativeInstallCheckInputs = [ + versionCheckHook + ]; meta = { description = "Agent of Nezha Monitoring"; homepage = "https://github.com/nezhahq/agent"; license = lib.licenses.asl20; maintainers = with lib.maintainers; [ moraxyc ]; + mainProgram = "nezha-agent"; }; } From 61567875e5d112d5e6708da52d850a0b7a0d0556 Mon Sep 17 00:00:00 2001 From: Moraxyc Date: Sat, 19 Oct 2024 18:36:04 +0800 Subject: [PATCH 2/2] nixos/nezha-agent: add some options for new features --- .../services/monitoring/nezha-agent.nix | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/nixos/modules/services/monitoring/nezha-agent.nix b/nixos/modules/services/monitoring/nezha-agent.nix index 7ebbc7f2f329..6b8d0f58177e 100644 --- a/nixos/modules/services/monitoring/nezha-agent.nix +++ b/nixos/modules/services/monitoring/nezha-agent.nix @@ -31,6 +31,20 @@ in Enable GPU monitoring. ''; }; + temperature = lib.mkOption { + type = lib.types.bool; + default = true; + description = '' + Enable temperature monitoring. + ''; + }; + useIPv6CountryCode = lib.mkOption { + type = lib.types.bool; + default = true; + description = '' + Use ipv6 countrycode to report location. + ''; + }; disableCommandExecute = lib.mkOption { type = lib.types.bool; default = true; @@ -96,7 +110,7 @@ in startLimitBurst = 3; script = lib.concatStringsSep " " ( [ - "${cfg.package}/bin/agent" + "${lib.getExe cfg.package}" "--disable-auto-update" "--disable-force-update" "--password $(cat ${cfg.passwordFile})" @@ -109,6 +123,8 @@ in ++ lib.optional cfg.skipProcess "--skip-procs" ++ lib.optional cfg.tls "--tls" ++ lib.optional cfg.gpu "--gpu" + ++ lib.optional cfg.temperature "--temperature" + ++ lib.optional cfg.useIPv6CountryCode "--use-ipv6-countrycode" ); wantedBy = [ "multi-user.target" ]; };