X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=modules%2Fprivate%2Fdatabases%2Fpostgresql_replication.nix;h=135bbed0d90bfbc9cd239727ab3ddbfc5a88e649;hb=4c4652aabf2cb3ac8b40f2856eca07a1df9c27e0;hp=7172c5e6e31f9c2046574a80b81e15571c5742c7;hpb=4c853ba6f422460ebfb775856920542db6a88fb8;p=perso%2FImmae%2FConfig%2FNix.git diff --git a/modules/private/databases/postgresql_replication.nix b/modules/private/databases/postgresql_replication.nix index 7172c5e..135bbed 100644 --- a/modules/private/databases/postgresql_replication.nix +++ b/modules/private/databases/postgresql_replication.nix @@ -11,6 +11,13 @@ in Base path to put the replications ''; }; + mainPackage = lib.mkOption { + type = lib.types.package; + default = pkgs.postgresql; + description = '' + Postgresql package available in shell + ''; + }; hosts = lib.mkOption { default = {}; description = '' @@ -43,10 +50,6 @@ in }; config = lib.mkIf cfg.enable { - nixpkgs.overlays = [ (self: super: { - postgresql = self.postgresql_11_custom; - }) ]; - users.users.postgres = { name = "postgres"; uid = config.ids.uids.postgres; @@ -57,11 +60,10 @@ in extraGroups = [ "keys" ]; }; users.groups.postgres.gid = config.ids.gids.postgres; - environment.systemPackages = [ pkgs.postgresql ]; + environment.systemPackages = [ cfg.mainPackage ]; - secrets.keys = lib.flatten (lib.mapAttrsToList (name: hcfg: [ - { - dest = "postgresql_replication/${name}/recovery.conf"; + secrets.keys = lib.listToAttrs (lib.flatten (lib.mapAttrsToList (name: hcfg: [ + (lib.nameValuePair "postgresql_replication/${name}/recovery.conf" { user = "postgres"; group = "postgres"; permissions = "0400"; @@ -70,16 +72,14 @@ in primary_conninfo = '${hcfg.connection}?sslmode=require' primary_slot_name = '${hcfg.slot}' ''; - } - { - dest = "postgresql_replication/${name}/connection_string"; + }) + (lib.nameValuePair "postgresql_replication/${name}/connection_string" { user = "postgres"; group = "postgres"; permissions = "0400"; text = hcfg.connection; - } - { - dest = "postgresql_replication/${name}/postgresql.conf"; + }) + (lib.nameValuePair "postgresql_replication/${name}/postgresql.conf" { user = "postgres"; group = "postgres"; permissions = "0400"; @@ -91,8 +91,8 @@ in data_directory = '${dataDir}' wal_level = logical ''; - } - ]) cfg.hosts); + }) + ]) cfg.hosts)); services.cron = { enable = true; @@ -116,7 +116,7 @@ in ${hcfg.package}/bin/pg_dumpall -h ${dataDir} -f ${backupDir}/$(${pkgs.coreutils}/bin/date -Iminutes).sql ''; u = pkgs.callPackage ./utils.nix {}; - cleanup_script = pkgs.writeScript "cleanup_postgresql_${name}" (u.keepLastNDumps "sql" backupDir 12); + cleanup_script = pkgs.writeScript "cleanup_postgresql_${name}" (u.keepLastNDumps "sql" backupDir 6); in [ "0 22,4,10,16 * * * postgres ${backup_script}" "0 3 * * * postgres ${cleanup_script}"