mirror of
https://github.com/CHN-beta/nixos.git
synced 2026-01-12 04:39:23 +08:00
services.mariadb: init
This commit is contained in:
@@ -21,6 +21,7 @@ inputs:
|
||||
./frp.nix
|
||||
./beesd.nix
|
||||
./snapper.nix
|
||||
./mariadb.nix
|
||||
];
|
||||
options.nixos.services = let inherit (inputs.lib) mkOption types; in
|
||||
{
|
||||
|
||||
43
modules/services/mariadb.nix
Normal file
43
modules/services/mariadb.nix
Normal file
@@ -0,0 +1,43 @@
|
||||
inputs:
|
||||
{
|
||||
options.nixos.services.mariadb = let inherit (inputs.lib) mkOption types; in
|
||||
{
|
||||
enable = mkOption { type = types.bool; default = false; };
|
||||
instances = mkOption
|
||||
{
|
||||
type = types.attrsOf (types.submodule (submoduleInputs: { options =
|
||||
{
|
||||
database = mkOption { type = types.nonEmptyStr; default = submoduleInputs.config._module.args.name; };
|
||||
user = mkOption { type = types.nonEmptyStr; default = submoduleInputs.config._module.args.name; };
|
||||
passwordFile = mkOption { type = types.nullOr types.nonEmptyStr; default = null; };
|
||||
};}));
|
||||
default = {};
|
||||
};
|
||||
};
|
||||
config =
|
||||
let
|
||||
inherit (inputs.config.nixos.services) mariadb;
|
||||
inherit (inputs.lib) mkIf;
|
||||
inherit (inputs.localLib) attrsToList;
|
||||
inherit (builtins) map listToAttrs filter;
|
||||
in mkIf mariadb.enable
|
||||
{
|
||||
services =
|
||||
{
|
||||
mysql =
|
||||
{
|
||||
enable = true;
|
||||
ensureDatabases = map (db: db.value.database) (attrsToList mariadb.instances);
|
||||
ensureUsers = map (db: { name = db.value.user; }) (attrsToList mariadb.instances);
|
||||
};
|
||||
mysqlBackup =
|
||||
{
|
||||
enable = true;
|
||||
databases = map (db: db.value.database) (attrsToList mariadb.instances);
|
||||
};
|
||||
};
|
||||
sops.secrets = listToAttrs (map
|
||||
(db: { name = "mariadb/${db.value.user}"; value.owner = inputs.config.users.users.mysql.name; })
|
||||
(filter (db: db.value.passwordFile == null) (attrsToList mariadb.instances)));
|
||||
};
|
||||
}
|
||||
@@ -17,8 +17,8 @@ inputs:
|
||||
config =
|
||||
let
|
||||
inherit (inputs.config.nixos.services) postgresql;
|
||||
inherit (inputs.lib) mkMerge mkAfter concatStringsSep mkIf;
|
||||
inherit (inputs.localLib) stripeTabs attrsToList;
|
||||
inherit (inputs.lib) mkAfter concatStringsSep mkIf;
|
||||
inherit (inputs.localLib) attrsToList;
|
||||
inherit (builtins) map listToAttrs filter;
|
||||
in mkIf postgresql.enable
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user