diff --git a/lib/default.nix b/lib/default.nix index c5011e9..37567ce 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -4,4 +4,16 @@ type = lib.types.str; default = ""; }; + mkPortOption = + port: + lib.mkOption { + type = lib.types.port; + default = port; + }; + mkPathOption = + path: + lib.mkOption { + type = lib.types.path; + default = path; + }; } diff --git a/modules/nixos/server/databases/default.nix b/modules/nixos/server/databases/default.nix index f404741..640d587 100644 --- a/modules/nixos/server/databases/default.nix +++ b/modules/nixos/server/databases/default.nix @@ -1,38 +1,58 @@ -{ lib, config, ... }: +{ + lib, + config, + pkgs, + ... +}: let cfg = config.server.databases; in { options.server.databases = { - mongodb.enable = lib.mkEnableOption ""; - mongodb.dbPath = lib.mkOption { - type = lib.types.str; - default = "/var/db/mongodb"; + mongodb = { + enable = lib.mkEnableOption "the MongoDB server"; + port = lib.pantheon.mkPortOption 27017; }; - mongodb.port = lib.mkOption { - type = lib.types.int; - default = 27017; + mysql = { + enable = lib.mkEnableOption "the MySQL server"; + port = lib.pantheon.mkPortOption 3306; }; }; config = lib.mkMerge [ (lib.mkIf cfg.mongodb.enable { + networking.firewall.allowedTCPPorts = [ cfg.mongodb.port ]; environment.persistence."/persist".directories = [ { - directory = cfg.mongodb.dbPath; + directory = builtins.toString config.services.mongodb.dbpath; user = "mongodb"; group = "mongodb"; } ]; - networking.firewall.allowedTCPPorts = [ cfg.mongodb.port ]; services.mongodb = { enable = true; - dbpath = cfg.mongodb.dbPath; bind_ip = "0.0.0.0"; extraConfig = '' 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; + }; + }; + }) ]; } diff --git a/systems/x86_64-linux/apollo/default.nix b/systems/x86_64-linux/apollo/default.nix index c73d048..a89aa9c 100644 --- a/systems/x86_64-linux/apollo/default.nix +++ b/systems/x86_64-linux/apollo/default.nix @@ -25,6 +25,7 @@ enableDDNS = true; mountHelios = true; databases.mongodb.enable = true; + databases.mysql.enable = true; librechat.enable = true; };