anchor.diff:        FreeRDP is a client-side implementation of the Remote Desktop Protocol (RDP)
         following the Microsoft Open Specifications.
       '';
  -    homepage = "http://www.freerdp.com/";
  +    homepage = "https://www.freerdp.com/";
       license = licenses.asl20;
       maintainers = with maintainers; [ peterhoeg lheckemann ];
       platforms = platforms.unix;
  
positive.code: { stdenv, lib, fetchFromGitHub, cmake, pkgconfig
  , alsaLib, ffmpeg, glib, openssl, pcre, zlib
  , libX11, libXcursor, libXdamage, libXext, libXi, libXinerama, libXrandr, libXrender, libXv, libXtst
  , libxkbcommon, libxkbfile
  , wayland
  , gstreamer, gst-plugins-base, gst-plugins-good, libunwind, orc
  , libxslt
  , libusb1
  , libpulseaudio ? null
  , cups ? null
  , pcsclite ? null
  , systemd ? null
  , buildServer ? true
  , nocaps ? false
  }:
  
  stdenv.mkDerivation rec {
    pname = "freerdp";
    version = "2.0.0";
  
    src = fetchFromGitHub {
      owner  = "FreeRDP";
      repo   = "FreeRDP";
      rev    = version;
      sha256 = "0d2559v0z1jnq6jlrvsgdf8p6gd27m8kwdnxckl1x0ygaxs50bqc";
    };
  
    # outputs = [ "bin" "out" "dev" ];
  
    prePatch = ''
      export HOME=$TMP
      substituteInPlace "libfreerdp/freerdp.pc.in" \
        --replace "Requires:" "Requires: @WINPR_PKG_CONFIG_FILENAME@"
    '' + lib.optionalString (pcsclite != null) ''
  
negative.code:       --replace "RDP_SCANCODE_CAPSLOCK" "RDP_SCANCODE_LCONTROL"
    '';
  
    buildInputs = with lib;
      [
        alsaLib
        cups
        ffmpeg
        glib
        gst-plugins-base
        gst-plugins-good
        gstreamer
        libX11
        libXcursor
        libXdamage
        libXext
        libXi
        libXinerama
        libXrandr
        libXrender
        libXtst
        libXv
        libpulseaudio
        libunwind
        libusb1
        libxkbcommon
        libxkbfile
        libxslt
        openssl
        orc
        pcre
        pcsclite
        wayland
        zlib
      ] ++ optional stdenv.isLinux systemd;
  
    nativeBuildInputs = [ cmake pkgconfig ];
  
    doCheck = true;
  
    cmakeFlags = [ "-DCMAKE_INSTALL_LIBDIR=lib" ]
      ++ lib.mapAttrsToList (k: v: "-D${k}=${if v then "ON" else "OFF"}") {
        BUILD_TESTING = doCheck;
        WITH_CUNIT = doCheck;
        WITH_CUPS = (cups != null);
        WITH_OSS = false;
        WITH_PCSC = (pcsclite != null);
        WITH_PULSE = (libpulseaudio != null);
        WITH_SERVER = buildServer;
        WITH_SSE2 = stdenv.isx86_64;
      };
  
    meta = with lib; {
      description = "A Remote Desktop Protocol Client";
  