[Add] port options in nix flake
This commit is contained in:
parent
505acd4b23
commit
6cc29a137e
3 changed files with 48 additions and 4 deletions
28
flake.nix
28
flake.nix
|
|
@ -88,6 +88,24 @@
|
||||||
description = "Whether to open the firewall for ports used by the Omikron.";
|
description = "Whether to open the firewall for ports used by the Omikron.";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
rhoPort = lib.mkOption {
|
||||||
|
type = lib.types.port;
|
||||||
|
default = 959;
|
||||||
|
description = "Port the Omikron server listens on for incoming QUIC connections.";
|
||||||
|
};
|
||||||
|
|
||||||
|
omegaHost = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
default = "tensamin.net";
|
||||||
|
description = "Hostname of the upstream Omega server.";
|
||||||
|
};
|
||||||
|
|
||||||
|
omegaPort = lib.mkOption {
|
||||||
|
type = lib.types.port;
|
||||||
|
default = 9187;
|
||||||
|
description = "Port of the upstream Omega server.";
|
||||||
|
};
|
||||||
|
|
||||||
package = lib.mkOption {
|
package = lib.mkOption {
|
||||||
type = lib.types.package;
|
type = lib.types.package;
|
||||||
default = defaultPackage;
|
default = defaultPackage;
|
||||||
|
|
@ -118,6 +136,12 @@
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
after = [ "network.target" ];
|
after = [ "network.target" ];
|
||||||
|
|
||||||
|
environment = {
|
||||||
|
RHO_PORT = toString cfg.rhoPort;
|
||||||
|
OMEGA_HOST = cfg.omegaHost;
|
||||||
|
OMEGA_PORT = toString cfg.omegaPort;
|
||||||
|
};
|
||||||
|
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
Type = "simple";
|
Type = "simple";
|
||||||
User = "omikron";
|
User = "omikron";
|
||||||
|
|
@ -164,8 +188,8 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
networking.firewall = lib.mkIf cfg.openFirewall {
|
networking.firewall = lib.mkIf cfg.openFirewall {
|
||||||
allowedTCPPorts = [ 959 ];
|
allowedTCPPorts = [ cfg.rhoPort ];
|
||||||
allowedUDPPorts = [ 959 ];
|
allowedUDPPorts = [ cfg.rhoPort ];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -39,9 +39,14 @@ async fn main() {
|
||||||
dotenv().ok();
|
dotenv().ok();
|
||||||
startup();
|
startup();
|
||||||
|
|
||||||
|
let rho_port = env::var("RHO_PORT")
|
||||||
|
.ok()
|
||||||
|
.and_then(|s| s.parse().ok())
|
||||||
|
.unwrap_or(959);
|
||||||
|
|
||||||
get_omega_connection();
|
get_omega_connection();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
if let Err(e) = start(959).await {
|
if let Err(e) = start(rho_port).await {
|
||||||
log_err!(0, util::logger::PrintType::General, "{}", e);
|
log_err!(0, util::logger::PrintType::General, "{}", e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,20 @@ use uuid::Uuid;
|
||||||
|
|
||||||
const OMEGA_HOST_DEFAULT: &str = "tensamin.net";
|
const OMEGA_HOST_DEFAULT: &str = "tensamin.net";
|
||||||
const OMEGA_PORT_DEFAULT: u16 = 9187;
|
const OMEGA_PORT_DEFAULT: u16 = 9187;
|
||||||
|
|
||||||
|
fn omega_host_and_port() -> (String, u16) {
|
||||||
|
let host = env::var("OMEGA_HOST")
|
||||||
|
.map(|s| s.trim().to_string())
|
||||||
|
.unwrap_or_else(|_| OMEGA_HOST_DEFAULT.to_string());
|
||||||
|
|
||||||
|
let port = env::var("OMEGA_PORT")
|
||||||
|
.ok()
|
||||||
|
.and_then(|s| s.trim().parse().ok())
|
||||||
|
.unwrap_or(OMEGA_PORT_DEFAULT);
|
||||||
|
|
||||||
|
(host, port)
|
||||||
|
}
|
||||||
|
|
||||||
const RECONNECT_DELAY: Duration = Duration::from_secs(5);
|
const RECONNECT_DELAY: Duration = Duration::from_secs(5);
|
||||||
const MAX_RECONNECT_DELAY: Duration = Duration::from_secs(300);
|
const MAX_RECONNECT_DELAY: Duration = Duration::from_secs(300);
|
||||||
const CONNECTION_TIMEOUT: Duration = Duration::from_secs(10);
|
const CONNECTION_TIMEOUT: Duration = Duration::from_secs(10);
|
||||||
|
|
@ -104,7 +118,8 @@ pub struct OmegaConnection {
|
||||||
|
|
||||||
impl OmegaConnection {
|
impl OmegaConnection {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self::with_host(OMEGA_HOST_DEFAULT, OMEGA_PORT_DEFAULT)
|
let (host, port) = omega_host_and_port();
|
||||||
|
Self::with_host(&host, port)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_host(host: &str, port: u16) -> Self {
|
pub fn with_host(host: &str, port: u16) -> Self {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue