2019-03-20 02:57:59 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
2019-02-26 13:44:40 +01:00
|
|
|
|
|
|
|
let
|
2019-07-03 08:38:11 +02:00
|
|
|
cfg = config.services;
|
|
|
|
mkInitialDatabases = servicename: if (cfg."${servicename}".enable && (cfg."${servicename}".database.type == "mysql")) then
|
|
|
|
let
|
2019-08-28 15:56:19 +02:00
|
|
|
password = (fileContents "${config.machine.secretPath}/${servicename}_db");
|
2019-07-03 08:38:11 +02:00
|
|
|
cfg = config.services."${servicename}".database;
|
|
|
|
in {
|
|
|
|
name = cfg.name;
|
|
|
|
schema = pkgs.writeText "${cfg.name}.sql" ''
|
|
|
|
create user if not exists ${cfg.user}@'localhost' identified by ${password};
|
|
|
|
grant all privileges on ${cfg.name}.* to ${cfg.user}@'localhost' identified by ${password};
|
|
|
|
'';
|
2019-08-04 04:49:22 +02:00
|
|
|
} else { name = ""; };
|
2019-03-20 02:57:59 +01:00
|
|
|
in mkIf (elem "mariaDB" config.machine.services) {
|
2019-02-26 13:44:40 +01:00
|
|
|
services.mysql = {
|
|
|
|
enable = true;
|
|
|
|
package = pkgs.mariadb;
|
2019-07-03 08:38:11 +02:00
|
|
|
initialDatabases = (map mkInitialDatabases [ "mailman3" "gitea" ]);
|
2019-02-26 13:44:40 +01:00
|
|
|
};
|
|
|
|
}
|
2019-03-20 02:57:59 +01:00
|
|
|
|