about summary refs log tree commit diff
path: root/nixpkgs/pkgs/data/misc/sing-geoip/default.nix
blob: b27a61ef02013875be6e61c240a3511bca15b28b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
{ lib
, stdenvNoCC
, buildGoModule
, fetchFromGitHub
, dbip-country-lite
}:

let
  generator = buildGoModule rec {
    pname = "sing-geoip";
    version = "20230512";

    src = fetchFromGitHub {
      owner = "SagerNet";
      repo = pname;
      rev = "refs/tags/${version}";
      hash = "sha256-Zm+5N/37hoHpH/TLNJrHeaBXI8G1jEpM1jz6Um8edNE=";
    };

    vendorHash = "sha256-ejXAdsJwXhqet+Ca+pDLWwu0gex79VcIxW6rmhRnbTQ=";

    meta = with lib; {
      description = "GeoIP data for sing-box";
      homepage = "https://github.com/SagerNet/sing-geoip";
      license = licenses.gpl3Plus;
      maintainers = with maintainers; [ linsui ];
    };
  };
in
stdenvNoCC.mkDerivation rec {
  inherit (generator) pname;
  inherit (dbip-country-lite) version;

  dontUnpack = true;

  nativeBuildInputs = [ generator ];

  buildPhase = ''
    runHook preBuild

    ${pname} ${dbip-country-lite.mmdb} geoip.db
    ${pname} ${dbip-country-lite.mmdb} geoip-cn.db cn

    runHook postBuild
  '';

  installPhase = ''
    runHook preInstall

    install -Dm644 geoip.db $out/share/sing-box/geoip.db
    install -Dm644 geoip-cn.db $out/share/sing-box/geoip-cn.db

    runHook postInstall
  '';

  passthru = { inherit generator; };

  meta = generator.meta // {
    inherit (dbip-country-lite.meta) license;
  };
}