1{ stdenv, fetchurl, cmake, pkgconfig, ncurses, zlib, xz, lzo, lz4, bzip2, snappy
2, libiconv, openssl, pcre, boost, judy, bison, libxml2
3, libaio, libevent, groff, jemalloc, cracklib, systemd, numactl, perl
4, fixDarwinDylibNames, cctools, CoreServices
5}:
6
7with stdenv.lib;
8
9let # in mariadb # spans the whole file
10
11mariadb = everything // {
12 inherit client; # libmysqlclient.so in .out, necessary headers in .dev and utils in .bin
13 server = everything; # a full single-output build, including everything in `client` again
14 inherit connector-c; # libmysqlclient.so
15};
16
17common = rec { # attributes common to both builds
18 version = "10.2.13";
19
20 src = fetchurl {
21 url = "https://downloads.mariadb.org/f/mariadb-${version}/source/mariadb-${version}.tar.gz";
22 sha256 = "0ly7dxc7rk327liya4kalgsw8irlxl0pl8gq0agdl18a63cpwbi7";
23 name = "mariadb-${version}.tar.gz";
24 };
25
26 nativeBuildInputs = [ cmake pkgconfig ];
27
28 buildInputs = [
29 ncurses openssl zlib pcre jemalloc libiconv
30 ] ++ stdenv.lib.optionals stdenv.isLinux [ libaio systemd ]
31 ++ stdenv.lib.optionals stdenv.isDarwin [ perl fixDarwinDylibNames cctools CoreServices ];
32
33 prePatch = ''
34 sed -i 's,[^"]*/var/log,/var/log,g' storage/mroonga/vendor/groonga/CMakeLists.txt
35 '';
36
37 patches = [ ./cmake-includedir.patch ]
38 ++ stdenv.lib.optional stdenv.cc.isClang ./clang-isfinite.patch;
39
40 cmakeFlags = [
41 "-DBUILD_CONFIG=mysql_release"
42 "-DMANUFACTURER=NixOS.org"
43 "-DDEFAULT_CHARSET=utf8"
44 "-DDEFAULT_COLLATION=utf8_general_ci"
45 "-DSECURITY_HARDENED=ON"
46
47 "-DMYSQL_UNIX_ADDR=/run/mysqld/mysqld.sock"
48 "-DINSTALL_MYSQLSHAREDIR=share/mysql"
49
50 "-DWITH_ZLIB=system"
51 "-DWITH_SSL=system"
52 "-DWITH_PCRE=system"
53
54 # On Darwin without sandbox, CMake will find the system java and attempt to build with java support, but
55 # then it will fail during the actual build. Let's just disable the flag explicitly until someone decides
56 # to pass in java explicitly. This should have no effect on Linux.
57 "-DCONNECT_WITH_JDBC=OFF"
58
59 # Same as above. Somehow on Darwin CMake decides that we support GSS even though we aren't provding the
60 # library through Nix, and then breaks later on. This should have no effect on Linux.
61 "-DPLUGIN_AUTH_GSSAPI=NO"
62 "-DPLUGIN_AUTH_GSSAPI_CLIENT=NO"
63 ]
64 ++ optional stdenv.isDarwin "-DCURSES_LIBRARY=${ncurses.out}/lib/libncurses.dylib"
65 ++ optional stdenv.hostPlatform.isMusl "-DWITHOUT_TOKUDB=1" # mariadb docs say disable this for musl
66 ;
67
68 preConfigure = ''
69 cmakeFlags="$cmakeFlags -DINSTALL_INCLUDEDIR=''${!outputDev}/include/mysql"
70 '';
71
72 postInstall = ''
73 rm "$out"/lib/*.a
74 find "''${!outputBin}/bin" -name '*test*' -delete
75 '';
76
77 passthru.mysqlVersion = "5.7";
78
79 meta = with stdenv.lib; {
80 description = "An enhanced, drop-in replacement for MySQL";
81 homepage = https://mariadb.org/;
82 license = licenses.gpl2;
83 maintainers = with maintainers; [ thoughtpolice wkennington ];
84 platforms = platforms.all;
85 };
86};
87
88client = stdenv.mkDerivation (common // {
89 name = "mariadb-client-${common.version}";
90
91 outputs = [ "bin" "dev" "out" ];
92
93 propagatedBuildInputs = [ openssl zlib ]; # required from mariadb.pc
94
95 cmakeFlags = common.cmakeFlags ++ [
96 "-DWITHOUT_SERVER=ON"
97 ];
98
99 preConfigure = common.preConfigure + ''
100 cmakeFlags="$cmakeFlags \
101 -DINSTALL_BINDIR=$bin/bin \
102 -DINSTALL_SCRIPTDIR=$bin/bin \
103 -DINSTALL_SUPPORTFILESDIR=$bin/share/mysql \
104 -DINSTALL_DOCDIR=$bin/share/doc/mysql \
105 -DINSTALL_DOCREADMEDIR=$bin/share/doc/mysql \
106 "
107 '';
108
109 # prevent cycle; it needs to reference $dev
110 postInstall = common.postInstall + ''
111 moveToOutput bin/mysql_config "$dev"
112 moveToOutput bin/mariadb_config "$dev"
113 '';
114
115 enableParallelBuilding = true; # the client should be OK
116});
117
118everything = stdenv.mkDerivation (common // {
119 name = "mariadb-${common.version}";
120
121 nativeBuildInputs = common.nativeBuildInputs ++ [ bison ];
122
123 buildInputs = common.buildInputs ++ [
124 xz lzo lz4 bzip2 snappy
125 libxml2 boost judy libevent cracklib
126 ] ++ optional (stdenv.isLinux && !stdenv.isArm) numactl;
127
128 cmakeFlags = common.cmakeFlags ++ [
129 "-DMYSQL_DATADIR=/var/lib/mysql"
130 "-DINSTALL_SYSCONFDIR=etc/mysql"
131 "-DINSTALL_INFODIR=share/mysql/docs"
132 "-DINSTALL_MANDIR=share/man"
133 "-DINSTALL_PLUGINDIR=lib/mysql/plugin"
134 "-DINSTALL_SCRIPTDIR=bin"
135 "-DINSTALL_SUPPORTFILESDIR=share/mysql"
136 "-DINSTALL_DOCREADMEDIR=share/doc/mysql"
137 "-DINSTALL_DOCDIR=share/doc/mysql"
138 "-DINSTALL_SHAREDIR=share/mysql"
139 "-DINSTALL_MYSQLTESTDIR=OFF"
140 "-DINSTALL_SQLBENCHDIR=OFF"
141
142 "-DENABLED_LOCAL_INFILE=ON"
143 "-DWITH_READLINE=ON"
144 "-DWITH_EXTRA_CHARSETS=complex"
145 "-DWITH_EMBEDDED_SERVER=ON"
146 "-DWITH_ARCHIVE_STORAGE_ENGINE=1"
147 "-DWITH_BLACKHOLE_STORAGE_ENGINE=1"
148 "-DWITH_INNOBASE_STORAGE_ENGINE=1"
149 "-DWITH_PARTITION_STORAGE_ENGINE=1"
150 "-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1"
151 "-DWITHOUT_FEDERATED_STORAGE_ENGINE=1"
152 "-DWITH_WSREP=ON"
153 ] ++ stdenv.lib.optionals stdenv.isDarwin [
154 "-DWITHOUT_OQGRAPH_STORAGE_ENGINE=1"
155 "-DWITHOUT_TOKUDB=1"
156 ];
157
158 postInstall = common.postInstall + ''
159 rm -r "$out"/data # Don't need testing data
160 rm "$out"/share/man/man1/mysql-test-run.pl.1
161 rm "$out"/bin/rcmysql
162 '';
163
164 CXXFLAGS = optionalString stdenv.isi686 "-fpermissive"
165 + optionalString stdenv.isDarwin " -std=c++11";
166});
167
168connector-c = stdenv.mkDerivation rec {
169 name = "mariadb-connector-c-${version}";
170 version = "2.3.4";
171
172 src = fetchurl {
173 url = "https://downloads.mariadb.org/interstitial/connector-c-${version}/mariadb-connector-c-${version}-src.tar.gz/from/http%3A//ftp.hosteurope.de/mirror/archive.mariadb.org/?serve";
174 sha256 = "1g1sq5knarxkfhpkcczr6qxmq12pid65cdkqnhnfs94av89hbswb";
175 name = "mariadb-connector-c-${version}-src.tar.gz";
176 };
177
178 # outputs = [ "dev" "out" ]; FIXME: cmake variables don't allow that < 3.0
179 cmakeFlags = [
180 "-DWITH_EXTERNAL_ZLIB=ON"
181 "-DMYSQL_UNIX_ADDR=/run/mysqld/mysqld.sock"
182 ];
183
184 # The cmake setup-hook uses $out/lib by default, this is not the case here.
185 preConfigure = stdenv.lib.optionalString stdenv.isDarwin ''
186 cmakeFlagsArray+=("-DCMAKE_INSTALL_NAME_DIR=$out/lib/mariadb")
187 '';
188
189 nativeBuildInputs = [ cmake ];
190 propagatedBuildInputs = [ openssl zlib ];
191 buildInputs = [ libiconv ];
192
193 enableParallelBuilding = true;
194
195 postFixup = ''
196 ln -sv mariadb_config $out/bin/mysql_config
197 ln -sv mariadb $out/lib/mysql
198 ln -sv mariadb $out/include/mysql
199 '';
200
201 meta = with stdenv.lib; {
202 description = "Client library that can be used to connect to MySQL or MariaDB";
203 license = licenses.lgpl21;
204 maintainers = with maintainers; [ globin ];
205 platforms = platforms.all;
206 };
207};
208
209in mariadb