summary refs log tree commit diff
path: root/pkgs/tools/misc/mongodb-tools/default.nix
blob: fd95faa40e15f18a8105e36d8a6f21b07f4197e2 (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
{ stdenv
, lib
, buildGoPackage
, fetchFromGitHub
, openssl_1_0_2
, pkgconfig
, libpcap
}:

let
  tools = [
    "bsondump"
    "mongoimport"
    "mongoexport"
    "mongodump"
    "mongorestore"
    "mongostat"
    "mongofiles"
    "mongotop"
    "mongoreplay"
  ];
  version = "4.2.0";

in buildGoPackage {
  pname = "mongo-tools";
  inherit version;

  goPackagePath = "github.com/mongodb/mongo-tools";
  subPackages = tools;

  src = fetchFromGitHub {
    rev = "r${version}";
    owner = "mongodb";
    repo = "mongo-tools";
    sha256 = "0mjwvx0cxvb6zam6jyr3753xjnwcygxcjzqhhlsq0b3xnwws9yh7";
  };

  nativeBuildInputs = [ pkgconfig ];
  buildInputs = [ openssl_1_0_2 libpcap ];

  # Mongodb incorrectly names all of their binaries main
  # Let's work around this with our own installer
  buildPhase = ''
    # move vendored codes so nixpkgs go builder could find it
    runHook preBuild

    ${stdenv.lib.concatMapStrings (t: ''
      go build -o "$bin/bin/${t}" -tags ssl -ldflags "-s -w" $goPackagePath/${t}/main
    '') tools}

    runHook postBuild
  '';

  meta = {
    homepage = https://github.com/mongodb/mongo-tools;
    description = "Tools for the MongoDB";
    license = lib.licenses.asl20;
  };
}