1{ lib
2, stdenv
3, pkg-config
4, cmake
5, fetchurl
6, git
7, cctools
8, developer_cmds
9, DarwinTools
10, makeWrapper
11, CoreServices
12, bison
13, openssl
14, protobuf
15, curl
16, zlib
17, libssh
18, zstd
19, lz4
20, boost
21, readline
22, libtirpc
23, rpcsvc-proto
24, libedit
25, libevent
26, icu
27, re2
28, ncurses
29, libfido2
30, v8
31, python3
32, cyrus_sasl
33, openldap
34, antlr
35}:
36
37let
38 pythonDeps = with python3.pkgs; [ certifi paramiko pyyaml ];
39in
40stdenv.mkDerivation rec {
41 pname = "mysql-shell";
42 version = "8.0.31";
43
44 srcs = [
45 (fetchurl {
46 url = "https://cdn.mysql.com//Downloads/MySQL-Shell/mysql-shell-${version}-src.tar.gz";
47 sha256 = "sha256-VA9dqvPmw2WXP3hAJS2xRTvxBM8D/IPsWYIaYwRZI/s=";
48 })
49 (fetchurl {
50 url = "https://dev.mysql.com/get/Downloads/MySQL-${lib.versions.majorMinor version}/mysql-${version}.tar.gz";
51 sha256 = "sha256-Z7uMunWyjpXH95SFY/AfuEUo/LsaNduoOdTORP4Bm6o=";
52 })
53 ];
54
55 sourceRoot = "mysql-shell-${version}-src";
56
57 postPatch = ''
58 substituteInPlace ../mysql-${version}/cmake/libutils.cmake --replace /usr/bin/libtool libtool
59 substituteInPlace ../mysql-${version}/cmake/os/Darwin.cmake --replace /usr/bin/libtool libtool
60
61 substituteInPlace cmake/libutils.cmake --replace /usr/bin/libtool libtool
62 '';
63
64 nativeBuildInputs = [ pkg-config cmake git bison makeWrapper ]
65 ++ lib.optionals (!stdenv.isDarwin) [ rpcsvc-proto ]
66 ++ lib.optionals stdenv.isDarwin [ cctools developer_cmds DarwinTools ];
67
68 buildInputs = [
69 boost
70 curl
71 libedit
72 libssh
73 lz4
74 openssl
75 protobuf
76 readline
77 zlib
78 zstd
79 libevent
80 icu
81 re2
82 ncurses
83 libfido2
84 cyrus_sasl
85 openldap
86 v8
87 python3
88 antlr.runtime.cpp
89 ] ++ pythonDeps
90 ++ lib.optionals stdenv.isLinux [ libtirpc ]
91 ++ lib.optionals stdenv.isDarwin [ CoreServices ];
92
93 preConfigure = ''
94 # Build MySQL
95 echo "Building mysqlclient mysqlxclient"
96
97 cmake -DWITH_BOOST=system -DWITH_SYSTEM_LIBS=ON -DWITH_ROUTER=OFF -DWITH_UNIT_TESTS=OFF \
98 -DFORCE_UNSUPPORTED_COMPILER=1 -S ../mysql-${version} -B ../mysql-${version}/build
99
100 cmake --build ../mysql-${version}/build --parallel ''${NIX_BUILD_CORES:-1} --target mysqlclient mysqlxclient
101 '';
102
103 cmakeFlags = [
104 "-DMYSQL_SOURCE_DIR=../mysql-${version}"
105 "-DMYSQL_BUILD_DIR=../mysql-${version}/build"
106 "-DMYSQL_CONFIG_EXECUTABLE=../../mysql-${version}/build/scripts/mysql_config"
107 "-DWITH_ZSTD=system"
108 "-DWITH_LZ4=system"
109 "-DWITH_ZLIB=system"
110 "-DWITH_PROTOBUF=${protobuf}"
111 "-DHAVE_V8=1"
112 "-DV8_INCLUDE_DIR=${v8}/include"
113 "-DV8_LIB_DIR=${v8}/lib"
114 "-DHAVE_PYTHON=1"
115 ];
116
117 CXXFLAGS = [ "-DV8_COMPRESS_POINTERS=1" "-DV8_31BIT_SMIS_ON_64BIT_ARCH=1" ];
118
119 postFixup = ''
120 wrapProgram $out/bin/mysqlsh --set PYTHONPATH "${lib.makeSearchPath python3.sitePackages pythonDeps}"
121 '';
122
123 meta = with lib; {
124 homepage = "https://dev.mysql.com/doc/mysql-shell/${lib.versions.majorMinor version}/en/";
125 description = "A new command line scriptable shell for MySQL";
126 license = licenses.gpl2;
127 maintainers = with maintainers; [ aaronjheng ];
128 mainProgram = "mysqlsh";
129 };
130}