{ config, pkgs, lib, user, ... }:
{
	services = {
		postgresql = {
			enable = true;
			package = pkgs.postgresql_12;
			dataDir = "/var/lib/postgresql/${config.services.postgresql.package.psqlSchema}"; # default
			# identMap = ''
				# ${user} ${user} ${user} 
			# '';
			enableJIT = false; # default
			initdbArgs = []; # default
			checkConfig = true; # default
			enableTCPIP = false;
			# # extraPlugins =
			initialScript = null; # default
	    authentication = lib.mkForce ''
		    # TYPE  DATABASE        USER            ADDRESS                 METHOD
		    local   all             all                                     trust
		    host    all             all             127.0.0.1/32            trust #scram-sha-256
		    host    all             all             ::1/128                 trust #scram-sha-256
	    '';
 			# recoveryConfig = null;
			ensureDatabases = [
				"gitea"
				"vaultwarden"
			];
			settings = {
				port = 5432; # default
				listen_addresses = lib.mkForce "127.0.0.1";
				log_line_prefix = "[%p] "; # default
				shared_preload_libraries = [ ]; # default
			};
			ensureUsers = [
			  # as liong as there is no declarative user management you gotta set a pw by hand
				# sudo -u postgres psql -c "ALTER USER gitea PASSWORD 'new-passwd';"
				{
					name = "gitea"; 
					ensureDBOwnership = true;
				}
				{
					name = "vaultwarden";
					ensureDBOwnership = true;
				}
			];
		};
		postgresqlBackup = {
			enable = true;
			# startAt = "*-*-* 01:15:00";
			# location = "/var/backup/postgresql";
			databases = config.services.postgresql.ensureDatabases;
			backupAll = false;
			# compression = "gzip";
			# pgdumpOptions = "-C";
			# compressionLevel = 6;
		};
	# postgresqlWalReceiver.receivers."main" = {
	#     postgresqlPackage = pkgs.postgresql_15;
	#     directory = /mnt/pg_wal/main/;
	#     slot = "main_wal_receiver";
	#     connection = "postgresql://user@somehost";
	# 	compress
	# 	extraArgs
	# 	synchronous
	# 	environment
	# 	statusInterval
	#   };
	# };
	};
}




