feat(nixosModules/server): add mongodb

This commit is contained in:
Mohammad Rafiq 2025-05-29 20:48:53 +08:00
parent 68b200175f
commit 2f23b952de
No known key found for this signature in database
2 changed files with 39 additions and 0 deletions

View file

@ -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}
'';
};
})
];
}