[Add] port options in nix flake

This commit is contained in:
Alois 2026-05-16 17:49:25 +02:00
commit 6cc29a137e
3 changed files with 48 additions and 4 deletions

View file

@ -88,6 +88,24 @@
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 {
type = lib.types.package;
default = defaultPackage;
@ -118,6 +136,12 @@
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
environment = {
RHO_PORT = toString cfg.rhoPort;
OMEGA_HOST = cfg.omegaHost;
OMEGA_PORT = toString cfg.omegaPort;
};
serviceConfig = {
Type = "simple";
User = "omikron";
@ -164,8 +188,8 @@
};
networking.firewall = lib.mkIf cfg.openFirewall {
allowedTCPPorts = [ 959 ];
allowedUDPPorts = [ 959 ];
allowedTCPPorts = [ cfg.rhoPort ];
allowedUDPPorts = [ cfg.rhoPort ];
};
};
};

View file

@ -39,9 +39,14 @@ async fn main() {
dotenv().ok();
startup();
let rho_port = env::var("RHO_PORT")
.ok()
.and_then(|s| s.parse().ok())
.unwrap_or(959);
get_omega_connection();
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);
}
});

View file

@ -26,6 +26,20 @@ use uuid::Uuid;
const OMEGA_HOST_DEFAULT: &str = "tensamin.net";
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 MAX_RECONNECT_DELAY: Duration = Duration::from_secs(300);
const CONNECTION_TIMEOUT: Duration = Duration::from_secs(10);
@ -104,7 +118,8 @@ pub struct OmegaConnection {
impl OmegaConnection {
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 {