X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=nixops%2Fmodules%2Fdatabases%2Fpostgresql.nix;h=de0820f238ef1559145c3e64ad0e14858a318ca2;hb=b9723c401f244f83d5cfc8074bdb5f6a98884f00;hp=673ced872b23d0dc2a51248d1e613ac06f2dc2cf;hpb=587b9e340bb5cb14ca55e62a0498295e702b56c5;p=perso%2FImmae%2FConfig%2FNix.git diff --git a/nixops/modules/databases/postgresql.nix b/nixops/modules/databases/postgresql.nix index 673ced8..de0820f 100644 --- a/nixops/modules/databases/postgresql.nix +++ b/nixops/modules/databases/postgresql.nix @@ -1,4 +1,4 @@ -{ lib, pkgs, config, myconfig, mylibs, ... }: +{ lib, pkgs, config, myconfig, ... }: let cfg = config.services.myDatabases; in { @@ -15,15 +15,7 @@ in { config = lib.mkIf cfg.enable { nixpkgs.overlays = [ (self: super: rec { - postgresql = postgresql_11; - postgresql_11 = super.postgresql_11.overrideAttrs(old: rec { - passthru = old.passthru // { psqlSchema = "11.0"; }; - configureFlags = old.configureFlags ++ [ "--with-pam" ]; - buildInputs = (old.buildInputs or []) ++ [ self.pam ]; - patches = old.patches ++ [ - ./postgresql_run_socket_path.patch - ]; - }); + postgresql = self.postgresql_11_custom; }) ]; networking.firewall.allowedTCPPorts = [ 5432 ]; @@ -38,10 +30,8 @@ in { ''; }; - system.activationScripts.postgresql = '' - install -m 0755 -o postgres -g postgres -d ${myconfig.env.databases.postgresql.socket} - ''; - + systemd.services.postgresql.serviceConfig.SupplementaryGroups = "keys"; + systemd.services.postgresql.serviceConfig.RuntimeDirectory = "postgresql"; services.postgresql = rec { enable = cfg.postgresql.enable; package = pkgs.postgresql; @@ -76,38 +66,52 @@ in { ''; }; - security.pam.services = let - pam_ldap = "${pkgs.pam_ldap}/lib/security/pam_ldap.so"; - pam_ldap_postgresql = with myconfig.env.databases.postgresql.pam; - pkgs.writeText "postgresql.conf" '' - host ${myconfig.env.ldap.host} - base ${myconfig.env.ldap.base} - binddn ${dn} - bindpw ${password} - pam_filter ${filter} - ssl start_tls + secrets.keys = [ + { + dest = "postgresql/pam"; + permissions = "0400"; + group = "postgres"; + user = "postgres"; + text = with myconfig.env.databases.postgresql.pam; '' + host ${myconfig.env.ldap.host} + base ${myconfig.env.ldap.base} + binddn ${dn} + bindpw ${password} + pam_filter ${filter} + ssl start_tls ''; - pam_ldap_postgresql_replication = pkgs.writeText "postgresql.conf" '' - host ${myconfig.env.ldap.host} - base ${myconfig.env.ldap.base} - binddn ${myconfig.env.ldap.host_dn} - bindpw ${myconfig.env.ldap.password} - pam_login_attribute cn - ssl start_tls + } + { + dest = "postgresql/pam_replication"; + permissions = "0400"; + group = "postgres"; + user = "postgres"; + text = '' + host ${myconfig.env.ldap.host} + base ${myconfig.env.ldap.base} + binddn ${myconfig.env.ldap.host_dn} + bindpw ${myconfig.env.ldap.password} + pam_login_attribute cn + ssl start_tls ''; + } + ]; + + security.pam.services = let + pam_ldap = "${pkgs.pam_ldap}/lib/security/pam_ldap.so"; in [ { name = "postgresql"; text = '' - auth required ${pam_ldap} config=${pam_ldap_postgresql} - account required ${pam_ldap} config=${pam_ldap_postgresql} + auth required ${pam_ldap} config=/var/secrets/postgresql/pam + account required ${pam_ldap} config=/var/secrets/postgresql/pam ''; } { name = "postgresql_replication"; text = '' - auth required ${pam_ldap} config=${pam_ldap_postgresql_replication} - account required ${pam_ldap} config=${pam_ldap_postgresql_replication} + auth required ${pam_ldap} config=/var/secrets/postgresql/pam_replication + account required ${pam_ldap} config=/var/secrets/postgresql/pam_replication ''; } ];