about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/libraries/geoip/default.nix
blob: 4b12871e55678f90d4d073f4e1abfd85e2df0d6f (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
{ lib
, stdenv
, fetchFromGitHub
, autoreconfHook
, drvName ? "geoip"

  # in geoipDatabase, you can insert a package defining
  # "${geoipDatabase}/share/GeoIP" e.g. geolite-legacy
, geoipDatabase ? "/var/lib/geoip-databases"
}:

let
  dataDir =
    if lib.isDerivation geoipDatabase
    then "${toString geoipDatabase}/share/GeoIP"
    else geoipDatabase;

in
stdenv.mkDerivation rec {
  pname = drvName;
  version = "1.6.12";

  src = fetchFromGitHub {
    owner = "maxmind";
    repo = "geoip-api-c";
    rev = "v${version}";
    sha256 = "0ixyp3h51alnncr17hqp1p0rlqz9w69nlhm60rbzjjz3vjx52ajv";
  };

  nativeBuildInputs = [ autoreconfHook ];

  # Cross compilation shenanigans
  configureFlags = lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
    "ac_cv_func_malloc_0_nonnull=yes"
    "ac_cv_func_realloc_0_nonnull=yes"
  ];

  # Fix up the default data directory
  postConfigure = ''
    find . -name Makefile.in -exec sed -i -r 's#^pkgdatadir\s*=.+$#pkgdatadir = ${dataDir}#' {} \;
  '';

  passthru = { inherit dataDir; };

  meta = with lib; {
    description = "An API for GeoIP/Geolocation databases";
    maintainers = with maintainers; [ thoughtpolice raskin ];
    license = licenses.lgpl21;
    platforms = platforms.unix;
    homepage = "https://www.maxmind.com";
  };
}