@@ -1,55 +1,133 @@
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 = 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+ 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+ nativeBuildInputs = [ cmake pkgconfig ];
33+
1834 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
35+ ncurses openssl zlib pcre
2436 ] ++ stdenv.lib.optionals stdenv.isLinux [ jemalloc libaio systemd ]
25− ++ stdenv.lib.optionals (stdenv.isLinux && !stdenv.isArm) [ numactl ]
2637 ++ stdenv.lib.optionals stdenv.isDarwin [ perl fixDarwinDylibNames cctools CoreServices ];
2738
28− patches = stdenv.lib.optional stdenv.isDarwin ./my_context_asm.patch;
29−
3039 cmakeFlags = [
3140 "-DBUILD_CONFIG=mysql_release"
41+ "-DMANUFACTURER=NixOS.org"
3242 "-DDEFAULT_CHARSET=utf8"
3343 "-DDEFAULT_COLLATION=utf8_general_ci"
34− "-DENABLED_LOCAL_INFILE=ON"
44+ "-DSECURITY_HARDENED=ON"
45+
3546 "-DMYSQL_UNIX_ADDR=/run/mysqld/mysqld.sock"
47+ "-DINSTALL_MYSQLSHAREDIR=share/mysql"
48+
49+ "-DWITH_ZLIB=system"
50+ "-DWITH_SSL=system"
51+ "-DWITH_PCRE=system"
52+ ]
53+ ++ optional stdenv.isDarwin "-DCURSES_LIBRARY=${ncurses.out}/lib/libncurses.dylib"
54+ ;
55+
56+ preConfigure = ''
57+ cmakeFlags="$cmakeFlags -DINSTALL_INCLUDEDIR=''${!outputDev}/include/mysql"
58+ '';
59+
60+ postInstall = ''
61+ rm "$out"/lib/*.a
62+ find "''${!outputBin}/bin" -name '*test*' -delete
63+ '';
64+
65+ passthru.mysqlVersion = "5.6";
66+
67+ meta = with stdenv.lib; {
68+ description = "An enhanced, drop-in replacement for MySQL";
69+ homepage = https://mariadb.org/;
70+ license = licenses.gpl2;
71+ maintainers = with maintainers; [ thoughtpolice wkennington ];
72+ platforms = platforms.all;
73+ };
74+};
75+
76+
77+client = stdenv.mkDerivation (common // {
78+ name = "mariadb-client-${common.version}";
79+
80+ outputs = [ "dev" "out" "bin" ];
81+
82+ propagatedBuildInputs = [ openssl zlib ]; # required from mariadb.pc
83+
84+ cmakeFlags = common.cmakeFlags ++ [
85+ "-DWITHOUT_SERVER=ON"
86+ ];
87+
88+ preConfigure = common.preConfigure + ''
89+ cmakeFlags="$cmakeFlags \
90+ -DINSTALL_BINDIR=$bin/bin -DINSTALL_SCRIPTDIR=$bin/bin \
91+ -DINSTALL_SUPPORTFILESDIR=$bin/share/mysql \
92+ -DINSTALL_DOCDIR=$bin/share/doc/mysql -DINSTALL_DOCREADMEDIR=$bin/share/doc/mysql \
93+ "
94+ '';
95+
96+ # prevent cycle; it needs to reference $dev
97+ postInstall = common.postInstall + ''
98+ moveToOutput bin/mysql_config "$dev"
99+ '';
100+
101+ enableParallelBuilding = true; # the client should be OK
102+});
103+
104+
105+everything = stdenv.mkDerivation (common // {
106+ name = "mariadb-${common.version}";
107+
108+ nativeBuildInputs = common.nativeBuildInputs ++ [ bison ];
109+
110+ buildInputs = common.buildInputs ++ [
111+ xz lzo lz4 bzip2 snappy
112+ libxml2 boost judy libevent cracklib
113+ ]
114+ ++ optionals (stdenv.isLinux && !stdenv.isArm) [ numactl ]
115+ ;
116+
117+ cmakeFlags = common.cmakeFlags ++ [
36118 "-DMYSQL_DATADIR=/var/lib/mysql"
37119 "-DINSTALL_SYSCONFDIR=etc/mysql"
38120 "-DINSTALL_INFODIR=share/mysql/docs"
39121 "-DINSTALL_MANDIR=share/man"
40122 "-DINSTALL_PLUGINDIR=lib/mysql/plugin"
41123 "-DINSTALL_SCRIPTDIR=bin"
42− "-DINSTALL_INCLUDEDIR=include/mysql"
43− "-DINSTALL_DOCREADMEDIR=share/mysql"
44124 "-DINSTALL_SUPPORTFILESDIR=share/mysql"
45− "-DINSTALL_MYSQLSHAREDIR=share/mysql"
46− "-DINSTALL_DOCDIR=share/mysql/docs"
125+ "-DINSTALL_DOCREADMEDIR=share/doc/mysql"
126+ "-DINSTALL_DOCDIR=share/doc/mysql"
47127 "-DINSTALL_SHAREDIR=share/mysql"
128+
129+ "-DENABLED_LOCAL_INFILE=ON"
48130 "-DWITH_READLINE=ON"
49− "-DWITH_ZLIB=system"
50− "-DWITH_SSL=system"
51− "-DWITH_PCRE=system"
52− "-DWITH_EMBEDDED_SERVER=yes"
53131 "-DWITH_EXTRA_CHARSETS=complex"
54132 "-DWITH_EMBEDDED_SERVER=ON"
55133 "-DWITH_ARCHIVE_STORAGE_ENGINE=1"
@@ -58,83 +136,17 @@ stdenv.mkDerivation rec {
58136 "-DWITH_PARTITION_STORAGE_ENGINE=1"
59137 "-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1"
60138 "-DWITHOUT_FEDERATED_STORAGE_ENGINE=1"
61− "-DSECURITY_HARDENED=ON"
62139 "-DWITH_WSREP=ON"
63140 ] ++ stdenv.lib.optionals stdenv.isDarwin [
64141 "-DWITHOUT_OQGRAPH_STORAGE_ENGINE=1"
65142 "-DWITHOUT_TOKUDB=1"
66− "-DCURSES_LIBRARY=${ncurses.out}/lib/libncurses.dylib"
67143 ];
68144
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
145+ postInstall = common.postInstall + ''
146+ rm -r "$out"/{mysql-test,sql-bench,data} # Don't need testing data
147+ rm "$out"/share/man/man1/mysql-test-run.pl.1
91148 '';
149+});
92150
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";
151+in mariadb
132152
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−}