about summary refs log tree commit diff
path: root/nixpkgs/pkgs/servers/sql/proxysql/default.nix
blob: 891ee8e5313489f497353780460e0e5669919c49 (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
{ stdenv
, lib
, applyPatches
, fetchFromGitHub
, autoconf
, automake
, bison
, cmake
, libtool
, civetweb
, coreutils
, curl
, flex
, gnutls
, libconfig
, libdaemon
, libev
, libgcrypt
, libinjection
, libmicrohttpd
, libuuid
, lz4
, nlohmann_json
, openssl
, pcre
, perl
, python3
, prometheus-cpp
, zlib
, texinfo
}:

stdenv.mkDerivation (finalAttrs: {
  pname = "proxysql";
  version = "2.6.0";

  src = fetchFromGitHub {
    owner = "sysown";
    repo = "proxysql";
    rev = finalAttrs.version;
    hash = "sha256-vFPTBSp5DPNRuhtSD34ah2074almS+jiYxBE1L9Pz6g=";
  };

  patches = [
    ./makefiles.patch
    ./dont-phone-home.patch
  ];

  nativeBuildInputs = [
    autoconf
    automake
    cmake
    libtool
    perl
    python3
    texinfo  # for makeinfo
  ];

  buildInputs = [
    bison
    curl
    flex
    gnutls
    libgcrypt
    libuuid
    zlib
  ];

  enableParallelBuilding = true;

  GIT_VERSION = finalAttrs.version;

  dontConfigure = true;

  # replace and fix some vendored dependencies
  preBuild = /* sh */ ''
    pushd deps

    function replace_dep() {
      local folder="$1"
      local src="$2"
      local symlink="$3"
      local name="$4"

      pushd "$folder"

      rm -rf "$symlink"
      if [ -d "$src" ]; then
        cp -R "$src"/. "$symlink"
        chmod -R u+w "$symlink"
      else
        tar xf "$src"
        ln -s "$name" "$symlink"
      fi

      popd
    }

    ${lib.concatMapStringsSep "\n"
      (x: ''replace_dep "${x.f}" "${x.p.src}" "${x.p.pname or (builtins.parseDrvName x.p.name).name}" "${x.p.name}"'') (
        map (x: {
          inherit (x) f;
          p = x.p // {
            src = applyPatches {
              inherit (x.p) src patches;
            };
          };
        }) [
          { f = "curl"; p = curl; }
          { f = "libconfig"; p = libconfig; }
          { f = "libdaemon"; p = libdaemon; }
          { f = "libev"; p = libev; }
          { f = "libinjection"; p = libinjection; }
          { f = "libmicrohttpd"; p = libmicrohttpd; }
          { f = "libssl"; p = openssl; }
          { f = "lz4"; p = lz4; }
          { f = "pcre"; p = pcre; }
          { f = "prometheus-cpp"; p = prometheus-cpp; }
        ]
      )}

    pushd libhttpserver
    tar xf libhttpserver-*.tar.gz
    sed -i s_/bin/pwd_${coreutils}/bin/pwd_g libhttpserver/configure.ac
    popd

    pushd json
    rm json.hpp
    ln -s ${nlohmann_json.src}/single_include/nlohmann/json.hpp .
    popd

    pushd prometheus-cpp/prometheus-cpp/3rdparty
    replace_dep . "${civetweb.src}" civetweb
    popd

    sed -i s_/usr/bin/env_${coreutils}/bin/env_g libssl/openssl/config

    pushd libmicrohttpd/libmicrohttpd
    autoreconf
    popd

    pushd libconfig/libconfig
    autoreconf
    popd

    pushd libdaemon/libdaemon
    autoreconf
    popd

    pushd pcre/pcre
    autoreconf
    popd

    popd
    patchShebangs .
  '';

  preInstall = ''
    mkdir -p $out/{etc,bin,lib/systemd/system}
  '';

  postInstall = ''
    sed -i s_/usr/bin/proxysql_$out/bin/proxysql_ $out/lib/systemd/system/*.service
  '';

  meta = with lib; {
    broken = stdenv.isDarwin;
    description = "High-performance MySQL proxy";
    homepage = "https://proxysql.com/";
    license = with licenses; [ gpl3Only ];
    maintainers = teams.helsinki-systems.members;
    platforms = platforms.unix;
  };
})