summary refs log tree commit diff
path: root/pkgs/data/misc
diff options
context:
space:
mode:
authorNick Cao <nickcao@nichi.co>2023-06-04 00:41:47 +0800
committerNick Cao <nickcao@nichi.co>2023-06-04 00:52:33 +0800
commit41436adde4048bc8603b0b40346463d2ea9fe740 (patch)
tree93d3c4ece61c5d03e7b8cca333319bd6579def85 /pkgs/data/misc
parentf47f0a525cac079318e62fef27439f17afa18e7a (diff)
downloadnixpkgs-41436adde4048bc8603b0b40346463d2ea9fe740.tar
nixpkgs-41436adde4048bc8603b0b40346463d2ea9fe740.tar.gz
nixpkgs-41436adde4048bc8603b0b40346463d2ea9fe740.tar.bz2
nixpkgs-41436adde4048bc8603b0b40346463d2ea9fe740.tar.lz
nixpkgs-41436adde4048bc8603b0b40346463d2ea9fe740.tar.xz
nixpkgs-41436adde4048bc8603b0b40346463d2ea9fe740.tar.zst
nixpkgs-41436adde4048bc8603b0b40346463d2ea9fe740.zip
v2ray-geoip: build from source with dbip-country-lite
Diffstat (limited to 'pkgs/data/misc')
-rw-r--r--pkgs/data/misc/v2ray-geoip/default.nix73
-rwxr-xr-xpkgs/data/misc/v2ray-geoip/update.sh6
2 files changed, 57 insertions, 22 deletions
diff --git a/pkgs/data/misc/v2ray-geoip/default.nix b/pkgs/data/misc/v2ray-geoip/default.nix
index d7bb9226253..5dbaa6c9c93 100644
--- a/pkgs/data/misc/v2ray-geoip/default.nix
+++ b/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 = "202306010100";
+let
+  generator = pkgsBuildBuild.buildGoModule {
+    pname = "v2ray-geoip";
+    version = "unstable-2023-03-27";
 
-  src = fetchFromGitHub {
-    owner = "v2fly";
-    repo = "geoip";
-    rev = "d8faa6ba0754c083a89898610942d1d1d978ef7f";
-    sha256 = "sha256-Aumk+YPsxZl3F/DQv6w0rE5f5hduLNYApCKQIvRUSIw=";
+    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;
   };
 }
diff --git a/pkgs/data/misc/v2ray-geoip/update.sh b/pkgs/data/misc/v2ray-geoip/update.sh
deleted file mode 100755
index e39012e30a5..00000000000
--- a/pkgs/data/misc/v2ray-geoip/update.sh
+++ /dev/null
@@ -1,6 +0,0 @@
-#! /usr/bin/env nix-shell
-#! nix-shell -i bash -p common-updater-scripts curl jq
-set -euo pipefail
-
-COMMIT=$(curl "https://api.github.com/repos/v2fly/geoip/commits/release?per_page=1")
-update-source-version v2ray-geoip "$(echo $COMMIT | jq -r .commit.message)" --file=pkgs/data/misc/v2ray-geoip/default.nix --rev="$(echo $COMMIT | jq -r .sha)"