|
| 1 | +{ |
| 2 | + config, |
| 3 | + lib, |
| 4 | + pkgs, |
| 5 | + ... |
| 6 | +}: |
| 7 | +let |
| 8 | + inherit (lib) |
| 9 | + getExe |
| 10 | + mkEnableOption |
| 11 | + mkIf |
| 12 | + mkOption |
| 13 | + mkPackageOption |
| 14 | + types |
| 15 | + ; |
| 16 | + |
| 17 | + cfg = config.services.mcp-outline; |
| 18 | + |
| 19 | + settingsFormat = pkgs.formats.keyValue { }; |
| 20 | + generatedEnvironmentFile = settingsFormat.generate "mcp-outline-env" cfg.settings; |
| 21 | +in |
| 22 | +{ |
| 23 | + options.services.mcp-outline = { |
| 24 | + enable = mkEnableOption "mcp-outline service"; |
| 25 | + |
| 26 | + package = mkPackageOption pkgs "mcp-outline" { }; |
| 27 | + |
| 28 | + environmentFile = mkOption { |
| 29 | + type = types.path; |
| 30 | + default = "/dev/null"; |
| 31 | + example = "/run/secrets/mcp-outline.env"; |
| 32 | + description = '' |
| 33 | + Path to an environment file loaded by the service. |
| 34 | +
|
| 35 | + Use this for secrets like `OUTLINE_API_KEY` so they stay out of the Nix store. |
| 36 | + ''; |
| 37 | + }; |
| 38 | + |
| 39 | + settings = mkOption { |
| 40 | + type = settingsFormat.type; |
| 41 | + default = { |
| 42 | + MCP_TRANSPORT = "streamable-http"; |
| 43 | + MCP_HOST = "127.0.0.1"; |
| 44 | + MCP_PORT = 3000; |
| 45 | + }; |
| 46 | + example = { |
| 47 | + MCP_TRANSPORT = "streamable-http"; |
| 48 | + MCP_HOST = "0.0.0.0"; |
| 49 | + MCP_PORT = 3000; |
| 50 | + OUTLINE_URL = "https://outline.example.com"; |
| 51 | + }; |
| 52 | + description = '' |
| 53 | + Environment variables written to a generated environment file for mcp-outline. |
| 54 | +
|
| 55 | + Common values are `MCP_TRANSPORT`, `MCP_HOST`, `MCP_PORT`, and `OUTLINE_URL`. |
| 56 | + Put secrets such as `OUTLINE_API_KEY` in `services.mcp-outline.environmentFile` instead. |
| 57 | +
|
| 58 | + Also see: https://github.com/Vortiago/mcp-outline/blob/main/docs/configuration.md |
| 59 | + ''; |
| 60 | + }; |
| 61 | + |
| 62 | + openFirewall = mkOption { |
| 63 | + type = types.bool; |
| 64 | + default = false; |
| 65 | + description = "Whether to open the configured MCP port in the firewall."; |
| 66 | + }; |
| 67 | + }; |
| 68 | + |
| 69 | + config = mkIf cfg.enable { |
| 70 | + assertions = [ |
| 71 | + { |
| 72 | + assertion = cfg.settings.MCP_TRANSPORT != "stdio"; |
| 73 | + message = "services.mcp-outline.settings.MCP_TRANSPORT must be \"sse\" or \"streamable-http\" when running mcp-outline as a NixOS service."; |
| 74 | + } |
| 75 | + ]; |
| 76 | + |
| 77 | + systemd.services.mcp-outline = { |
| 78 | + description = "mcp-outline service"; |
| 79 | + after = [ "network.target" ]; |
| 80 | + wantedBy = [ "multi-user.target" ]; |
| 81 | + restartTriggers = [ |
| 82 | + cfg.package |
| 83 | + cfg.environmentFile |
| 84 | + generatedEnvironmentFile |
| 85 | + ]; |
| 86 | + |
| 87 | + serviceConfig = { |
| 88 | + Type = "simple"; |
| 89 | + DynamicUser = true; |
| 90 | + ExecStart = getExe cfg.package; |
| 91 | + Restart = "on-failure"; |
| 92 | + EnvironmentFile = [ |
| 93 | + cfg.environmentFile |
| 94 | + generatedEnvironmentFile |
| 95 | + ]; |
| 96 | + |
| 97 | + StateDirectory = "mcp-outline"; |
| 98 | + NoNewPrivileges = true; |
| 99 | + PrivateTmp = true; |
| 100 | + ProtectSystem = "strict"; |
| 101 | + ProtectHome = true; |
| 102 | + ProtectControlGroups = true; |
| 103 | + ProtectKernelModules = true; |
| 104 | + ProtectKernelTunables = true; |
| 105 | + RestrictSUIDSGID = true; |
| 106 | + LockPersonality = true; |
| 107 | + MemoryDenyWriteExecute = true; |
| 108 | + SystemCallArchitectures = "native"; |
| 109 | + }; |
| 110 | + }; |
| 111 | + |
| 112 | + networking.firewall.allowedTCPPorts = lib.optional cfg.openFirewall cfg.settings.MCP_PORT; |
| 113 | + }; |
| 114 | +} |
0 commit comments