Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at devShellTools-shell 386 lines 12 kB view raw
1let 2 # shared across all versions 3 generic = 4 { 5 version, 6 hash, 7 lib, 8 stdenv, 9 fetchurl, 10 nixosTests, 11 buildPackages, 12 # Native buildInputs components 13 bison, 14 boost, 15 cmake, 16 fixDarwinDylibNames, 17 flex, 18 makeWrapper, 19 pkg-config, 20 # Common components 21 curl, 22 libiconv, 23 ncurses, 24 openssl, 25 pcre2, 26 libkrb5, 27 libaio, 28 liburing, 29 systemd, 30 cctools, 31 perl, 32 jemalloc, 33 less, 34 libedit, 35 # Server components 36 bzip2, 37 lz4, 38 lzo, 39 snappy, 40 xz, 41 zlib, 42 zstd, 43 cracklib, 44 judy, 45 libevent, 46 libxml2, 47 linux-pam, 48 numactl, 49 fmt_11, 50 withStorageMroonga ? true, 51 kytea, 52 libsodium, 53 msgpack, 54 zeromq, 55 withStorageRocks ? true, 56 withEmbedded ? false, 57 withNuma ? false, 58 }: 59 60 let 61 isCross = stdenv.buildPlatform != stdenv.hostPlatform; 62 63 libExt = stdenv.hostPlatform.extensions.sharedLibrary; 64 65 mytopEnv = buildPackages.perl.withPackages ( 66 p: with p; [ 67 DBDMariaDB 68 DBI 69 TermReadKey 70 ] 71 ); 72 73 common = rec { 74 # attributes common to both builds 75 inherit version; 76 77 src = fetchurl { 78 url = "https://archive.mariadb.org/mariadb-${version}/source/mariadb-${version}.tar.gz"; 79 inherit hash; 80 }; 81 82 outputs = [ 83 "out" 84 "man" 85 ]; 86 87 nativeBuildInputs = [ 88 cmake 89 pkg-config 90 ] 91 ++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames 92 ++ lib.optional (!stdenv.hostPlatform.isDarwin) makeWrapper; 93 94 buildInputs = [ 95 libiconv 96 ncurses 97 zlib 98 pcre2 99 openssl 100 curl 101 ] 102 ++ lib.optionals stdenv.hostPlatform.isLinux ( 103 [ 104 libkrb5 105 systemd 106 ] 107 ++ (if (lib.versionOlder version "10.6") then [ libaio ] else [ liburing ]) 108 ) 109 ++ lib.optionals stdenv.hostPlatform.isDarwin [ 110 cctools 111 perl 112 libedit 113 ] 114 ++ lib.optionals (!stdenv.hostPlatform.isDarwin) [ jemalloc ]; 115 116 prePatch = '' 117 sed -i 's,[^"]*/var/log,/var/log,g' storage/mroonga/vendor/groonga/CMakeLists.txt 118 ''; 119 env = lib.optionalAttrs (stdenv.hostPlatform.isLinux && !stdenv.hostPlatform.isGnu) { 120 # MariaDB uses non-POSIX fopen64, which musl only conditionally defines. 121 NIX_CFLAGS_COMPILE = "-D_LARGEFILE64_SOURCE"; 122 }; 123 124 patches = [ 125 ./patch/cmake-includedir.patch 126 # patch for musl compatibility 127 ./patch/include-cstdint-full.patch 128 ] 129 # Fixes a build issue as documented on 130 # https://jira.mariadb.org/browse/MDEV-26769?focusedCommentId=206073&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-206073 131 ++ lib.optional ( 132 !stdenv.hostPlatform.isLinux && lib.versionAtLeast version "10.6" 133 ) ./patch/macos-MDEV-26769-regression-fix.patch; 134 135 cmakeFlags = [ 136 "-DBUILD_CONFIG=mysql_release" 137 "-DMANUFACTURER=nixos.org" 138 "-DDEFAULT_CHARSET=utf8mb4" 139 "-DDEFAULT_COLLATION=utf8mb4_unicode_ci" 140 "-DSECURITY_HARDENED=ON" 141 142 "-DINSTALL_UNIX_ADDRDIR=/run/mysqld/mysqld.sock" 143 "-DINSTALL_BINDIR=bin" 144 "-DINSTALL_DOCDIR=share/doc/mysql" 145 "-DINSTALL_DOCREADMEDIR=share/doc/mysql" 146 "-DINSTALL_INCLUDEDIR=include/mysql" 147 "-DINSTALL_LIBDIR=lib" 148 "-DINSTALL_PLUGINDIR=lib/mysql/plugin" 149 "-DINSTALL_INFODIR=share/mysql/docs" 150 "-DINSTALL_MANDIR=share/man" 151 "-DINSTALL_MYSQLSHAREDIR=share/mysql" 152 "-DINSTALL_SCRIPTDIR=bin" 153 "-DINSTALL_SUPPORTFILESDIR=share/doc/mysql" 154 "-DINSTALL_MYSQLTESTDIR=OFF" 155 "-DINSTALL_SQLBENCHDIR=OFF" 156 "-DINSTALL_PAMDIR=share/pam/lib/security" 157 "-DINSTALL_PAMDATADIR=share/pam/etc/security" 158 159 "-DWITH_ZLIB=system" 160 "-DWITH_SSL=system" 161 "-DWITH_PCRE=system" 162 "-DWITH_SAFEMALLOC=OFF" 163 "-DWITH_UNIT_TESTS=OFF" 164 "-DEMBEDDED_LIBRARY=OFF" 165 ] 166 ++ lib.optionals stdenv.hostPlatform.isDarwin [ 167 # On Darwin without sandbox, CMake will find the system java and attempt to build with java support, but 168 # then it will fail during the actual build. Let's just disable the flag explicitly until someone decides 169 # to pass in java explicitly. 170 "-DCONNECT_WITH_JDBC=OFF" 171 "-DCURSES_LIBRARY=${ncurses.out}/lib/libncurses.dylib" 172 ] 173 ++ lib.optionals (stdenv.hostPlatform.isDarwin && lib.versionAtLeast version "10.6") [ 174 # workaround for https://jira.mariadb.org/browse/MDEV-29925 175 "-Dhave_C__Wl___as_needed=" 176 ] 177 ++ lib.optionals isCross [ 178 # revisit this if nixpkgs supports any architecture whose stack grows upwards 179 "-DSTACK_DIRECTION=-1" 180 "-DCMAKE_CROSSCOMPILING_EMULATOR=${stdenv.hostPlatform.emulator buildPackages}" 181 ]; 182 183 postInstall = lib.optionalString (!withEmbedded) '' 184 # Remove Development components. Need to use libmysqlclient. 185 rm "$out"/lib/mysql/plugin/daemon_example.ini 186 rm "$out"/lib/{libmariadb.a,libmariadbclient.a,libmysqlclient.a,libmysqlclient_r.a,libmysqlservices.a} 187 rm -f "$out"/bin/{mariadb-config,mariadb_config,mysql_config} 188 rm -r $out/include 189 rm -r $out/lib/pkgconfig 190 ''; 191 192 # perlPackages.DBDmysql is broken on darwin 193 postFixup = lib.optionalString (!stdenv.hostPlatform.isDarwin) '' 194 wrapProgram $out/bin/mytop --set PATH ${ 195 lib.makeBinPath [ 196 less 197 ncurses 198 ] 199 } 200 ''; 201 202 passthru.tests = 203 let 204 testVersion = "mariadb_${builtins.replaceStrings [ "." ] [ "" ] (lib.versions.majorMinor version)}"; 205 in 206 { 207 mariadb-galera-rsync = nixosTests.mariadb-galera.${testVersion}; 208 mysql = nixosTests.mysql.${testVersion}; 209 mysql-autobackup = nixosTests.mysql-autobackup.${testVersion}; 210 mysql-backup = nixosTests.mysql-backup.${testVersion}; 211 mysql-replication = nixosTests.mysql-replication.${testVersion}; 212 }; 213 214 meta = with lib; { 215 description = "Enhanced, drop-in replacement for MySQL"; 216 homepage = "https://mariadb.org/"; 217 license = licenses.gpl2Plus; 218 maintainers = with maintainers; [ thoughtpolice ]; 219 teams = [ teams.helsinki-systems ]; 220 platforms = platforms.all; 221 }; 222 }; 223 224 client = stdenv.mkDerivation ( 225 common 226 // { 227 pname = "mariadb-client"; 228 229 patches = common.patches ++ [ 230 ./patch/cmake-plugin-includedir.patch 231 ]; 232 233 buildInputs = 234 common.buildInputs ++ lib.optionals (lib.versionAtLeast common.version "10.11") [ fmt_11 ]; 235 236 cmakeFlags = common.cmakeFlags ++ [ 237 "-DPLUGIN_AUTH_PAM=NO" 238 "-DWITHOUT_SERVER=ON" 239 "-DWITH_WSREP=OFF" 240 "-DINSTALL_MYSQLSHAREDIR=share/mysql-client" 241 ]; 242 243 postInstall = common.postInstall + '' 244 rm "$out"/bin/{mariadb-test,mysqltest} 245 libmysqlclient_path=$(readlink -f $out/lib/libmysqlclient${libExt}) 246 rm "$out"/lib/{libmariadb${libExt},libmysqlclient${libExt},libmysqlclient_r${libExt}} 247 mv "$libmysqlclient_path" "$out"/lib/libmysqlclient${libExt} 248 ln -sv libmysqlclient${libExt} "$out"/lib/libmysqlclient_r${libExt} 249 ''; 250 } 251 ); 252 in 253 254 stdenv.mkDerivation ( 255 finalAttrs: 256 common 257 // { 258 pname = "mariadb-server"; 259 260 nativeBuildInputs = common.nativeBuildInputs ++ [ 261 bison 262 boost.dev 263 flex 264 ]; 265 266 buildInputs = 267 common.buildInputs 268 ++ [ 269 bzip2 270 lz4 271 lzo 272 snappy 273 xz 274 zstd 275 cracklib 276 judy 277 libevent 278 libxml2 279 ] 280 ++ lib.optional withNuma numactl 281 ++ lib.optionals stdenv.hostPlatform.isLinux [ linux-pam ] 282 ++ lib.optional (!stdenv.hostPlatform.isDarwin) mytopEnv 283 ++ lib.optionals withStorageMroonga [ 284 kytea 285 libsodium 286 msgpack 287 zeromq 288 ] 289 ++ lib.optionals (lib.versionAtLeast common.version "10.11") [ fmt_11 ]; 290 291 propagatedBuildInputs = lib.optional withNuma numactl; 292 293 postPatch = '' 294 substituteInPlace scripts/galera_new_cluster.sh \ 295 --replace ":-mariadb" ":-mysql" 296 ''; 297 298 cmakeFlags = 299 common.cmakeFlags 300 ++ [ 301 "-DMYSQL_DATADIR=/var/lib/mysql" 302 "-DENABLED_LOCAL_INFILE=OFF" 303 "-DWITH_READLINE=ON" 304 "-DWITH_EXTRA_CHARSETS=all" 305 "-DWITH_EMBEDDED_SERVER=${if withEmbedded then "ON" else "OFF"}" 306 "-DWITH_UNIT_TESTS=OFF" 307 "-DWITH_WSREP=ON" 308 "-DWITH_INNODB_DISALLOW_WRITES=ON" 309 "-DWITHOUT_EXAMPLE=1" 310 "-DWITHOUT_FEDERATED=1" 311 "-DWITHOUT_TOKUDB=1" 312 ] 313 ++ lib.optionals withNuma [ 314 "-DWITH_NUMA=ON" 315 ] 316 ++ lib.optionals (!withStorageMroonga) [ 317 "-DWITHOUT_MROONGA=1" 318 ] 319 ++ lib.optionals (!withStorageRocks) [ 320 "-DWITHOUT_ROCKSDB=1" 321 ] 322 ++ lib.optionals (!stdenv.hostPlatform.isDarwin && withStorageRocks) [ 323 "-DWITH_ROCKSDB_JEMALLOC=ON" 324 ] 325 ++ lib.optionals (!stdenv.hostPlatform.isDarwin) [ 326 "-DWITH_JEMALLOC=yes" 327 ] 328 ++ lib.optionals stdenv.hostPlatform.isDarwin [ 329 "-DPLUGIN_AUTH_PAM=NO" 330 "-DPLUGIN_AUTH_PAM_V1=NO" 331 "-DWITHOUT_OQGRAPH=1" 332 "-DWITHOUT_PLUGIN_S3=1" 333 ]; 334 335 preConfigure = lib.optionalString (!stdenv.hostPlatform.isDarwin) '' 336 patchShebangs scripts/mytop.sh 337 ''; 338 339 postInstall = 340 common.postInstall 341 + '' 342 rm -r "$out"/share/aclocal 343 chmod +x "$out"/bin/wsrep_sst_common 344 rm -f "$out"/bin/{mariadb-client-test,mariadb-test,mysql_client_test,mysqltest} 345 '' 346 + lib.optionalString withStorageMroonga '' 347 mv "$out"/share/{groonga,groonga-normalizer-mysql} "$out"/share/doc/mysql 348 '' 349 + lib.optionalString (!stdenv.hostPlatform.isDarwin && lib.versionAtLeast common.version "10.4") '' 350 mv "$out"/OFF/suite/plugins/pam/pam_mariadb_mtr.so "$out"/share/pam/lib/security 351 mv "$out"/OFF/suite/plugins/pam/mariadb_mtr "$out"/share/pam/etc/security 352 rm -r "$out"/OFF 353 ''; 354 355 CXXFLAGS = lib.optionalString stdenv.hostPlatform.isi686 "-fpermissive"; 356 357 passthru = { 358 inherit client; 359 server = finalAttrs.finalPackage; 360 }; 361 } 362 ); 363in 364self: { 365 # see https://mariadb.org/about/#maintenance-policy for EOLs 366 mariadb_106 = self.callPackage generic { 367 # Supported until 2026-07-06 368 version = "10.6.22"; 369 hash = "sha256-LKYA3H6F6tHzPCEvnXax8vgS0knIveAuXzjq0Jit5CA="; 370 }; 371 mariadb_1011 = self.callPackage generic { 372 # Supported until 2028-02-16 373 version = "10.11.13"; 374 hash = "sha256-+Lc0dJ+9ZS6k4lW+jMeID5jQe2p/604eqMc2y0gNI+Q="; 375 }; 376 mariadb_114 = self.callPackage generic { 377 # Supported until 2029-05-29 378 version = "11.4.7"; 379 hash = "sha256-vyBofKEvp+/ajficqx8qZhKIzqQaz49TGJtp1SlDR9A="; 380 }; 381 mariadb_118 = self.callPackage generic { 382 # Supported until 2028-06-04 383 version = "11.8.2"; 384 hash = "sha256-shYs316TF9ioYhy+2oOZkyT8CsiUQhDhSrtf4Kn+o+8="; 385 }; 386}