2023-08-17 22:37:52 +05:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
{
|
|
|
|
config.services.postgresql = {
|
|
|
|
enable = true;
|
|
|
|
package = pkgs.postgresql_15;
|
2023-08-23 17:23:47 +05:00
|
|
|
ensureDatabases = [ "mastodon" "matrix-synapse" "nextcloud" "maddy" "plausible" "microboard" "freshrss" ];
|
2023-08-18 09:59:23 +05:00
|
|
|
ensureUsers = [
|
|
|
|
{
|
|
|
|
name = "mastodon";
|
|
|
|
ensurePermissions = {
|
|
|
|
"DATABASE mastodon" = "ALL PRIVILEGES";
|
|
|
|
};
|
2023-08-19 09:39:02 +05:00
|
|
|
ensureClauses.login = true;
|
2023-08-18 09:59:23 +05:00
|
|
|
}
|
2023-08-18 17:33:59 +05:00
|
|
|
{
|
|
|
|
name = "nextcloud";
|
|
|
|
ensurePermissions = {
|
|
|
|
"DATABASE nextcloud" = "ALL PRIVILEGES";
|
|
|
|
};
|
2023-08-19 09:39:02 +05:00
|
|
|
ensureClauses.login = true;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
name = "matrix-synapse";
|
|
|
|
ensurePermissions = {
|
|
|
|
"DATABASE \"matrix-synapse\"" = "ALL PRIVILEGES";
|
2023-08-18 17:33:59 +05:00
|
|
|
};
|
2023-08-19 09:39:02 +05:00
|
|
|
ensureClauses.login = true;
|
2023-08-18 17:33:59 +05:00
|
|
|
}
|
2023-08-19 16:34:35 +05:00
|
|
|
{
|
|
|
|
name = "maddy";
|
|
|
|
ensurePermissions = {
|
|
|
|
"DATABASE maddy" = "ALL PRIVILEGES";
|
|
|
|
};
|
|
|
|
ensureClauses.login = true;
|
|
|
|
}
|
2023-08-19 20:23:00 +05:00
|
|
|
{
|
|
|
|
name = "plausible";
|
|
|
|
ensurePermissions = {
|
|
|
|
"DATABASE plausible" = "ALL PRIVILEGES";
|
|
|
|
};
|
|
|
|
ensureClauses.login = true;
|
|
|
|
}
|
2023-08-20 22:19:38 +05:00
|
|
|
{
|
|
|
|
name = "microboard";
|
|
|
|
ensurePermissions = {
|
|
|
|
"DATABASE microboard" = "ALL PRIVILEGES";
|
|
|
|
};
|
|
|
|
ensureClauses.login = true;
|
|
|
|
}
|
2023-08-23 17:23:47 +05:00
|
|
|
{
|
|
|
|
name = "freshrss";
|
|
|
|
ensurePermissions = {
|
|
|
|
"DATABASE freshrss" = "ALL PRIVILEGES";
|
|
|
|
};
|
|
|
|
ensureClauses.login = true;
|
|
|
|
}
|
2023-08-18 09:59:23 +05:00
|
|
|
];
|
2023-08-19 09:39:02 +05:00
|
|
|
initialScript = pkgs.writeText "pg-init.sql" ''
|
|
|
|
ALTER DATABASE nextcloud OWNER TO nextcloud;
|
|
|
|
ALTER DATABASE mastodon OWNER TO mastodon;
|
|
|
|
ALTER DATABASE "matrix-synapse" OWNER TO "matrix-synapse";
|
2023-08-19 16:34:35 +05:00
|
|
|
ALTER DATABASE maddy OWNER TO maddy;
|
2023-08-19 20:23:00 +05:00
|
|
|
ALTER DATABASE plausible OWNER TO plausible;
|
2023-08-20 22:19:38 +05:00
|
|
|
ALTER DATABASE microboard OWNER TO microboard;
|
2023-08-23 17:23:47 +05:00
|
|
|
ALTER DATABASE freshrss OWNER TO freshrss;
|
2023-08-19 09:39:02 +05:00
|
|
|
'';
|
2023-08-17 22:37:52 +05:00
|
|
|
identMap = ''
|
|
|
|
# ArbitraryMapName systemUser DBUser
|
|
|
|
superuser_map root postgres
|
|
|
|
superuser_map postgres postgres
|
|
|
|
|
|
|
|
# Let other names login as themselves
|
|
|
|
superuser_map /^(.*)$ \1
|
|
|
|
'';
|
|
|
|
authentication = pkgs.lib.mkOverride 10 ''
|
2023-08-23 17:27:58 +05:00
|
|
|
#type database DBuser auth-method optional_ident_map
|
|
|
|
local sameuser all peer map=superuser_map
|
|
|
|
|
|
|
|
#type database DBuser origin-address auth-method
|
|
|
|
host all all 127.0.0.1/32 scram-sha-256
|
2023-08-17 22:37:52 +05:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|