2 # shared across all versions
5 , lib, stdenv, fetchurl, nixosTests, buildPackages
6 # Native buildInputs components
7 , bison, boost, cmake, fixDarwinDylibNames, flex, makeWrapper, pkg-config
9 , curl, libiconv, ncurses, openssl, pcre2
10 , libkrb5, libaio, liburing, systemd
11 , CoreServices, cctools, perl
12 , jemalloc, less, libedit
14 , bzip2, lz4, lzo, snappy, xz, zlib, zstd
15 , cracklib, judy, libevent, libxml2
18 , withStorageMroonga ? true, kytea, libsodium, msgpack, zeromq
19 , withStorageRocks ? true
20 , withEmbedded ? false
25 isCross = stdenv.buildPlatform != stdenv.hostPlatform;
27 libExt = stdenv.hostPlatform.extensions.sharedLibrary;
29 mytopEnv = buildPackages.perl.withPackages (p: with p; [ DBDmysql DBI TermReadKey ]);
31 common = rec { # attributes common to both builds
35 url = "https://downloads.mariadb.com/MariaDB/mariadb-${version}/source/mariadb-${version}.tar.gz";
39 outputs = [ "out" "man" ];
41 nativeBuildInputs = [ cmake pkg-config ]
42 ++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames
43 ++ lib.optional (!stdenv.hostPlatform.isDarwin) makeWrapper;
50 ] ++ lib.optionals stdenv.hostPlatform.isLinux ([ libkrb5 systemd ]
51 ++ (if (lib.versionOlder version "10.6") then [ libaio ] else [ liburing ]))
52 ++ lib.optionals stdenv.hostPlatform.isDarwin [ CoreServices cctools perl libedit ]
53 ++ lib.optionals (!stdenv.hostPlatform.isDarwin) [ jemalloc ];
56 sed -i 's,[^"]*/var/log,/var/log,g' storage/mroonga/vendor/groonga/CMakeLists.txt
60 ./patch/cmake-includedir.patch
62 # Fixes a build issue as documented on
63 # https://jira.mariadb.org/browse/MDEV-26769?focusedCommentId=206073&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-206073
64 ++ lib.optional (!stdenv.hostPlatform.isLinux && lib.versionAtLeast version "10.6") ./patch/macos-MDEV-26769-regression-fix.patch;
67 "-DBUILD_CONFIG=mysql_release"
68 "-DMANUFACTURER=nixos.org"
69 "-DDEFAULT_CHARSET=utf8mb4"
70 "-DDEFAULT_COLLATION=utf8mb4_unicode_ci"
71 "-DSECURITY_HARDENED=ON"
73 "-DINSTALL_UNIX_ADDRDIR=/run/mysqld/mysqld.sock"
74 "-DINSTALL_BINDIR=bin"
75 "-DINSTALL_DOCDIR=share/doc/mysql"
76 "-DINSTALL_DOCREADMEDIR=share/doc/mysql"
77 "-DINSTALL_INCLUDEDIR=include/mysql"
78 "-DINSTALL_LIBDIR=lib"
79 "-DINSTALL_PLUGINDIR=lib/mysql/plugin"
80 "-DINSTALL_INFODIR=share/mysql/docs"
81 "-DINSTALL_MANDIR=share/man"
82 "-DINSTALL_MYSQLSHAREDIR=share/mysql"
83 "-DINSTALL_SCRIPTDIR=bin"
84 "-DINSTALL_SUPPORTFILESDIR=share/doc/mysql"
85 "-DINSTALL_MYSQLTESTDIR=OFF"
86 "-DINSTALL_SQLBENCHDIR=OFF"
87 "-DINSTALL_PAMDIR=share/pam/lib/security"
88 "-DINSTALL_PAMDATADIR=share/pam/etc/security"
93 "-DWITH_SAFEMALLOC=OFF"
94 "-DWITH_UNIT_TESTS=OFF"
95 "-DEMBEDDED_LIBRARY=OFF"
96 ] ++ lib.optionals stdenv.hostPlatform.isDarwin [
97 # On Darwin without sandbox, CMake will find the system java and attempt to build with java support, but
98 # then it will fail during the actual build. Let's just disable the flag explicitly until someone decides
99 # to pass in java explicitly.
100 "-DCONNECT_WITH_JDBC=OFF"
101 "-DCURSES_LIBRARY=${ncurses.out}/lib/libncurses.dylib"
102 ] ++ lib.optionals (stdenv.hostPlatform.isDarwin && lib.versionAtLeast version "10.6") [
103 # workaround for https://jira.mariadb.org/browse/MDEV-29925
104 "-Dhave_C__Wl___as_needed="
105 ] ++ lib.optionals isCross [
106 # revisit this if nixpkgs supports any architecture whose stack grows upwards
107 "-DSTACK_DIRECTION=-1"
108 "-DCMAKE_CROSSCOMPILING_EMULATOR=${stdenv.hostPlatform.emulator buildPackages}"
111 postInstall = lib.optionalString (!withEmbedded) ''
112 # Remove Development components. Need to use libmysqlclient.
113 rm "$out"/lib/mysql/plugin/daemon_example.ini
114 rm "$out"/lib/{libmariadb.a,libmariadbclient.a,libmysqlclient.a,libmysqlclient_r.a,libmysqlservices.a}
115 rm -f "$out"/bin/{mariadb-config,mariadb_config,mysql_config}
117 rm -r $out/lib/pkgconfig
120 # perlPackages.DBDmysql is broken on darwin
121 postFixup = lib.optionalString (!stdenv.hostPlatform.isDarwin) ''
122 wrapProgram $out/bin/mytop --set PATH ${lib.makeBinPath [ less ncurses ]}
126 testVersion = "mariadb_${builtins.replaceStrings ["."] [""] (lib.versions.majorMinor version)}";
128 mariadb-galera-rsync = nixosTests.mariadb-galera.${testVersion};
129 mysql = nixosTests.mysql.${testVersion};
130 mysql-autobackup = nixosTests.mysql-autobackup.${testVersion};
131 mysql-backup = nixosTests.mysql-backup.${testVersion};
132 mysql-replication = nixosTests.mysql-replication.${testVersion};
136 description = "Enhanced, drop-in replacement for MySQL";
137 homepage = "https://mariadb.org/";
138 license = licenses.gpl2Plus;
139 maintainers = with maintainers; [ thoughtpolice ] ++ teams.helsinki-systems.members;
140 platforms = platforms.all;
144 client = stdenv.mkDerivation (common // {
145 pname = "mariadb-client";
147 patches = common.patches ++ [
148 ./patch/cmake-plugin-includedir.patch
151 buildInputs = common.buildInputs
152 ++ lib.optionals (lib.versionAtLeast common.version "10.7") [ fmt_8 ];
154 cmakeFlags = common.cmakeFlags ++ [
155 "-DPLUGIN_AUTH_PAM=NO"
156 "-DWITHOUT_SERVER=ON"
158 "-DINSTALL_MYSQLSHAREDIR=share/mysql-client"
161 postInstall = common.postInstall + ''
162 rm "$out"/bin/{mariadb-test,mysqltest}
163 libmysqlclient_path=$(readlink -f $out/lib/libmysqlclient${libExt})
164 rm "$out"/lib/{libmariadb${libExt},libmysqlclient${libExt},libmysqlclient_r${libExt}}
165 mv "$libmysqlclient_path" "$out"/lib/libmysqlclient${libExt}
166 ln -sv libmysqlclient${libExt} "$out"/lib/libmysqlclient_r${libExt}
170 server = stdenv.mkDerivation (common // {
171 pname = "mariadb-server";
173 nativeBuildInputs = common.nativeBuildInputs ++ [ bison boost.dev flex ];
175 buildInputs = common.buildInputs ++ [
176 bzip2 lz4 lzo snappy xz zstd
177 cracklib judy libevent libxml2
178 ] ++ lib.optional withNuma numactl
179 ++ lib.optionals stdenv.hostPlatform.isLinux [ linux-pam ]
180 ++ lib.optional (!stdenv.hostPlatform.isDarwin) mytopEnv
181 ++ lib.optionals withStorageMroonga [ kytea libsodium msgpack zeromq ]
182 ++ lib.optionals (lib.versionAtLeast common.version "10.7") [ fmt_8 ];
184 propagatedBuildInputs = lib.optional withNuma numactl;
187 substituteInPlace scripts/galera_new_cluster.sh \
188 --replace ":-mariadb" ":-mysql"
191 cmakeFlags = common.cmakeFlags ++ [
192 "-DMYSQL_DATADIR=/var/lib/mysql"
193 "-DENABLED_LOCAL_INFILE=OFF"
195 "-DWITH_EXTRA_CHARSETS=all"
196 "-DWITH_EMBEDDED_SERVER=${if withEmbedded then "ON" else "OFF"}"
197 "-DWITH_UNIT_TESTS=OFF"
199 "-DWITH_INNODB_DISALLOW_WRITES=ON"
200 "-DWITHOUT_EXAMPLE=1"
201 "-DWITHOUT_FEDERATED=1"
203 ] ++ lib.optionals withNuma [
205 ] ++ lib.optionals (!withStorageMroonga) [
206 "-DWITHOUT_MROONGA=1"
207 ] ++ lib.optionals (!withStorageRocks) [
208 "-DWITHOUT_ROCKSDB=1"
209 ] ++ lib.optionals (!stdenv.hostPlatform.isDarwin && withStorageRocks) [
210 "-DWITH_ROCKSDB_JEMALLOC=ON"
211 ] ++ lib.optionals (!stdenv.hostPlatform.isDarwin) [
212 "-DWITH_JEMALLOC=yes"
213 ] ++ lib.optionals stdenv.hostPlatform.isDarwin [
214 "-DPLUGIN_AUTH_PAM=NO"
215 "-DPLUGIN_AUTH_PAM_V1=NO"
216 "-DWITHOUT_OQGRAPH=1"
217 "-DWITHOUT_PLUGIN_S3=1"
220 preConfigure = lib.optionalString (!stdenv.hostPlatform.isDarwin) ''
221 patchShebangs scripts/mytop.sh
224 postInstall = common.postInstall + ''
225 rm -r "$out"/share/aclocal
226 chmod +x "$out"/bin/wsrep_sst_common
227 rm -f "$out"/bin/{mariadb-client-test,mariadb-test,mysql_client_test,mysqltest}
228 '' + lib.optionalString withStorageMroonga ''
229 mv "$out"/share/{groonga,groonga-normalizer-mysql} "$out"/share/doc/mysql
230 '' + lib.optionalString (!stdenv.hostPlatform.isDarwin && lib.versionAtLeast common.version "10.4") ''
231 mv "$out"/OFF/suite/plugins/pam/pam_mariadb_mtr.so "$out"/share/pam/lib/security
232 mv "$out"/OFF/suite/plugins/pam/mariadb_mtr "$out"/share/pam/etc/security
236 CXXFLAGS = lib.optionalString stdenv.hostPlatform.isi686 "-fpermissive";
240 inherit client server;
244 # see https://mariadb.org/about/#maintenance-policy for EOLs
245 mariadb_105 = self.callPackage generic {
246 # Supported until 2025-06-24
247 # TODO should be removed
249 hash = "sha256-lhnQ9R6GQ1dGayxjMBo0pT99/ZnxjE/UUvqyK/Obpk4=";
250 inherit (self.darwin.apple_sdk.frameworks) CoreServices;
252 mariadb_106 = self.callPackage generic {
253 # Supported until 2026-07-06
255 hash = "sha256-aJihER9HEwcJ4ouix70aV+S7VxAfbhCeWX1R5tOFzxg=";
256 inherit (self.darwin.apple_sdk.frameworks) CoreServices;
258 mariadb_1011 = self.callPackage generic {
259 # Supported until 2028-02-16
261 hash = "sha256-XwTz4z2fHL7/BeecVNQdMCYwUAyZWu5ysGOOL5383w8=";
262 inherit (self.darwin.apple_sdk.frameworks) CoreServices;
264 mariadb_110 = self.callPackage generic {
265 # Supported until 2024-06-07
266 # TODO should be removed
268 hash = "sha256-AYnWKUbDfG20a/GkaLqVgLy6joDwWVjsSDwzh+zPmgA=";
269 inherit (self.darwin.apple_sdk.frameworks) CoreServices;