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