From 090b6cb7e51c30c67cf4a9a9342a49f1db5fabcc Mon Sep 17 00:00:00 2001 From: Shane Pearman Date: Mon, 19 Jan 2026 02:12:55 +0100 Subject: [PATCH] add config path env variable --- shell.nix | 2 +- src/lib.rs | 12 ++++++------ src/main.rs | 9 +++++++-- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/shell.nix b/shell.nix index e375930..e5fbcb5 100644 --- a/shell.nix +++ b/shell.nix @@ -1,7 +1,7 @@ with import {}; let unstable = import - (fetchTarball https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz) {}; + (fetchTarball "https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz") {}; in mkShell { buildInputs = [ diff --git a/src/lib.rs b/src/lib.rs index 704f2b8..6837d2f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -68,6 +68,12 @@ impl Client { } pub async fn run(&self, mut transport: Transport, id: PrivateIdentity) { + // create in destination + let in_destination = transport + .add_destination(id, DestinationName::new("rns_vpn", "client")).await; + let in_destination_hash = in_destination.lock().await.desc.address_hash; + log::info!("created destination: {}", + format!("{}", in_destination_hash).trim_matches('/')); // set up peer map let peer_map = { let mut peer_map = BTreeMap::::new(); @@ -84,12 +90,6 @@ impl Client { } tokio::sync::Mutex::new(peer_map) }; - // create in destination - let in_destination = transport - .add_destination(id, DestinationName::new("rns_vpn", "client")).await; - let in_destination_hash = in_destination.lock().await.desc.address_hash; - log::info!("created destination: {}", - format!("{}", in_destination_hash).trim_matches('/')); // send announces let announce_loop = async || loop { transport.send_announce(&in_destination, None).await; diff --git a/src/main.rs b/src/main.rs index 424eb00..0ac6ee8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,7 +15,7 @@ use x25519_dalek; use rns_vpn; -const CONFIG_PATH: &str = "Config.toml"; +const DEFAULT_CONFIG_PATH: &str = "Config.toml"; /// Command line arguments #[derive(Parser)] @@ -38,7 +38,12 @@ async fn main() -> Result<(), process::ExitCode> { let cmd = Command::parse(); // load config let config: rns_vpn::Config = { - let s = fs::read_to_string(CONFIG_PATH).unwrap(); + let path = if let Ok(path) = std::env::var("RNS_VPN_CONFIG_PATH") { + path + } else { + DEFAULT_CONFIG_PATH.to_string() + }; + let s = fs::read_to_string(path).unwrap(); toml::from_str(&s).unwrap() }; // init logging