[Add] port options in nix flake
This commit is contained in:
parent
fe0250218d
commit
fa7c060624
2 changed files with 31 additions and 4 deletions
21
flake.nix
21
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 ];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
|
|||
14
src/main.rs
14
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();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue