feat(nixosModules/databases): add mysql

This commit is contained in:
Mohammad Rafiq 2025-06-03 20:59:23 +08:00
parent b6da0aa2f1
commit e3e8f88460
No known key found for this signature in database
3 changed files with 44 additions and 11 deletions

View file

@ -4,4 +4,16 @@
type = lib.types.str; type = lib.types.str;
default = ""; default = "";
}; };
mkPortOption =
port:
lib.mkOption {
type = lib.types.port;
default = port;
};
mkPathOption =
path:
lib.mkOption {
type = lib.types.path;
default = path;
};
} }

View file

@ -1,38 +1,58 @@
{ lib, config, ... }: {
lib,
config,
pkgs,
...
}:
let let
cfg = config.server.databases; cfg = config.server.databases;
in in
{ {
options.server.databases = { options.server.databases = {
mongodb.enable = lib.mkEnableOption ""; mongodb = {
mongodb.dbPath = lib.mkOption { enable = lib.mkEnableOption "the MongoDB server";
type = lib.types.str; port = lib.pantheon.mkPortOption 27017;
default = "/var/db/mongodb";
}; };
mongodb.port = lib.mkOption { mysql = {
type = lib.types.int; enable = lib.mkEnableOption "the MySQL server";
default = 27017; port = lib.pantheon.mkPortOption 3306;
}; };
}; };
config = lib.mkMerge [ config = lib.mkMerge [
(lib.mkIf cfg.mongodb.enable { (lib.mkIf cfg.mongodb.enable {
networking.firewall.allowedTCPPorts = [ cfg.mongodb.port ];
environment.persistence."/persist".directories = [ environment.persistence."/persist".directories = [
{ {
directory = cfg.mongodb.dbPath; directory = builtins.toString config.services.mongodb.dbpath;
user = "mongodb"; user = "mongodb";
group = "mongodb"; group = "mongodb";
} }
]; ];
networking.firewall.allowedTCPPorts = [ cfg.mongodb.port ];
services.mongodb = { services.mongodb = {
enable = true; enable = true;
dbpath = cfg.mongodb.dbPath;
bind_ip = "0.0.0.0"; bind_ip = "0.0.0.0";
extraConfig = '' extraConfig = ''
net.port: ${builtins.toString cfg.mongodb.port} net.port: ${builtins.toString cfg.mongodb.port}
''; '';
}; };
}) })
(lib.mkIf cfg.mysql.enable {
networking.firewall.allowedTCPPorts = [ cfg.mysql.port ];
environment.persistence."/persist".directories = [
{
directory = builtins.toString config.services.mysql.dataDir;
user = "mysql";
group = "mysql";
}
];
services.mysql = {
enable = true;
package = pkgs.mariadb;
settings.mysqld = {
inherit (cfg.mysql) port;
};
};
})
]; ];
} }

View file

@ -25,6 +25,7 @@
enableDDNS = true; enableDDNS = true;
mountHelios = true; mountHelios = true;
databases.mongodb.enable = true; databases.mongodb.enable = true;
databases.mysql.enable = true;
librechat.enable = true; librechat.enable = true;
}; };