From 4752689cfb89d5945612fade8c8ac7430f083a2f Mon Sep 17 00:00:00 2001
From: Sergei Trofimovich <slyich@gmail.com>
Date: Sat, 4 Dec 2021 18:32:19 +0000
Subject: [PATCH] postgresqlPackages.pg_auto_failover: upstream fix for
 ncurses-6.3

Without the change the build fails as:

    watch.c:673:2: error: format not a string literal and no format arguments [-Werror=format-security]
      673 |  mvprintw(r, context->cols - strlen(help), help);
          |  ^~~~~~~~
---
 pkgs/servers/sql/postgresql/ext/pg_auto_failover.nix | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/pkgs/servers/sql/postgresql/ext/pg_auto_failover.nix b/pkgs/servers/sql/postgresql/ext/pg_auto_failover.nix
index 34654a3d0430..fb62bdd94eee 100644
--- a/pkgs/servers/sql/postgresql/ext/pg_auto_failover.nix
+++ b/pkgs/servers/sql/postgresql/ext/pg_auto_failover.nix
@@ -1,4 +1,4 @@
-{ lib, stdenv, fetchFromGitHub, postgresql, openssl, zlib, readline, libkrb5 }:
+{ lib, stdenv, fetchFromGitHub, fetchpatch, postgresql, openssl, zlib, readline, libkrb5 }:
 
 stdenv.mkDerivation rec {
   pname = "pg_auto_failover";
@@ -11,6 +11,16 @@ stdenv.mkDerivation rec {
     sha256 = "sha256-hGpcHV4ai9mxaJ/u/o9LNFWPGsW22W7ak2pbvAUgmwU=";
   };
 
+  patches = [
+    # Pull upstream fix for ncurses-6.3 support:
+    #  https://github.com/citusdata/pg_auto_failover/pull/830
+    (fetchpatch {
+      name = "ncurses-6.3.patch";
+      url = "https://github.com/citusdata/pg_auto_failover/commit/fc92546965437a6d5f82ed9a6bdc8204a3bca725.patch";
+      sha256 = "sha256-t4DC/d/2s/Mc44rpFxBMOWGhACG0s5wAWyeDD7Mefo8=";
+    })
+  ];
+
   buildInputs = [ postgresql openssl zlib readline libkrb5 ];
 
   installPhase = ''