@@ -1,55 +1,135 @@
1−{ stdenv, fetchurl, cmake, ncurses, zlib, xz, lzo, lz4, bzip2, snappy
1+{ stdenv, fetchurl, cmake, pkgconfig, ncurses, zlib, xz, lzo, lz4, bzip2, snappy
22, openssl, pcre, boost, judy, bison, libxml2
33, libaio, libevent, groff, jemalloc, cracklib, systemd, numactl, perl
44, fixDarwinDylibNames, cctools, CoreServices
5−, makeWrapper
65}:
76
87with stdenv.lib;
9−stdenv.mkDerivation rec {
10− name = "mariadb-${version}";
11− version = "10.1.9";
8+
9+let # in mariadb # spans the whole file
10+
11+mariadb = {
12+ inherit client # libmysqlclient.so in .out, necessary headers in .dev and utils in .bin
13+ server; # currently a full build, including everything in `client` again
14+ lib = client; # compat. with the old mariadb split
15+};
16+
17+
18+common = rec { # attributes common to both builds
19+ version = "10.1.16";
1220
1321 src = fetchurl {
1422 url = "https://downloads.mariadb.org/interstitial/mariadb-${version}/source/mariadb-${version}.tar.gz";
15− sha256 = "0471vwg9c5c17m7679krjha16ib6d48fcsphkchb9v9cf8k5i74f";
23+ sha256 = "14s3wq1c25n62n75hkixl8n7cni4m73w055nsx4czm655k33bjv7";
1624 };
1725
26+ prePatch = ''
27+ substituteInPlace cmake/libutils.cmake \
28+ --replace /usr/bin/libtool libtool
29+ sed -i 's,[^"]*/var/log,/var/log,g' storage/mroonga/vendor/groonga/CMakeLists.txt
30+ '';
31+
32+ patches = stdenv.lib.optional stdenv.isDarwin ./my_context_asm.patch;
33+
34+ nativeBuildInputs = [ cmake pkgconfig ];
35+
1836 buildInputs = [
19− cmake ncurses openssl zlib xz lzo lz4 bzip2
20− # temporary due to https://mariadb.atlassian.net/browse/MDEV-9000
21− (if stdenv.is64bit then snappy else null)
22− pcre libxml2 boost judy bison libevent cracklib
23− makeWrapper
37+ ncurses openssl zlib pcre
2438 ] ++ stdenv.lib.optionals stdenv.isLinux [ jemalloc libaio systemd ]
25− ++ stdenv.lib.optionals (stdenv.isLinux && !stdenv.isArm) [ numactl ]
2639 ++ stdenv.lib.optionals stdenv.isDarwin [ perl fixDarwinDylibNames cctools CoreServices ];
2740
28− patches = stdenv.lib.optional stdenv.isDarwin ./my_context_asm.patch;
29−
3041 cmakeFlags = [
3142 "-DBUILD_CONFIG=mysql_release"
43+ "-DMANUFACTURER=NixOS.org"
3244 "-DDEFAULT_CHARSET=utf8"
3345 "-DDEFAULT_COLLATION=utf8_general_ci"
34− "-DENABLED_LOCAL_INFILE=ON"
46+ "-DSECURITY_HARDENED=ON"
47+
3548 "-DMYSQL_UNIX_ADDR=/run/mysqld/mysqld.sock"
49+ "-DINSTALL_MYSQLSHAREDIR=share/mysql"
50+
51+ "-DWITH_ZLIB=system"
52+ "-DWITH_SSL=system"
53+ "-DWITH_PCRE=system"
54+ ]
55+ ++ optional stdenv.isDarwin "-DCURSES_LIBRARY=${ncurses.out}/lib/libncurses.dylib"
56+ ;
57+
58+ preConfigure = ''
59+ cmakeFlags="$cmakeFlags -DINSTALL_INCLUDEDIR=''${!outputDev}/include/mysql"
60+ '';
61+
62+ postInstall = ''
63+ rm "$out"/lib/*.a
64+ find "''${!outputBin}/bin" -name '*test*' -delete
65+ '';
66+
67+ passthru.mysqlVersion = "5.6";
68+
69+ meta = with stdenv.lib; {
70+ description = "An enhanced, drop-in replacement for MySQL";
71+ homepage = https://mariadb.org/;
72+ license = licenses.gpl2;
73+ maintainers = with maintainers; [ thoughtpolice wkennington ];
74+ platforms = platforms.all;
75+ };
76+};
77+
78+
79+client = stdenv.mkDerivation (common // {
80+ name = "mariadb-client-${common.version}";
81+
82+ outputs = [ "dev" "out" "bin" ];
83+
84+ propagatedBuildInputs = [ openssl zlib ]; # required from mariadb.pc
85+
86+ cmakeFlags = common.cmakeFlags ++ [
87+ "-DWITHOUT_SERVER=ON"
88+ ];
89+
90+ preConfigure = common.preConfigure + ''
91+ cmakeFlags="$cmakeFlags \
92+ -DINSTALL_BINDIR=$bin/bin -DINSTALL_SCRIPTDIR=$bin/bin \
93+ -DINSTALL_SUPPORTFILESDIR=$bin/share/mysql \
94+ -DINSTALL_DOCDIR=$bin/share/doc/mysql -DINSTALL_DOCREADMEDIR=$bin/share/doc/mysql \
95+ "
96+ '';
97+
98+ # prevent cycle; it needs to reference $dev
99+ postInstall = common.postInstall + ''
100+ moveToOutput bin/mysql_config "$dev"
101+ '';
102+
103+ enableParallelBuilding = true; # the client should be OK
104+});
105+
106+
107+server = stdenv.mkDerivation (common // {
108+ name = "mariadb-${common.version}";
109+
110+ nativeBuildInputs = common.nativeBuildInputs ++ [ bison ];
111+
112+ buildInputs = common.buildInputs ++ [
113+ xz lzo lz4 bzip2 snappy
114+ libxml2 boost judy libevent cracklib
115+ ]
116+ ++ optionals (stdenv.isLinux && !stdenv.isArm) [ numactl ]
117+ ;
118+
119+ cmakeFlags = common.cmakeFlags ++ [
36120 "-DMYSQL_DATADIR=/var/lib/mysql"
37121 "-DINSTALL_SYSCONFDIR=etc/mysql"
38122 "-DINSTALL_INFODIR=share/mysql/docs"
39123 "-DINSTALL_MANDIR=share/man"
40124 "-DINSTALL_PLUGINDIR=lib/mysql/plugin"
41125 "-DINSTALL_SCRIPTDIR=bin"
42− "-DINSTALL_INCLUDEDIR=include/mysql"
43− "-DINSTALL_DOCREADMEDIR=share/mysql"
44126 "-DINSTALL_SUPPORTFILESDIR=share/mysql"
45− "-DINSTALL_MYSQLSHAREDIR=share/mysql"
46− "-DINSTALL_DOCDIR=share/mysql/docs"
127+ "-DINSTALL_DOCREADMEDIR=share/doc/mysql"
128+ "-DINSTALL_DOCDIR=share/doc/mysql"
47129 "-DINSTALL_SHAREDIR=share/mysql"
130+
131+ "-DENABLED_LOCAL_INFILE=ON"
48132 "-DWITH_READLINE=ON"
49− "-DWITH_ZLIB=system"
50− "-DWITH_SSL=system"
51− "-DWITH_PCRE=system"
52− "-DWITH_EMBEDDED_SERVER=yes"
53133 "-DWITH_EXTRA_CHARSETS=complex"
54134 "-DWITH_EMBEDDED_SERVER=ON"
55135 "-DWITH_ARCHIVE_STORAGE_ENGINE=1"
@@ -58,83 +138,17 @@ stdenv.mkDerivation rec {
58138 "-DWITH_PARTITION_STORAGE_ENGINE=1"
59139 "-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1"
60140 "-DWITHOUT_FEDERATED_STORAGE_ENGINE=1"
61− "-DSECURITY_HARDENED=ON"
62141 "-DWITH_WSREP=ON"
63142 ] ++ stdenv.lib.optionals stdenv.isDarwin [
64143 "-DWITHOUT_OQGRAPH_STORAGE_ENGINE=1"
65144 "-DWITHOUT_TOKUDB=1"
66− "-DCURSES_LIBRARY=${ncurses.out}/lib/libncurses.dylib"
67145 ];
68146
69− # fails to find lex_token.h sometimes
70− enableParallelBuilding = false;
71−
72− outputs = [ "out" "lib" ];
73− setOutputFlags = false;
74− moveToDev = false;
75−
76− prePatch = ''
77− substituteInPlace cmake/libutils.cmake \
78− --replace /usr/bin/libtool libtool
79− sed -i "s,SET(DEFAULT_MYSQL_HOME.*$,SET(DEFAULT_MYSQL_HOME /not/a/real/dir),g" CMakeLists.txt
80− sed -i "s,SET(PLUGINDIR.*$,SET(PLUGINDIR $lib/lib/mysql/plugin),g" CMakeLists.txt
81−
82− sed -i "s,SET(pkgincludedir.*$,SET(pkgincludedir $lib/include),g" scripts/CMakeLists.txt
83− sed -i "s,SET(pkglibdir.*$,SET(pkglibdir $lib/lib),g" scripts/CMakeLists.txt
84− sed -i "s,SET(pkgplugindir.*$,SET(pkgplugindir $lib/lib/mysql/plugin),g" scripts/CMakeLists.txt
85−
86− sed -i "s,set(libdir.*$,SET(libdir $lib/lib),g" storage/mroonga/vendor/groonga/CMakeLists.txt
87− sed -i "s,set(includedir.*$,SET(includedir $lib/include),g" storage/mroonga/vendor/groonga/CMakeLists.txt
88− sed -i "/\"\$[{]CMAKE_INSTALL_PREFIX}\/\$[{]GRN_RELATIVE_PLUGINS_DIR}\"/d" storage/mroonga/vendor/groonga/CMakeLists.txt
89− sed -i "s,set(GRN_PLUGINS_DIR.*$,SET(GRN_PLUGINS_DIR $lib/\$\{GRN_RELATIVE_PLUGINS_DIR}),g" storage/mroonga/vendor/groonga/CMakeLists.txt
90− sed -i 's,[^"]*/var/log,/var/log,g' storage/mroonga/vendor/groonga/CMakeLists.txt
147+ postInstall = common.postInstall + ''
148+ rm -r "$out"/{mysql-test,sql-bench,data} # Don't need testing data
149+ rm "$out"/share/man/man1/mysql-test-run.pl.1
91150 '';
151+});
92152
93− postInstall = ''
94− substituteInPlace $out/bin/mysql_install_db \
95− --replace basedir=\"\" basedir=\"$out\"
96−
97− # Wrap mysqld with --basedir, but as last flag
98− wrapProgram $out/bin/mysqld
99− sed -i "s,\(^exec.*$\),\1 --basedir=$out,g" $out/bin/mysqld
100−
101− # Remove superfluous files
102− rm -r $out/mysql-test $out/sql-bench $out/data # Don't need testing data
103− rm $out/share/man/man1/mysql-test-run.pl.1
104− rm $out/bin/rcmysql # Not needed with nixos units
105− rm $out/bin/mysqlbug # Encodes a path to gcc and not really useful
106− find $out/bin -name \*test\* -exec rm {} \;
107−
108− # Separate libs and includes into their own derivation
109− mkdir -p $lib
110− mv $out/lib $lib
111− mv $out/include $lib
112−
113− # Fix the mysql_config
114− sed -i $out/bin/mysql_config \
115− -e 's,-lz,-L${zlib.out}/lib -lz,g' \
116− -e 's,-lssl,-L${openssl.out}/lib -lssl,g'
117−
118− # Add mysql_config to libs since configure scripts use it
119− mkdir -p $lib/bin
120− cp $out/bin/mysql_config $lib/bin
121− sed -i "/\(execdir\|bindir\)/ s,'[^\"']*',$lib/bin,g" $lib/bin/mysql_config
122−
123− # Make sure to propagate lib for compatability
124− mkdir -p $out/nix-support
125− echo "$lib" > $out/nix-support/propagated-native-build-inputs
126−
127− # Don't install static libraries.
128− rm $lib/lib/libmysqlclient.a $lib/lib/libmysqld.a
129− '';
130−
131− passthru.mysqlVersion = "5.6";
153+in mariadb
132154
133− meta = with stdenv.lib; {
134− description = "An enhanced, drop-in replacement for MySQL";
135− homepage = https://mariadb.org/;
136− license = stdenv.lib.licenses.gpl2;
137− maintainers = with stdenv.lib.maintainers; [ thoughtpolice wkennington ];
138− platforms = stdenv.lib.platforms.all;
139− };
140−}