1 { lib, pkgs, config, mylibs, ... }:
3 cfg = config.services.myDatabases;
5 options.services.myDatabases = {
6 enable = lib.mkEnableOption "my databases service";
8 enable = lib.mkOption {
11 description = "Whether to enable postgresql database";
12 type = lib.types.bool;
17 enable = lib.mkOption {
20 description = "Whether to enable mariadb database";
21 type = lib.types.bool;
26 enable = lib.mkOption {
29 description = "Whether to enable redis database";
30 type = lib.types.bool;
35 config = lib.mkIf cfg.enable {
36 nixpkgs.config.packageOverrides = oldpkgs: rec {
37 postgresql = postgresql111;
38 postgresql111 = oldpkgs.postgresql100.overrideAttrs(old: rec {
39 passthru = old.passthru // { psqlSchema = "11.0"; };
40 name = "postgresql-11.1";
42 url = "mirror://postgresql/source/v11.1/${name}.tar.bz2";
43 sha256 = "026v0sicsh7avzi45waf8shcbhivyxmi7qgn9fd1x0vl520mx0ch";
47 mariadbPAM = oldpkgs.mariadb.overrideAttrs(old: rec {
48 cmakeFlags = old.cmakeFlags ++ [ "-DWITH_AUTHENTICATION_PAM=ON" ];
49 buildInputs = old.buildInputs ++ [ pkgs.pam ];
53 networking.firewall.allowedTCPPorts = [ 3306 5432 ];
57 # FIXME: restart after pam
58 # FIXME: pam access doesn’t work (because of php module)
60 services.mysql = rec {
61 enable = cfg.mariadb.enable;
62 package = pkgs.mariadb;
68 services.postgresql = rec {
69 enable = cfg.postgresql.enable;
70 package = pkgs.postgresql;
75 shared_buffers = 128MB
78 log_timezone = 'Europe/Paris'
79 datestyle = 'iso, mdy'
80 timezone = 'Europe/Paris'
81 lc_messages = 'en_US.UTF-8'
82 lc_monetary = 'en_US.UTF-8'
83 lc_numeric = 'en_US.UTF-8'
84 lc_time = 'en_US.UTF-8'
85 default_text_search_config = 'pg_catalog.english'
87 # ssl_cert_file = '/var/lib/acme/eldiron/fullchain.pem'
88 # ssl_key_file = '/var/lib/acme/eldiron/key.pem'
91 local all postgres ident
93 host all all samehost md5
94 host all all 178.33.252.96/32 md5
95 host all all 188.165.209.148/32 md5
100 security.pam.services = let
101 pam_ldap = pkgs.pam_ldap;
102 pam_ldap_mysql = assert mylibs.checkEnv "NIXOPS_MYSQL_PAM_PASSWORD";
103 pkgs.writeText "mysql.conf" ''
106 binddn cn=mysql,cn=pam,ou=services,dc=immae,dc=eu
107 bindpw ${builtins.getEnv "NIXOPS_MYSQL_PAM_PASSWORD"}
108 pam_filter memberOf=cn=users,cn=mysql,cn=pam,ou=services,dc=immae,dc=eu
114 # https://mariadb.com/kb/en/mariadb/pam-authentication-plugin/
115 auth required ${pam_ldap}/lib/security/pam_ldap.so config=${pam_ldap_mysql}
116 account required ${pam_ldap}/lib/security/pam_ldap.so config=${pam_ldap_mysql}
123 services.redis = rec {
124 enable = config.services.myDatabases.redis.enable;
126 unixSocket = "/run/redis/redis.sock";
132 system.activationScripts.redis = ''
134 chown redis /run/redis