cratedocs-mcp/config.nix
Harald Hoyer abc74ceb94
Some checks failed
Rust / build (push) Failing after 13s
feat: open listen addr and add firewall config
2025-09-17 15:41:48 +02:00

75 lines
2.1 KiB
Nix

{ config, lib, pkgs, ... }:
let
cfg = config.services.cratedocs-mcp;
in
{
options.services.cratedocs-mcp = {
enable = lib.mkEnableOption "CrateDocs MCP server";
port = lib.mkOption {
type = lib.types.int;
default = 3000;
description = "Port to listen on for HTTP/SSE server";
};
openFirewall = lib.mkOption {
default = false;
type = lib.types.bool;
description = "Whether to open the firewall for the specified port.";
};
user = lib.mkOption {
type = lib.types.str;
default = "cratedocs-mcp";
description = "User to run the service as";
};
group = lib.mkOption {
type = lib.types.str;
default = "cratedocs-mcp";
description = "Group to run the service as";
};
};
config = lib.mkIf cfg.enable {
networking.firewall.allowedTCPPorts = lib.mkIf cfg.openFirewall [ cfg.port ];
systemd.services.cratedocs-mcp = {
description = "CrateDocs MCP server";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
ExecStart = "${lib.getExe pkgs.cratedocs-mcp} http -a 0.0.0.0:${toString cfg.port}";
Restart = "always";
User = cfg.user;
Group = cfg.group;
DynamicUser = true;
StateDirectory = "cratedocs-mcp";
CacheDirectory = "cratedocs-mcp";
# Security hardening
PrivateTmp = true;
ProtectSystem = "strict";
ProtectHome = true;
NoNewPrivileges = true;
RestrictNamespaces = true;
RestrictRealtime = true;
RestrictSUIDSGID = true;
RemoveIPC = true;
PrivateMounts = true;
ProtectHostname = true;
ProtectClock = true;
ProtectKernelTunables = true;
ProtectKernelModules = true;
ProtectKernelLogs = true;
ProtectControlGroups = true;
LockPersonality = true;
MemoryDenyWriteExecute = true;
RestrictAddressFamilies = [ "AF_INET" "AF_INET6" ];
SystemCallFilter = "@system-service";
SystemCallErrorNumber = "EPERM";
};
};
};
}