nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 cmake,
6 curl,
7 openssl,
8 zlib,
9 zstd,
10 libiconv,
11 version,
12 hash,
13 ...
14}:
15
16let
17 isVer33 = lib.versionAtLeast version "3.3";
18
19in
20stdenv.mkDerivation {
21 pname = "mariadb-connector-c";
22 inherit version;
23
24 src = fetchFromGitHub {
25 owner = "mariadb-corporation";
26 repo = "mariadb-connector-c";
27 rev = "v${version}";
28 inherit hash;
29 };
30
31 outputs = [
32 "out"
33 "dev"
34 ];
35
36 cmakeFlags = [
37 "-DMARIADB_UNIX_ADDR=/run/mysqld/mysqld.sock"
38 "-DWITH_CURL=ON"
39 "-DWITH_EXTERNAL_ZLIB=ON"
40 "-DWITH_MYSQLCOMPAT=ON"
41 ];
42
43 postPatch = ''
44 substituteInPlace mariadb_config/mariadb_config.c.in \
45 --replace '#define INCLUDE "-I%s/@INSTALL_INCLUDEDIR@ -I%s/@INSTALL_INCLUDEDIR@/mysql"' "#define INCLUDE \"-I$dev/include -I$dev/include/mysql\"" \
46 --replace '#define LIBS "-L%s/@INSTALL_LIBDIR@/ -lmariadb"' "#define LIBS \"-L$out/lib/mariadb -lmariadb\"" \
47 --replace '#define PKG_LIBDIR "%s/@INSTALL_LIBDIR@"' "#define PKG_LIBDIR \"$out/lib/mariadb\"" \
48 --replace '#define PLUGIN_DIR "%s/@INSTALL_PLUGINDIR@"' "#define PLUGIN_DIR \"$out/lib/mariadb/plugin\"" \
49 --replace '#define PKG_PLUGINDIR "%s/@INSTALL_PLUGINDIR@"' "#define PKG_PLUGINDIR \"$out/lib/mariadb/plugin\""
50 ''
51 + lib.optionalString stdenv.hostPlatform.isStatic ''
52 # Disables all dynamic plugins
53 substituteInPlace cmake/plugins.cmake \
54 --replace 'if(''${CC_PLUGIN_DEFAULT} STREQUAL "DYNAMIC")' 'if(''${CC_PLUGIN_DEFAULT} STREQUAL "INVALID")'
55 # Force building static libraries
56 substituteInPlace libmariadb/CMakeLists.txt \
57 --replace 'libmariadb SHARED' 'libmariadb STATIC'
58 '';
59
60 # The cmake setup-hook uses $out/lib by default, this is not the case here.
61 preConfigure = lib.optionalString stdenv.hostPlatform.isDarwin ''
62 cmakeFlagsArray+=("-DCMAKE_INSTALL_NAME_DIR=$out/lib/mariadb")
63 '';
64
65 nativeBuildInputs = [ cmake ];
66 propagatedBuildInputs = [
67 curl
68 openssl
69 zlib
70 ]
71 ++ lib.optional isVer33 zstd;
72 buildInputs = [ libiconv ];
73
74 postInstall = ''
75 moveToOutput bin/mariadb_config "$dev"
76 '';
77
78 postFixup = ''
79 ln -sv mariadb_config $dev/bin/mysql_config
80 ln -sv mariadb $out/lib/mysql
81 ln -sv mariadb $dev/include/mysql
82 ln -sv mariadb_version.h $dev/include/mariadb/mysql_version.h
83 ln -sv libmariadb.pc $dev/lib/pkgconfig/mysqlclient.pc
84 install -Dm644 include/ma_config.h $dev/include/mariadb/my_config.h
85 '';
86
87 meta = with lib; {
88 description = "Client library that can be used to connect to MySQL or MariaDB";
89 license = licenses.lgpl21Plus;
90 maintainers = with maintainers; [ globin ];
91 platforms = platforms.all;
92 };
93}