{ stdenv, fetchurl, cups, libssh, libXpm, nxproxy, openldap, makeWrapper, qt4, qmake4Hook }:

stdenv.mkDerivation rec {
  name = "x2goclient-${version}";
  version = "4.0.5.1";

  src = fetchurl {
    url = "http://code.x2go.org/releases/source/x2goclient/${name}.tar.gz";
    sha256 = "04gdccqywas029a76k3r9zhr2mfn385i9r06cmi8mznxpczrhkl4";
  };

  buildInputs = [ cups libssh libXpm nxproxy openldap qt4 ];
  nativeBuildInputs = [ makeWrapper qmake4Hook ];

  patchPhase = ''
     substituteInPlace Makefile \
       --replace "lrelease-qt4" "${qt4}/bin/lrelease" \
       --replace "qmake-qt4" "${qt4}/bin/qmake" \
       --replace "-o root -g root" ""
  '';

  preConfigure = ''
    qmakeFlags="$qmakeFlags ETCDIR=$out/etc"
  '';

  enableParallelBuilding = true;

  installTargets = [ "install_client" "install_man" ];
  postInstall = ''
    wrapProgram "$out/bin/x2goclient" --suffix PATH : "${nxproxy}/bin";
  '';

  meta = with stdenv.lib; {
    description = "Graphical NoMachine NX3 remote desktop client";
    homepage = http://x2go.org/;
    license = licenses.gpl2;
    platforms = platforms.linux;
    maintainers = with maintainers; [ nckx ];
  };
}

{ stdenv, fetchurl, cups, libssh, libXpm, nxproxy, openldap, makeWrapper, qt4 }:

stdenv.mkDerivation rec {
  name = "x2goclient-${version}";
  version = "4.0.5.1";

  src = fetchurl {
    url = "http://code.x2go.org/releases/source/x2goclient/${name}.tar.gz";
    sha256 = "04gdccqywas029a76k3r9zhr2mfn385i9r06cmi8mznxpczrhkl4";
  };

  buildInputs = [ cups libssh libXpm nxproxy openldap qt4 ];
  nativeBuildInputs = [ makeWrapper ];

  patchPhase = ''
     substituteInPlace Makefile \
       --replace "lrelease-qt4" "${qt4}/bin/lrelease" \
       --replace "qmake-qt4" "${qt4}/bin/qmake" \
       --replace "-o root -g root" ""
  '';

  makeFlags = [ "PREFIX=$(out)" "ETCDIR=$(out)/etc" ];

  enableParallelBuilding = true;

  installTargets = [ "install_client" "install_man" ];
  postInstall = ''
    wrapProgram "$out/bin/x2goclient" --suffix PATH : "${nxproxy}/bin";
  '';

  meta = with stdenv.lib; {
    description = "Graphical NoMachine NX3 remote desktop client";
    homepage = http://x2go.org/;
    license = licenses.gpl2;
    platforms = platforms.linux;
    maintainers = with maintainers; [ nckx ];
  };
}

Revert "x2goclient: move to qmake4Hook"
Revert "x2goclient: move to qmake4Hook"

This reverts commit 83406bc171ca2b385c49838e6ed5e89007a875b5, because
it broke the build.

x2goclient requires to be built with its top-level (hand coded) Makefile
(in accordance with upstream documentation). Invoking qmake directly on
the .pro file, without specifying a separate build tree, will overwrite
the Makefile and break the build.

For instance, there are no install rules in the .pro file. That exists
only in the Makefile.
