about summary refs log tree commit diff
path: root/nixpkgs/pkgs/data/misc/v2ray-geoip/default.nix
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/data/misc/v2ray-geoip/default.nix')
-rw-r--r--nixpkgs/pkgs/data/misc/v2ray-geoip/default.nix73
1 files changed, 57 insertions, 16 deletions
diff --git a/nixpkgs/pkgs/data/misc/v2ray-geoip/default.nix b/nixpkgs/pkgs/data/misc/v2ray-geoip/default.nix
index 0788bff7f368..5dbaa6c9c93b 100644
--- a/nixpkgs/pkgs/data/misc/v2ray-geoip/default.nix
+++ b/nixpkgs/pkgs/data/misc/v2ray-geoip/default.nix
@@ -1,28 +1,69 @@
-{ lib, stdenv, fetchFromGitHub }:
+{ lib
+, stdenvNoCC
+, fetchFromGitHub
+, pkgsBuildBuild
+, jq
+, moreutils
+, dbip-country-lite
+}:
 
-stdenv.mkDerivation rec {
-  pname = "v2ray-geoip";
-  version = "202208040058";
+let
+  generator = pkgsBuildBuild.buildGoModule {
+    pname = "v2ray-geoip";
+    version = "unstable-2023-03-27";
 
-  src = fetchFromGitHub {
-    owner = "v2fly";
-    repo = "geoip";
-    rev = "97174fe0eeb28838b0e5e805687d230df773e661";
-    sha256 = "sha256-hodJ4HQHbv9voSS847pAHd3YSmfkV7fKyJhEUApVN+w=";
+    src = fetchFromGitHub {
+      owner = "v2fly";
+      repo = "geoip";
+      rev = "9321a7f5e301a957228eba44845144b4555b6658";
+      hash = "sha256-S30XEgzA9Vrq7I7REfO/WN/PKpcjcI7KZnrL4uw/Chs=";
+    };
+
+    vendorHash = "sha256-bAXeA1pDIUuEvzTLydUIX6S6fm6j7CUQmBG+7xvxUcc=";
+
+    meta = with lib; {
+      description = "GeoIP for V2Ray";
+      homepage = "https://github.com/v2fly/geoip";
+      license = licenses.cc-by-sa-40;
+      maintainers = with maintainers; [ nickcao ];
+    };
   };
+  input = {
+    type = "maxmindMMDB";
+    action = "add";
+    args = {
+      uri = dbip-country-lite.mmdb;
+    };
+  };
+in
+stdenvNoCC.mkDerivation {
+  inherit (generator) pname src;
+  inherit (dbip-country-lite) version;
+
+  nativeBuildInputs = [
+    jq
+    moreutils
+  ];
+
+  postPatch = ''
+    jq '.input[0] |= ${builtins.toJSON input}' config.json | sponge config.json
+  '';
+
+  buildPhase = ''
+    runHook preBuild
+    ${generator}/bin/geoip
+    runHook postBuild
+  '';
 
   installPhase = ''
     runHook preInstall
-    install -m 0644 geoip.dat -D $out/share/v2ray/geoip.dat
+    install -Dm444 -t "$out/share/v2ray" output/dat/{cn,geoip-only-cn-private,geoip,private}.dat
     runHook postInstall
   '';
 
-  passthru.updateScript = ./update.sh;
+  passthru.generator = generator;
 
-  meta = with lib; {
-    description = "GeoIP for V2Ray";
-    homepage = "https://github.com/v2fly/geoip";
-    license = licenses.cc-by-sa-40;
-    maintainers = with maintainers; [ nickcao ];
+  meta = generator.meta // {
+    inherit (dbip-country-lite.meta) license;
   };
 }