nixos/services/mariaDB.nix

26 lines
811 B
Nix
Raw Normal View History

{ config, lib, pkgs, ... }:
with lib;
2019-02-26 13:44:40 +01:00
let
cfg = config.services;
mkInitialDatabases = servicename: if (cfg."${servicename}".enable && (cfg."${servicename}".database.type == "mysql")) then
let
password = (fileContents "/secret/${servicename}_db");
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};
'';
} else {};
in mkIf (elem "mariaDB" config.machine.services) {
2019-02-26 13:44:40 +01:00
services.mysql = {
enable = true;
package = pkgs.mariadb;
initialDatabases = (map mkInitialDatabases [ "mailman3" "gitea" ]);
2019-02-26 13:44:40 +01:00
};
}