Add nix-infra-machine

This commit is contained in:
Ruben Hensen
2026-03-15 18:31:53 +01:00
parent 28ea6f4a47
commit 1034986fa1
79 changed files with 14465 additions and 0 deletions
@@ -0,0 +1,48 @@
{ config, pkgs, lib, ... }:
let
appName = "mongodb";
defaultPort = 27017;
cfg = config.infrastructure.${appName};
in
{
options.infrastructure.${appName} = {
enable = lib.mkEnableOption "infrastructure.mongodb";
package = lib.mkOption {
type = lib.types.package;
description = "MongoDB package to use.";
default = pkgs.mongodb-ce;
example = "pkgs.mongodb";
};
bindToIp = lib.mkOption {
type = lib.types.str;
description = "IP address to bind.";
default = "127.0.0.1";
};
bindToPort = lib.mkOption {
type = lib.types.int;
description = "Port to bind.";
default = defaultPort;
};
};
config = lib.mkIf cfg.enable {
services.mongodb = {
enable = true;
package = cfg.package;
bind_ip = cfg.bindToIp;
extraConfig = lib.mkIf (cfg.bindToPort != defaultPort) ''
net.port: ${toString cfg.bindToPort}
'';
};
# Install mongosh for CLI access
environment.systemPackages = [ pkgs.mongosh ];
# Open firewall for MongoDB if binding to non-localhost
networking.firewall.allowedTCPPorts = lib.mkIf (cfg.bindToIp != "127.0.0.1") [ cfg.bindToPort ];
};
}