nezha: init at 0.20.13

This commit is contained in:
Moraxyc 2024-10-30 19:15:08 +08:00
parent 73c671819b
commit 1ef53f5fc0
No known key found for this signature in database
2 changed files with 98 additions and 0 deletions

View File

@ -0,0 +1,36 @@
diff --git a/pkg/geoip/geoip.go b/pkg/geoip/geoip.go
index 6d913b9..13be7f5 100644
--- a/pkg/geoip/geoip.go
+++ b/pkg/geoip/geoip.go
@@ -19,10 +19,12 @@ var (
)
type IPInfo struct {
- Country string `maxminddb:"country"`
- CountryName string `maxminddb:"country_name"`
- Continent string `maxminddb:"continent"`
- ContinentName string `maxminddb:"continent_name"`
+ Country struct {
+ IsoCode string `maxminddb:"iso_code"`
+ } `maxminddb:"country"`
+ Continent struct {
+ Code string `maxminddb:"code"`
+ } `maxminddb:"continent"`
}
func init() {
@@ -44,10 +46,10 @@ func Lookup(ip net.IP, record *IPInfo) (string, error) {
return "", err
}
- if record.Country != "" {
- return strings.ToLower(record.Country), nil
- } else if record.Continent != "" {
- return strings.ToLower(record.Continent), nil
+ if record.Country.IsoCode != "" {
+ return strings.ToLower(record.Country.IsoCode), nil
+ } else if record.Continent.Code != "" {
+ return strings.ToLower(record.Continent.Code), nil
}
return "", fmt.Errorf("IP not found")

View File

@ -0,0 +1,62 @@
{
lib,
buildGoModule,
fetchFromGitHub,
versionCheckHook,
dbip-country-lite,
nix-update-script,
}:
buildGoModule rec {
pname = "nezha";
version = "0.20.13";
src = fetchFromGitHub {
owner = "naiba";
repo = "nezha";
rev = "refs/tags/v${version}";
hash = "sha256-fJvL2cESQoiW93aj2RHPyZXvP8246Mf8hIRiP/DSRRY=";
};
postPatch = ''
cp ${dbip-country-lite.mmdb} pkg/geoip/geoip.db
'';
patches = [
# Nezha originally used ipinfo.mmdb to provide geoip query feature.
# Unfortunately, ipinfo.mmdb must be downloaded with token.
# Therefore, we patch the nezha to use dbip-country-lite.mmdb in nixpkgs.
./dbip.patch
];
vendorHash = "sha256-SYefkgc0CsAEdkL7rxu9fpz7dpBnx1LwabIadUeOKco=";
ldflags = [
"-s"
"-w"
"-X github.com/naiba/nezha/service/singleton.Version=${version}"
];
checkFlags = "-skip=^TestSplitDomainSOA$";
postInstall = ''
mv $out/bin/dashboard $out/bin/nezha
'';
nativeInstallCheckInputs = [
versionCheckHook
];
versionCheckProgramArg = [ "--version" ];
doInstallCheck = true;
passthru.updateScript = nix-update-script { };
meta = {
description = "Self-hosted, lightweight server and website monitoring and O&M tool";
homepage = "https://github.com/naiba/nezha";
changelog = "https://github.com/naiba/nezha/releases/tag/v${version}";
license = lib.licenses.asl20;
maintainers = with lib.maintainers; [ moraxyc ];
mainProgram = "nezha";
};
}