mysql: Use ensure* options, split definition up into service files.
note/reason for split: nixos submodule option names aren't standardized...
This commit is contained in:
parent
627a45c070
commit
92cd95d6ce
3 changed files with 56 additions and 45 deletions
|
@ -3,7 +3,8 @@
|
|||
with lib;
|
||||
|
||||
mkIf (elem "gitea" config.machine.services) {
|
||||
services.gitea = let
|
||||
services = {
|
||||
gitea = let
|
||||
cfg = config.machine;
|
||||
domain = (findFirst (s: s.service == "gitea") cfg cfg.vHosts).domain;
|
||||
in {
|
||||
|
@ -33,6 +34,19 @@ mkIf (elem "gitea" config.machine.services) {
|
|||
'';
|
||||
};
|
||||
|
||||
mysql = let
|
||||
cfg = config.services.gitea.database;
|
||||
in {
|
||||
ensureDatabases = [ cfg.name ];
|
||||
ensureUsers = [{
|
||||
name = cfg.user;
|
||||
ensurePermissions = {
|
||||
"${cfg.name}.*" = "ALL PRIVILEGES";
|
||||
};
|
||||
}];
|
||||
};
|
||||
};
|
||||
|
||||
users.users.git = {
|
||||
description = "Gitea Service";
|
||||
isNormalUser = true;
|
||||
|
|
|
@ -2,24 +2,9 @@
|
|||
|
||||
with lib;
|
||||
|
||||
let
|
||||
cfg = config.services;
|
||||
mkInitialDatabases = servicename: if (cfg."${servicename}".enable && (cfg."${servicename}".database.type == "mysql")) then
|
||||
let
|
||||
password = (fileContents "${config.machine.secretPath}/${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 { name = ""; };
|
||||
in mkIf (elem "mariaDB" config.machine.services) {
|
||||
services.mysql = {
|
||||
mkIf (elem "mariaDB" config.machine.services) {
|
||||
services.mysql = rec {
|
||||
enable = true;
|
||||
package = pkgs.mariadb;
|
||||
initialDatabases = (map mkInitialDatabases [ "mailman3" "gitea" ]);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -47,5 +47,17 @@ mkIf (elem "nextcloud" config.machine.services) {
|
|||
no-multicast-peers
|
||||
'';
|
||||
};
|
||||
|
||||
mysql = let
|
||||
cfg = config.services.nextcloud.config;
|
||||
in {
|
||||
ensureDatabases = [ cfg.dbname ];
|
||||
ensureUsers = [{
|
||||
name = cfg.dbuser;
|
||||
ensurePermissions = {
|
||||
"${cfg.dbname}.*" = "ALL PRIVILEGES";
|
||||
};
|
||||
}];
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue