diff --git a/pkgs/applications/kde/akonadi/0001-Revert-Make-Akonadi-installation-properly-relocatabl.patch b/pkgs/applications/kde/akonadi/0001-Revert-Make-Akonadi-installation-properly-relocatabl.patch
index 24ed20fd83fb..c3964c5c05b5 100644
--- a/pkgs/applications/kde/akonadi/0001-Revert-Make-Akonadi-installation-properly-relocatabl.patch
+++ b/pkgs/applications/kde/akonadi/0001-Revert-Make-Akonadi-installation-properly-relocatabl.patch
@@ -9,11 +9,11 @@ This reverts commit b2bb55f13f2ac783f89cc414de8c39f62fa2096a.
  KF5AkonadiConfig.cmake.in | 6 +++---
  2 files changed, 3 insertions(+), 6 deletions(-)
 
-diff --git a/CMakeLists.txt b/CMakeLists.txt
-index 9788bea94..15bad00fd 100644
---- a/CMakeLists.txt
-+++ b/CMakeLists.txt
-@@ -285,9 +285,6 @@ configure_package_config_file(
+Index: akonadi-19.08.0/CMakeLists.txt
+===================================================================
+--- akonadi-19.08.0.orig/CMakeLists.txt
++++ akonadi-19.08.0/CMakeLists.txt
+@@ -306,9 +306,6 @@ configure_package_config_file(
      "${CMAKE_CURRENT_SOURCE_DIR}/KF5AkonadiConfig.cmake.in"
      "${CMAKE_CURRENT_BINARY_DIR}/KF5AkonadiConfig.cmake"
      INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR}
@@ -23,13 +23,13 @@ index 9788bea94..15bad00fd 100644
  )
  
  install(FILES
-diff --git a/KF5AkonadiConfig.cmake.in b/KF5AkonadiConfig.cmake.in
-index 75abede50..10f039376 100644
---- a/KF5AkonadiConfig.cmake.in
-+++ b/KF5AkonadiConfig.cmake.in
-@@ -13,8 +13,8 @@ find_dependency(KF5ConfigWidgets "@KF5_VERSION@")
- find_dependency(Qt5DBus "@QT_REQUIRED_VERSION@")
- find_dependency(Qt5Network "@QT_REQUIRED_VERSION@")
+Index: akonadi-19.08.0/KF5AkonadiConfig.cmake.in
+===================================================================
+--- akonadi-19.08.0.orig/KF5AkonadiConfig.cmake.in
++++ akonadi-19.08.0/KF5AkonadiConfig.cmake.in
+@@ -26,8 +26,8 @@ if(BUILD_TESTING)
+     find_dependency(Qt5Test "@QT_REQUIRED_VERSION@")
+ endif()
  
 -set_and_check(AKONADI_DBUS_INTERFACES_DIR  "@PACKAGE_AKONADI_DBUS_INTERFACES_INSTALL_DIR@")
 -set_and_check(AKONADI_INCLUDE_DIR          "@PACKAGE_AKONADI_INCLUDE_DIR@")
@@ -38,15 +38,12 @@ index 75abede50..10f039376 100644
  
  find_dependency(Boost "@Boost_MINIMUM_VERSION@")
  
-@@ -22,7 +22,7 @@ include(${CMAKE_CURRENT_LIST_DIR}/KF5AkonadiTargets.cmake)
+@@ -35,7 +35,7 @@ include(${CMAKE_CURRENT_LIST_DIR}/KF5Ako
  include(${CMAKE_CURRENT_LIST_DIR}/KF5AkonadiMacros.cmake)
  
  # The directory where akonadi-xml.xsd and kcfg2dbus.xsl are installed
 -set(KF5Akonadi_DATA_DIR "@PACKAGE_KF5Akonadi_DATA_DIR@")
 +set(KF5Akonadi_DATA_DIR "@KF5Akonadi_DATA_DIR@")
-
+ 
  ####################################################################################
  # CMAKE_AUTOMOC
--- 
-2.15.1
-
diff --git a/pkgs/applications/kde/akonadi/akonadi-paths.patch b/pkgs/applications/kde/akonadi/akonadi-paths.patch
index fcbbbbb72eb3..ba6bbedeeae7 100644
--- a/pkgs/applications/kde/akonadi/akonadi-paths.patch
+++ b/pkgs/applications/kde/akonadi/akonadi-paths.patch
@@ -1,8 +1,8 @@
-diff --git a/src/akonadicontrol/agentmanager.cpp b/src/akonadicontrol/agentmanager.cpp
-index d85c1a79b..8df02710c 100644
---- a/src/akonadicontrol/agentmanager.cpp
-+++ b/src/akonadicontrol/agentmanager.cpp
-@@ -78,12 +78,12 @@ AgentManager::AgentManager(bool verbose, QObject *parent)
+Index: akonadi-19.08.0/src/akonadicontrol/agentmanager.cpp
+===================================================================
+--- akonadi-19.08.0.orig/src/akonadicontrol/agentmanager.cpp
++++ akonadi-19.08.0/src/akonadicontrol/agentmanager.cpp
+@@ -78,12 +78,12 @@ AgentManager::AgentManager(bool verbose,
      mStorageController = new Akonadi::ProcessControl;
      mStorageController->setShutdownTimeout(15 * 1000);   // the server needs more time for shutdown if we are using an internal mysqld
      connect(mStorageController, &Akonadi::ProcessControl::unableToStart, this, &AgentManager::serverFailure);
@@ -17,11 +17,11 @@ index d85c1a79b..8df02710c 100644
      }
  }
  
-diff --git a/src/akonadicontrol/agentprocessinstance.cpp b/src/akonadicontrol/agentprocessinstance.cpp
-index be1cc4afb..6d0c1d7e5 100644
---- a/src/akonadicontrol/agentprocessinstance.cpp
-+++ b/src/akonadicontrol/agentprocessinstance.cpp
-@@ -62,7 +62,7 @@ bool AgentProcessInstance::start(const AgentType &agentInfo)
+Index: akonadi-19.08.0/src/akonadicontrol/agentprocessinstance.cpp
+===================================================================
+--- akonadi-19.08.0.orig/src/akonadicontrol/agentprocessinstance.cpp
++++ akonadi-19.08.0/src/akonadicontrol/agentprocessinstance.cpp
+@@ -62,7 +62,7 @@ bool AgentProcessInstance::start(const A
      } else {
          Q_ASSERT(agentInfo.launchMethod == AgentType::Launcher);
          const QStringList arguments = QStringList() << executable << identifier();
@@ -30,11 +30,11 @@ index be1cc4afb..6d0c1d7e5 100644
          mController->start(agentLauncherExec, arguments);
      }
      return true;
-diff --git a/src/server/storage/dbconfigmysql.cpp b/src/server/storage/dbconfigmysql.cpp
-index dfff6fc29..419e54a5b 100644
---- a/src/server/storage/dbconfigmysql.cpp
-+++ b/src/server/storage/dbconfigmysql.cpp
-@@ -82,7 +82,6 @@ bool DbConfigMysql::init(QSettings &settings)
+Index: akonadi-19.08.0/src/server/storage/dbconfigmysql.cpp
+===================================================================
+--- akonadi-19.08.0.orig/src/server/storage/dbconfigmysql.cpp
++++ akonadi-19.08.0/src/server/storage/dbconfigmysql.cpp
+@@ -83,7 +83,6 @@ bool DbConfigMysql::init(QSettings &sett
      // determine default settings depending on the driver
      QString defaultHostName;
      QString defaultOptions;
@@ -42,7 +42,7 @@ index dfff6fc29..419e54a5b 100644
      QString defaultCleanShutdownCommand;
  
  #ifndef Q_OS_WIN
-@@ -90,16 +89,7 @@ bool DbConfigMysql::init(QSettings &settings)
+@@ -92,16 +91,7 @@ bool DbConfigMysql::init(QSettings &sett
  #endif
  
      const bool defaultInternalServer = true;
@@ -59,8 +59,8 @@ index dfff6fc29..419e54a5b 100644
 +    const QString mysqladminPath = QLatin1String(NIXPKGS_MYSQL_MYSQLADMIN);
      if (!mysqladminPath.isEmpty()) {
  #ifndef Q_OS_WIN
-         defaultCleanShutdownCommand = QStringLiteral("%1 --defaults-file=%2/mysql.conf --socket=%3/mysql.socket shutdown")
-@@ -109,10 +99,10 @@ bool DbConfigMysql::init(QSettings &settings)
+         defaultCleanShutdownCommand = QStringLiteral("%1 --defaults-file=%2/mysql.conf --socket=%3/%4 shutdown")
+@@ -111,10 +101,10 @@ bool DbConfigMysql::init(QSettings &sett
  #endif
      }
  
@@ -73,7 +73,7 @@ index dfff6fc29..419e54a5b 100644
      qCDebug(AKONADISERVER_LOG) << "Found mysqlcheck: " << mMysqlCheckPath;
  
      mInternalServer = settings.value(QStringLiteral("QMYSQL/StartServer"), defaultInternalServer).toBool();
-@@ -129,7 +119,7 @@ bool DbConfigMysql::init(QSettings &settings)
+@@ -131,7 +121,7 @@ bool DbConfigMysql::init(QSettings &sett
      mUserName = settings.value(QStringLiteral("User")).toString();
      mPassword = settings.value(QStringLiteral("Password")).toString();
      mConnectionOptions = settings.value(QStringLiteral("Options"), defaultOptions).toString();
@@ -82,7 +82,7 @@ index dfff6fc29..419e54a5b 100644
      mCleanServerShutdownCommand = settings.value(QStringLiteral("CleanServerShutdownCommand"), defaultCleanShutdownCommand).toString();
      settings.endGroup();
  
-@@ -139,9 +129,6 @@ bool DbConfigMysql::init(QSettings &settings)
+@@ -141,9 +131,6 @@ bool DbConfigMysql::init(QSettings &sett
          // intentionally not namespaced as we are the only one in this db instance when using internal mode
          mDatabaseName = QStringLiteral("akonadi");
      }
@@ -92,7 +92,7 @@ index dfff6fc29..419e54a5b 100644
  
      qCDebug(AKONADISERVER_LOG) << "Using mysqld:" << mMysqldPath;
  
-@@ -150,9 +137,6 @@ bool DbConfigMysql::init(QSettings &settings)
+@@ -152,9 +139,6 @@ bool DbConfigMysql::init(QSettings &sett
      settings.setValue(QStringLiteral("Name"), mDatabaseName);
      settings.setValue(QStringLiteral("Host"), mHostName);
      settings.setValue(QStringLiteral("Options"), mConnectionOptions);
@@ -102,7 +102,7 @@ index dfff6fc29..419e54a5b 100644
      settings.setValue(QStringLiteral("StartServer"), mInternalServer);
      settings.endGroup();
      settings.sync();
-@@ -206,7 +190,7 @@ bool DbConfigMysql::startInternalServer()
+@@ -209,7 +193,7 @@ bool DbConfigMysql::startInternalServer(
  #endif
  
      // generate config file
@@ -111,56 +111,35 @@ index dfff6fc29..419e54a5b 100644
      const QString localConfig  = StandardDirs::locateResourceFile("config", QStringLiteral("mysql-local.conf"));
      const QString actualConfig = StandardDirs::saveDir("data") + QLatin1String("/mysql.conf");
      if (globalConfig.isEmpty()) {
-diff --git a/src/server/storage/dbconfigpostgresql.cpp b/src/server/storage/dbconfigpostgresql.cpp
-index 6b50ae50e..f94a8c5eb 100644
---- a/src/server/storage/dbconfigpostgresql.cpp
-+++ b/src/server/storage/dbconfigpostgresql.cpp
-@@ -58,7 +58,6 @@ bool DbConfigPostgresql::init(QSettings &settings)
+Index: akonadi-19.08.0/src/server/storage/dbconfigpostgresql.cpp
+===================================================================
+--- akonadi-19.08.0.orig/src/server/storage/dbconfigpostgresql.cpp
++++ akonadi-19.08.0/src/server/storage/dbconfigpostgresql.cpp
+@@ -140,9 +140,7 @@ bool DbConfigPostgresql::init(QSettings
      // determine default settings depending on the driver
      QString defaultHostName;
      QString defaultOptions;
 -    QString defaultServerPath;
      QString defaultInitDbPath;
+-    QString defaultPgUpgradePath;
      QString defaultPgData;
  
-@@ -70,35 +69,7 @@ bool DbConfigPostgresql::init(QSettings &settings)
+ #ifndef Q_WS_WIN // We assume that PostgreSQL is running as service on Windows
+@@ -153,12 +151,8 @@ bool DbConfigPostgresql::init(QSettings
  
      mInternalServer = settings.value(QStringLiteral("QPSQL/StartServer"), defaultInternalServer).toBool();
      if (mInternalServer) {
--        QStringList postgresSearchPath;
+-        const auto paths = postgresSearchPaths(QStringLiteral("/usr/lib/postgresql"));
 -
--#ifdef POSTGRES_PATH
--        const QString dir(QStringLiteral(POSTGRES_PATH));
--        if (QDir(dir).exists()) {
--            postgresSearchPath << QStringLiteral(POSTGRES_PATH);
--        }
--#endif
--        postgresSearchPath << QStringLiteral("/usr/bin")
--                           << QStringLiteral("/usr/sbin")
--                           << QStringLiteral("/usr/local/sbin");
--        // Locale all versions in /usr/lib/postgresql (i.e. /usr/lib/postgresql/X.Y) in reversed
--        // sorted order, so we search from the newest one to the oldest.
--        QStringList postgresVersionedSearchPaths;
--        QDir versionedDir(QStringLiteral("/usr/lib/postgresql"));
--        if (versionedDir.exists()) {
--            const auto versionedDirs = versionedDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name | QDir::Reversed);
--            for (const auto &path : versionedDirs) {
--                // Don't break once PostgreSQL 10 is released, but something more future-proof will be needed
--                if (path.fileName().startsWith(QLatin1String("10."))) {
--                    postgresVersionedSearchPaths.prepend(path.absoluteFilePath() + QStringLiteral("/bin"));
--                } else {
--                    postgresVersionedSearchPaths.append(path.absoluteFilePath() + QStringLiteral("/bin"));
--                }
--            }
--        }
--        postgresSearchPath.append(postgresVersionedSearchPaths);
--        defaultServerPath = QStandardPaths::findExecutable(QStringLiteral("pg_ctl"), postgresSearchPath);
--        defaultInitDbPath = QStandardPaths::findExecutable(QStringLiteral("initdb"), postgresSearchPath);
+-        defaultServerPath = QStandardPaths::findExecutable(QStringLiteral("pg_ctl"), paths);
+-        defaultInitDbPath = QStandardPaths::findExecutable(QStringLiteral("initdb"), paths);
 +        defaultInitDbPath = QLatin1String(NIXPKGS_POSTGRES_INITDB);
          defaultHostName = Utils::preferredSocketDirectory(StandardDirs::saveDir("data", QStringLiteral("db_misc")));
+-        defaultPgUpgradePath = QStandardPaths::findExecutable(QStringLiteral("pg_upgrade"), paths);
          defaultPgData = StandardDirs::saveDir("data", QStringLiteral("db_data"));
      }
-@@ -118,10 +89,7 @@ bool DbConfigPostgresql::init(QSettings &settings)
+ 
+@@ -177,20 +171,14 @@ bool DbConfigPostgresql::init(QSettings
      mUserName = settings.value(QStringLiteral("User")).toString();
      mPassword = settings.value(QStringLiteral("Password")).toString();
      mConnectionOptions = settings.value(QStringLiteral("Options"), defaultOptions).toString();
@@ -172,7 +151,18 @@ index 6b50ae50e..f94a8c5eb 100644
      qCDebug(AKONADISERVER_LOG) << "Found pg_ctl:" << mServerPath;
      mInitDbPath = settings.value(QStringLiteral("InitDbPath"), defaultInitDbPath).toString();
      if (mInternalServer && mInitDbPath.isEmpty()) {
-@@ -142,7 +110,6 @@ bool DbConfigPostgresql::init(QSettings &settings)
+         mInitDbPath = defaultInitDbPath;
+     }
+     qCDebug(AKONADISERVER_LOG) << "Found initdb:" << mServerPath;
+-    mPgUpgradePath = settings.value(QStringLiteral("UpgradePath"), defaultPgUpgradePath).toString();
+-    if (mInternalServer && mPgUpgradePath.isEmpty()) {
+-        mPgUpgradePath = defaultPgUpgradePath;
+-    }
++    mPgUpgradePath = QLatin1String(NIXPKGS_POSTGRES_PG_UPGRADE);
+     qCDebug(AKONADISERVER_LOG) << "Found pg_upgrade:" << mPgUpgradePath;
+     mPgData = settings.value(QStringLiteral("PgData"), defaultPgData).toString();
+     if (mPgData.isEmpty()) {
+@@ -206,7 +194,6 @@ bool DbConfigPostgresql::init(QSettings
          settings.setValue(QStringLiteral("Port"), mHostPort);
      }
      settings.setValue(QStringLiteral("Options"), mConnectionOptions);
@@ -180,6 +170,3 @@ index 6b50ae50e..f94a8c5eb 100644
      settings.setValue(QStringLiteral("InitDbPath"), mInitDbPath);
      settings.setValue(QStringLiteral("StartServer"), mInternalServer);
      settings.endGroup();
--- 
-2.18.1
-
diff --git a/pkgs/applications/kde/akonadi/akonadi-timestamps.patch b/pkgs/applications/kde/akonadi/akonadi-timestamps.patch
index 25a835f5ba24..e299a6991f05 100644
--- a/pkgs/applications/kde/akonadi/akonadi-timestamps.patch
+++ b/pkgs/applications/kde/akonadi/akonadi-timestamps.patch
@@ -1,8 +1,8 @@
-Index: akonadi-17.04.0/src/server/storage/dbconfigmysql.cpp
+Index: akonadi-19.08.0/src/server/storage/dbconfigmysql.cpp
 ===================================================================
---- akonadi-17.04.0.orig/src/server/storage/dbconfigmysql.cpp
-+++ akonadi-17.04.0/src/server/storage/dbconfigmysql.cpp
-@@ -229,8 +229,7 @@ bool DbConfigMysql::startInternalServer(
+--- akonadi-19.08.0.orig/src/server/storage/dbconfigmysql.cpp
++++ akonadi-19.08.0/src/server/storage/dbconfigmysql.cpp
+@@ -235,8 +235,7 @@ bool DbConfigMysql::startInternalServer(
      bool confUpdate = false;
      QFile actualFile(actualConfig);
      // update conf only if either global (or local) is newer than actual
diff --git a/pkgs/applications/kde/akonadi/default.nix b/pkgs/applications/kde/akonadi/default.nix
index cba0b1e59e3a..b9a96394a674 100644
--- a/pkgs/applications/kde/akonadi/default.nix
+++ b/pkgs/applications/kde/akonadi/default.nix
@@ -25,6 +25,7 @@ mkDerivation {
     ''-DNIXPKGS_MYSQL_MYSQL_INSTALL_DB=\"${lib.getBin mysql}/bin/mysql_install_db\"''
     ''-DNIXPKGS_MYSQL_MYSQLCHECK=\"${lib.getBin mysql}/bin/mysqlcheck\"''
     ''-DNIXPKGS_POSTGRES_PG_CTL=\"\"''
+    ''-DNIXPKGS_POSTGRES_PG_UPGRADE=\"\"''
     ''-DNIXPKGS_POSTGRES_INITDB=\"\"''
   ];
   preConfigure = ''