summary refs log tree commit diff
path: root/pkgs/applications/misc/mysql-workbench/default.nix
blob: 76517f874642209246276cfa15258c355e563385 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
{ stdenv, fetchurl, makeWrapper, cmake, pkgconfig
, glibc, gnome-keyring, gtk, gtkmm, pcre, swig, sudo
, mysql, libxml2, libctemplate, libmysqlconnectorcpp
, vsqlite, tinyxml, gdal, libiodbc, libpthreadstubs
, libXdmcp, libuuid, libzip, libgnome-keyring, file
, pythonPackages, jre, autoconf, automake, libtool
, boost, glibmm, libsigcxx, pangomm, libX11, openssl
, proj, cairo, libglade
}:

let
  inherit (pythonPackages) pexpect pycrypto python paramiko;
in stdenv.mkDerivation rec {
  pname = "mysql-workbench";
  version = "6.3.8";
  name = "${pname}-${version}";

  src = fetchurl {
    url = "http://dev.mysql.com/get/Downloads/MySQLGUITools/mysql-workbench-community-${version}-src.tar.gz";
    sha256 = "1bxd828nrawmym6d8awh1vrni8dsbwh1k5am1lrq5ihp5c3kw9ka";
  };

  nativeBuildInputs = [ pkgconfig ];
  buildInputs = [ cmake gnome-keyring gtk gtk.dev gtkmm pcre swig python sudo
    paramiko mysql libxml2 libctemplate libmysqlconnectorcpp vsqlite tinyxml gdal libiodbc file
    libpthreadstubs libXdmcp libuuid libzip libgnome-keyring libgnome-keyring.dev jre autoconf
    automake libtool boost glibmm glibmm.dev libsigcxx pangomm libX11 pexpect pycrypto openssl
    proj cairo cairo.dev makeWrapper libglade ] ;

  prePatch = ''
    for f in backend/wbpublic/{grt/spatial_handler.h,grtui/geom_draw_box.h,objimpl/db.query/db_query_Resultset.cpp} ;
    do
      sed -i 's@#include <gdal/@#include <@' $f ;
    done

    sed -i '32s@mysqlparser@mysqlparser sqlparser@' library/mysql.parser/CMakeLists.txt

    cat <<EOF > ext/antlr-runtime/fix-configure
    #!${stdenv.shell}
    echo "fixing bundled antlr3c configure" ;
    sed -i 's@/usr/bin/file@${file}/bin/file@' configure
    sed -i '12121d' configure
    EOF
    chmod +x ext/antlr-runtime/fix-configure
    sed -i '236s@&&@& ''${PROJECT_SOURCE_DIR}/ext/antlr-runtime/fix-configure &@' CMakeLists.txt

    substituteInPlace $(pwd)/frontend/linux/workbench/mysql-workbench.in --replace "catchsegv" "${glibc.bin}/bin/catchsegv"
    substituteInPlace $(pwd)/frontend/linux/workbench/mysql-workbench.in --replace "/usr/lib/x86_64-linux-gnu" "${proj}/lib"
    patchShebangs $(pwd)/library/mysql.parser/grammar/build-parser
    patchShebangs $(pwd)/tools/get_wb_version.sh
  '';

  NIX_CFLAGS_COMPILE = [
    "-I${libsigcxx}/lib/sigc++-2.0/include"
    "-I${pangomm}/lib/pangomm-1.4/include"
    "-I${glibmm}/lib/giomm-2.4/include"
  ];

  cmakeFlags = [
    "-DCMAKE_CXX_FLAGS=-std=c++11"
    "-DMySQL_CONFIG_PATH=${mysql}/bin/mysql_config"
    "-DCTemplate_INCLUDE_DIR=${libctemplate}/include"
    "-DCAIRO_INCLUDE_DIRS=${cairo.dev}/include"
    "-DGTK2_GDKCONFIG_INCLUDE_DIR=${gtk}/lib/gtk-2.0/include"
    "-DGTK2_GLIBCONFIG_INCLUDE_DIR=${gtk.dev}/include"
    "-DGTK2_GTKMMCONFIG_INCLUDE_DIR=${gtkmm}/lib/gtkmm-2.4/include"
    "-DGTK2_GDKMMCONFIG_INCLUDE_DIR=${gtkmm}/lib/gdkmm-2.4/include"
    "-DGTK2_GLIBMMCONFIG_INCLUDE_DIR=${glibmm}/lib/glibmm-2.4/include"
  ];

  postInstall = ''
    patchShebangs $out/share/mysql-workbench/extras/build_freetds.sh

    for i in $out/lib/mysql-workbench/modules/wb_utils_grt.py \
             $out/lib/mysql-workbench/modules/wb_server_management.py \
             $out/lib/mysql-workbench/modules/wb_admin_grt.py; do
      substituteInPlace $i \
        --replace "/bin/bash" ${stdenv.shell} \
        --replace "/usr/bin/sudo" ${sudo}/bin/sudo
    done

    wrapProgram "$out/bin/mysql-workbench" \
      --prefix LD_LIBRARY_PATH : "${python}/lib" \
      --prefix LD_LIBRARY_PATH : "$(cat ${stdenv.cc}/nix-support/orig-cc)/lib64" \
      --prefix PATH : "${gnome-keyring}/bin" \
      --prefix PATH : "${python}/bin" \
      --set PYTHONPATH $PYTHONPATH \
      --run '
# The gnome-keyring-daemon must be running.  To allow for environments like
# kde, xfce where this is not so, we start it first.
# It is cleaned up using a supervisor subshell which detects that
# the parent has finished via the closed pipe as terminate signal idiom,
# used because we cannot clean up after ourselves due to the exec call.

# Start gnome-keyring-daemon, export the environment variables it asks us to set.
for expr in $( gnome-keyring-daemon --start ) ; do eval "export "$expr ; done

# Prepare fifo pipe.
FIFOCTL="/tmp/gnome-keyring-daemon-ctl.$$.fifo"
[ -p $FIFOCTL ] && rm $FIFOCTL
mkfifo $FIFOCTL

# Supervisor subshell waits reading from pipe, will receive EOF when parent
# closes pipe on termination.  Negate read with ! operator to avoid subshell
# quitting when read EOF returns 1 due to -e option being set.
(
    exec 19< $FIFOCTL
    ! read -u 19

    kill $GNOME_KEYRING_PID
    rm $FIFOCTL
) &

exec 19> $FIFOCTL
            '
  '';

  meta = with stdenv.lib; {
    description = "Visual MySQL database modeling, administration and querying tool";
    longDescription = ''
      MySQL Workbench is a modeling tool that allows you to design
      and generate MySQL databases graphically. It also has administration
      and query development modules where you can manage MySQL server instances
      and execute SQL queries.
    '';

    homepage = http://wb.mysql.com/;
    license = licenses.gpl2;
    maintainers = [ maintainers.kkallio ];
    platforms = [ "x86_64-linux" ];
  };
}