diff --git a/flake.nix b/flake.nix index 9c34223..55f73e0 100644 --- a/flake.nix +++ b/flake.nix @@ -87,6 +87,18 @@ ''; }; + apiPort = lib.mkOption { + type = lib.types.port; + default = 9188; + description = "Port for the web/API server."; + }; + + transportPort = lib.mkOption { + type = lib.types.port; + default = 9187; + description = "Port for the TTP/QUIC transport server."; + }; + openFirewall = lib.mkOption { type = lib.types.bool; default = true; @@ -125,6 +137,11 @@ Restart = "always"; RestartSec = "5s"; + Environment = [ + "API_PORT=${toString cfg.apiPort}" + "OMIKRON_PORT=${toString cfg.transportPort}" + ]; + EnvironmentFile = cfg.environmentFiles; AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" ]; @@ -161,8 +178,8 @@ }; networking.firewall = lib.mkIf cfg.openFirewall { - allowedTCPPorts = [ 9187 9188 ]; - allowedUDPPorts = [ 9187 9188 ]; + allowedTCPPorts = [ cfg.transportPort cfg.apiPort ]; + allowedUDPPorts = [ cfg.transportPort cfg.apiPort ]; }; }; }; diff --git a/src/main.rs b/src/main.rs index 8143c9f..7d5cfcc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,8 +35,13 @@ async fn main() { log_in!("Incoming messages"); log_out!("Outgoing messages"); + let omikron_port: u16 = env::var("OMIKRON_PORT") + .ok() + .and_then(|s| s.parse().ok()) + .unwrap_or(9187); + tokio::spawn(async move { - match omikron_connection::start(9187).await { + match omikron_connection::start(omikron_port).await { Err(e) => log_err!(0, PrintType::General, "{:?}", e), _ => {} } @@ -59,7 +64,12 @@ async fn main() { log!(" Users"); } - let _ = server::server::start(9188).await; + let api_port: u16 = env::var("API_PORT") + .ok() + .and_then(|s| s.parse().ok()) + .unwrap_or(9188); + + let _ = server::server::start(api_port).await; tokio::signal::ctrl_c().await.unwrap(); }