diff --git a/modules/nixos/server/databases/default.nix b/modules/nixos/server/databases/default.nix new file mode 100644 index 0000000..f404741 --- /dev/null +++ b/modules/nixos/server/databases/default.nix @@ -0,0 +1,38 @@ +{ lib, config, ... }: +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.port = lib.mkOption { + type = lib.types.int; + default = 27017; + }; + }; + + config = lib.mkMerge [ + (lib.mkIf cfg.mongodb.enable { + environment.persistence."/persist".directories = [ + { + directory = cfg.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} + ''; + }; + }) + ]; +} diff --git a/systems/x86_64-linux/apollo/default.nix b/systems/x86_64-linux/apollo/default.nix index a771a83..6a985de 100644 --- a/systems/x86_64-linux/apollo/default.nix +++ b/systems/x86_64-linux/apollo/default.nix @@ -23,6 +23,7 @@ server = { enableDDNS = true; mountHelios = true; + databases.mongodb.enable = true; }; nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";