nixos

NixOS server files. Mirror from https://git.nordgedanken.dev/kubernetes/nixos
git clone git://archive.git.mtrnord.blog/MTRNord/nixos.git
Log | Files | Refs | README

commit 6af1ac44501a18b9701f3b1a92e266e29b3aac19
parent 90680acc0b46df2cc8a570e046235fe790c70689
Author: MTRNord <mtrnord1@gmail.com>
Date:   Sun, 10 Sep 2023 14:24:42 +0200

Use confd for pgbouncer config

Diffstat:
Anixos/common/lib/confd.nix | 77+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mnixos/common/lib/pgbouncer.nix | 48++++++++++++++++++++++++------------------------
Mnixos/common/lib/pgcat.nix | 35-----------------------------------
Mnixos/worker-1/configuration.nix | 3++-
4 files changed, 103 insertions(+), 60 deletions(-)

diff --git a/nixos/common/lib/confd.nix b/nixos/common/lib/confd.nix @@ -0,0 +1,77 @@ +{ lib, pkgs, config, ... }: +{ + services.confd = { + enable = true; + nodes = [ + "http://100.64.0.3:2379" + "http://100.64.0.1:2379" + ]; + prefix = "/service/cluster-1"; + }; + environment.etc = { + "confd/conf.d/pgcat.toml" = { + text = '' + [template] + prefix = "/service/cluster-1" + uid = 985 + gid = 983 + mode = "0644" + src = "pgcat.toml.tmpl" + dest = "/etc/pgcat/pgcat.toml" + + reload_cmd = "systemctl reload pgcat" + + keys = [ + "/", "/members/","/leader" + ] + ''; + }; + "confd/conf.d/pgbouncer.toml" = { + text = '' + [template] + prefix = "/service/cluster-1" + uid = 986 + gid = 984 + mode = "0644" + src = "pgbouncer.tmpl" + dest = "/etc/pgbouncer/pgbouncer.ini" + + reload_cmd = "systemctl reload pgbouncer" + + keys = [ + "/members/", "/leader" + ] + ''; + }; + "confd/templates/pgbouncer.tmpl" = { + text = '' + [databases] + {{with get "/leader"}}{{$leader := .Value}}{{$leadkey := printf "/members/%s" $leader}}{{with get $leadkey}}{{$data := json .Value}}{{$hostport := base (replace (index (split $data.conn_url "/") 2) "@" "/" -1)}}{{ $host := base (index (split $hostport ":") 0)}}{{ $port := base (index (split $hostport ":") 1)}}* = host={{ $host }} port={{ $port }} pool_size=10{{end}}{{end}} + + [pgbouncer] + listen_addr = * + listen_port = 5000 + + ignore_startup_parameters = extra_float_digits + prepared_statement_cache_size = 10000 + + auth_type = md5 + auth_hba_file = /etc/pgbouncer/pg_hba.conf + auth_file = ${config.sops.secrets.pgbouncer_auth_file.path} + + pool_mode = transaction + max_client_conn = 200 + default_pool_size = 10 + min_pool_size = 2 + reserve_pool_size = 5 + ''; + }; + }; + # Ensure confd can create a config + system.activationScripts = { + postgresqlMkdir = { + text = "mkdir -p /etc/pgcat && chown pgcat:pgcat -R /etc/pgcat && chmod o+w /etc/pgcat"; + deps = [ ]; + }; + }; +} diff --git a/nixos/common/lib/pgbouncer.nix b/nixos/common/lib/pgbouncer.nix @@ -44,33 +44,33 @@ host all all 10.244.0.0/10 md5 ''; }; - "pgbouncer/pgbouncer.ini" = { - user = config.users.users.pgbouncer.name; - group = config.users.users.pgbouncer.group; - text = '' - [databases] - * = host=10.100.0.2 port=5432 pool_size=10 - * = host=10.100.0.1 port=5432 pool_size=10 + # "pgbouncer/pgbouncer.ini" = { + # user = config.users.users.pgbouncer.name; + # group = config.users.users.pgbouncer.group; + # text = '' + # [databases] + # * = host=10.100.0.2 port=5432 pool_size=10 + # * = host=10.100.0.1 port=5432 pool_size=10 - [pgbouncer] - listen_addr = * - listen_port = 5000 + # [pgbouncer] + # listen_addr = * + # listen_port = 5000 - ignore_startup_parameters = extra_float_digits - prepared_statement_cache_size = 10000 + # ignore_startup_parameters = extra_float_digits + # prepared_statement_cache_size = 10000 - ; Define your PgBouncer user and password here (replace with your actual values) - auth_type = md5 - auth_hba_file = /etc/pgbouncer/pg_hba.conf - auth_file = ${config.sops.secrets.pgbouncer_auth_file.path} + # ; Define your PgBouncer user and password here (replace with your actual values) + # auth_type = md5 + # auth_hba_file = /etc/pgbouncer/pg_hba.conf + # auth_file = ${config.sops.secrets.pgbouncer_auth_file.path} - ; Connection Pooling Settings - pool_mode = transaction - max_client_conn = 200 - default_pool_size = 10 - min_pool_size = 2 - reserve_pool_size = 5 - ''; - }; + # ; Connection Pooling Settings + # pool_mode = transaction + # max_client_conn = 200 + # default_pool_size = 10 + # min_pool_size = 2 + # reserve_pool_size = 5 + # ''; + # }; }; } diff --git a/nixos/common/lib/pgcat.nix b/nixos/common/lib/pgcat.nix @@ -36,39 +36,4 @@ Group = config.users.users.pgcat.group; # Set the group under which PgCat should run }; }; - - services.confd = { - enable = true; - nodes = [ - "http://100.64.0.3:2379" - "http://100.64.0.1:2379" - ]; - prefix = "/service/cluster-1"; - }; - environment.etc = { - "confd/conf.d/pgcat.toml" = { - text = '' - [template] - prefix = "/service/cluster-1" - uid = 985 - gid = 983 - mode = "0644" - src = "pgcat.toml.tmpl" - dest = "/etc/pgcat/pgcat.toml" - - reload_cmd = "systemctl reload pgcat" - - keys = [ - "/", "/members/","/leader" - ] - ''; - }; - }; - # Ensure confd can create a config - system.activationScripts = { - postgresqlMkdir = { - text = "mkdir -p /etc/pgcat && chown pgcat:pgcat -R /etc/pgcat && chmod o+w /etc/pgcat"; - deps = [ ]; - }; - }; } diff --git a/nixos/worker-1/configuration.nix b/nixos/worker-1/configuration.nix @@ -27,8 +27,9 @@ ../common/lib/shell.nix ../common/lib/patroni.nix - ../common/lib/pgadmin.nix + ../common/lib/confd.nix ../common/lib/pgbouncer.nix + ../common/lib/pgadmin.nix ../common/lib/envoy.nix ../common/lib/fail2ban.nix ../common/lib/podman.nix