anchor.diff:      # https://github.com/NixOS/nixpkgs/commit/5c5362427a3fa9aefccfca9e531492a8735d4e6f
       "--without-system-orcus"
       "--without-system-xmlsec"
  -  ] ++ lib.optionals kdeIntegration [
  +  ] ++ optionals kdeIntegration [
       "--enable-kf5"
       "--enable-qt5"
       "--enable-gtk3-kde5"
     ];
   
  -  checkPhase = ''
  -    make unitcheck
  -    make slowcheck
  -  '';
  +  checkTarget = concatStringsSep " " [
  +    "unitcheck"
  +    "slowcheck"
  +  ];
   
     nativeBuildInputs = [
  -    gdb fontforge autoconf automake bison pkg-config libtool jdk
  -  ] ++ lib.optional (!kdeIntegration) wrapGAppsHook
  -    ++ lib.optional kdeIntegration wrapQtAppsHook;
  -
  -  buildInputs = with xorg;
  -    [ ant ArchiveZip boost box2d cairo clucene_core
  -      IOCompress cppunit cups curl db dbus-glib expat file flex fontconfig
  -      freetype getopt gperf gtk3
  -      hunspell icu jre' lcms libcdr libexttextcat unixODBC libjpeg
  -      libmspack librdf_redland librsvg libsndfile libvisio libwpd libwpg libX11
  -      libXaw libXext libXi libXinerama libxml2 libxslt libXtst
  -      libXdmcp libpthreadstubs libGLU libGL mythes
  -      glib libmysqlclient
  -      neon nspr nss openldap openssl pam perl pkg-config poppler
  -      python3 sane-backends unzip which zip zlib
  -      mdds bluez5 libwps libabw libzmf
  -      libxshmfence libatomic_ops graphite2 harfbuzz gpgme util-linux
  -      librevenge libe-book libmwaw glm ncurses libepoxy
  -      libodfgen CoinMP librdf_rasqal gnome.adwaita-icon-theme gettext abseil-cpp
  -    ]
  -    ++ (with gst_all_1; [
  -      gstreamer
  -      gst-plugins-base gst-plugins-good gst-plugins-bad gst-plugins-ugly
  -      gst-libav
  -    ])
  -    ++ lib.optional kdeIntegration [ qtbase qtx11extras kcoreaddons kio ];
  +    autoconf
  +    automake
  +    bison
  +    fontforge
  +    gdb
  +    jdk
  +    libtool
  +    pkg-config
  +  ]
  +  ++ [ (if kdeIntegration then wrapQtAppsHook else wrapGAppsHook) ];
  +
  +  buildInputs = with xorg; [
  +    ArchiveZip
  +    CoinMP
  +    IOCompress
  +    abseil-cpp
  +    ant
  +    bluez5
  +    boost
  +    box2d
  +    cairo
  +    clucene_core
  +    cppunit
  +    cups
  +    curl
  +    db
  +    dbus-glib
  +    expat
  +    file
  +    flex
  +    fontconfig
  +    freetype
  +    getopt
  +    gettext
  +    glib
  +    glm
  +    gnome.adwaita-icon-theme
  +    gperf
  +    gpgme
  +    graphite2
  +    gtk3
  +    harfbuzz
  +    hunspell
  +    icu
  +    jre'
  +    lcms
  +    libGL
  +    libGLU
  +    libX11
  +    libXaw
  +    libXdmcp
  +    libXext
  +    libXi
  +    libXinerama
  +    libXtst
  +    libabw
  +    libatomic_ops
  +    libcdr
  +    libe-book
  +    libepoxy
  +    libexttextcat
  +    libjpeg
  +    libmspack
  +    libmwaw
  +    libmysqlclient
  +    libodfgen
  +    libpthreadstubs
  +    librdf_rasqal
  +    librdf_redland
  +    librevenge
  +    librsvg
  +    libsndfile
  +    libvisio
  +    libwpd
  +    libwpg
  +    libwps
  +    libxml2
  +    libxshmfence
  +    libxslt
  +    libzmf
  +    mdds
  +    mythes
  +    ncurses
  +    neon
  +    nspr
  +    nss
  +    openldap
  +    openssl
  +    pam
  +    perl
  +    pkg-config
  +    poppler
  +    python3
  +    sane-backends
  +    unixODBC
  +    unzip
  +    util-linux
  +    which
  +    zip
  +    zlib
  +  ]
  +  ++ (with gst_all_1; [
  +    gst-libav
  +    gst-plugins-bad
  +    gst-plugins-base
  +    gst-plugins-good
  +    gst-plugins-ugly
  +    gstreamer
  +  ])
  +  ++ optionals kdeIntegration [ qtbase qtx11extras kcoreaddons kio ];
   
     passthru = {
       inherit srcs;
  
positive.code:     substituteInPlace configure.ac --replace \
        'GPGMEPP_CFLAGS=-I/usr/include/gpgme++' \
        'GPGMEPP_CFLAGS=-I${gpgme.dev}/include/gpgme++'
    '' + lib.optionalString kdeIntegration ''
        substituteInPlace configure.ac \
          --replace kcoreaddons_version.h KCoreAddons/kcoreaddons_version.h \
          --replace '$QT5INC'             ${qtbase.dev}/include \
          --replace '$QT5LIB'             ${qtbase.out}/lib \
          --replace '-I$qt5_incdir '      '-I${qtx11extras.dev}/include '\
          --replace '-L$qt5_libdir '      '${libs [ qtbase qtx11extras ]} ' \
          --replace '$KF5INC'             ${kcoreaddons.dev}/include \
          --replace '$KF5LIB'             ${kcoreaddons.out}/lib \
          --replace '$kf5_incdir/KCore'   ${inc kcoreaddons "KCore"} \
          --replace '$kf5_incdir/KI18n'   ${inc ki18n "KI18n"} \
          --replace '$kf5_incdir/KConfig' ${inc kconfig "KConfig"} \
          --replace '$kf5_incdir/KWindow' ${inc kwindowsystem "KWindow"} \
          --replace '$kf5_incdir/KIO'     ${inc kio "KIO"} \
          --replace '-L$kf5_libdir '      '${libs [ kconfig kcoreaddons ki18n kio kwindowsystem ]} '
    '';
  
    dontUseCmakeConfigure = true;
  
negative.code: 
    ### QT/KDE
    #
    # configure.ac assumes that the first directory that contains headers and
    # libraries during its checks contains *all* the relevant headers/libs which
    # obviously doesn't work for us, so we have 2 options:
    #
    # 1. patch configure.ac in order to specify the direct paths to various Qt/KDE
    # dependencies which is ugly and brittle, or
    #
    # 2. use symlinkJoin to pull in the relevant dependencies and just patch in
    # that path which is *also* ugly, but far less likely to break
    #
    # The 2nd option is not very Nix'y, but I'll take robust over nice any day.
    # Additionally, it's much easier to fix if LO breaks on the next upgrade (just
    # add the missing dependencies to it).
    postPatch = ''
      substituteInPlace shell/source/unix/exec/shellexec.cxx \
        --replace /usr/bin/xdg-open ${if kdeIntegration then "kde-open5" else "xdg-open"}
  
  