From 32013f82c8df64bb2f6dd1a14508c9aad5686df8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 15 Jan 2026 17:59:44 +0000 Subject: [PATCH 1/8] Replace hardcoded DB defaults with values from default.config.toml --- examples/watcher/main.rs | 6 +- nexus-common/src/config/file/mod.rs | 2 +- nexus-common/src/config/file/reader.rs | 3 +- nexus-common/src/config/mod.rs | 23 +++---- nexus-common/src/config/stack.rs | 10 +-- nexus-common/src/db/config.rs | 94 ++++++++++++++++++++++++++ nexus-common/src/db/config/mod.rs | 22 ------ nexus-common/src/db/config/neo4j.rs | 28 -------- 8 files changed, 116 insertions(+), 72 deletions(-) create mode 100644 nexus-common/src/db/config.rs delete mode 100644 nexus-common/src/db/config/mod.rs delete mode 100644 nexus-common/src/db/config/neo4j.rs diff --git a/examples/watcher/main.rs b/examples/watcher/main.rs index 8f7c56272..25f535f67 100644 --- a/examples/watcher/main.rs +++ b/examples/watcher/main.rs @@ -2,8 +2,8 @@ use std::path::PathBuf; use clap::Parser; use nexus_common::{ - db::DatabaseConfig, file::validate_and_expand_path, get_files_dir_pathbuf, types::DynError, - StackConfig, WatcherConfig, LOG_LEVEL, + db::DatabaseConfig, file::validate_and_expand_path, get_default_log_level, + get_files_dir_pathbuf, types::DynError, StackConfig, WatcherConfig, }; use nexus_watcher::{service::NexusWatcher, NexusWatcherBuilder}; use pubky_app_specs::PubkyId; @@ -31,7 +31,7 @@ async fn main() -> Result<(), DynError> { let moderation_id = PubkyId::try_from("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa").unwrap(); let stack = StackConfig { - log_level: LOG_LEVEL, + log_level: get_default_log_level(), files_path: get_files_dir_pathbuf(), otlp_endpoint: None, db: DatabaseConfig::default(), diff --git a/nexus-common/src/config/file/mod.rs b/nexus-common/src/config/file/mod.rs index 8ed2b9743..7158fb239 100644 --- a/nexus-common/src/config/file/mod.rs +++ b/nexus-common/src/config/file/mod.rs @@ -1,5 +1,5 @@ mod loader; -pub(super) mod reader; +pub mod reader; pub use loader::ConfigLoader; pub use reader::{default_config_dir_path, validate_and_expand_path, CONFIG_FILE_NAME}; diff --git a/nexus-common/src/config/file/reader.rs b/nexus-common/src/config/file/reader.rs index 439a56fe8..a494c4565 100644 --- a/nexus-common/src/config/file/reader.rs +++ b/nexus-common/src/config/file/reader.rs @@ -6,7 +6,8 @@ use std::path::{Component, PathBuf}; /// /// See [default_config_dir_path] to use this as [PathBuf] pub const DEFAULT_HOME_DIR: &str = ".pubky-nexus"; -pub(crate) const DEFAULT_CONFIG_TOML: &str = include_str!("../../../default.config.toml"); +/// The default config TOML content embedded in the binary +pub const DEFAULT_CONFIG_TOML: &str = include_str!("../../../default.config.toml"); /// The sole configuration file name recognized by nexus pub const CONFIG_FILE_NAME: &str = "config.toml"; diff --git a/nexus-common/src/config/mod.rs b/nexus-common/src/config/mod.rs index d770687f9..0dc1312df 100644 --- a/nexus-common/src/config/mod.rs +++ b/nexus-common/src/config/mod.rs @@ -1,19 +1,12 @@ use serde::{Deserialize, Serialize}; use std::{fmt::Debug, path::PathBuf, sync::OnceLock}; -pub const LOG_LEVEL: Level = Level::Info; +use crate::db::{default_files_path, default_log_level}; -/// Path to the directory where static files are stored. To access this as a [PathBuf], use [get_files_dir_pathbuf]. -pub const FILES_DIR: &str = "~/.pubky-nexus/static/files"; -static FILES_DIR_PATHBUF: OnceLock = OnceLock::new(); -/// See [FILES_DIR] -pub fn get_files_dir_pathbuf() -> PathBuf { - FILES_DIR_PATHBUF - .get_or_init(|| { - validate_and_expand_path(PathBuf::from(FILES_DIR)) - .expect("Hardcoded FILES_DIR should be a valid directory path") - }) - .clone() +/// Returns the default log level from `default.config.toml`. +/// Provided for backward compatibility. Use `StackConfig::default()` when possible. +pub fn get_default_log_level() -> Level { + default_log_level() } // All the tests run inside their own crate therefore the default directory does not apply @@ -28,6 +21,12 @@ pub fn get_files_dir_test_pathbuf() -> PathBuf { .clone() } +/// Returns the default files directory path from `default.config.toml`. +/// See [default_files_path] for the implementation. +pub fn get_files_dir_pathbuf() -> PathBuf { + default_files_path() +} + mod api; mod daemon; pub mod file; diff --git a/nexus-common/src/config/stack.rs b/nexus-common/src/config/stack.rs index 8fa06ceac..1b5a74850 100644 --- a/nexus-common/src/config/stack.rs +++ b/nexus-common/src/config/stack.rs @@ -1,8 +1,8 @@ -use crate::{db::DatabaseConfig, get_files_dir_pathbuf}; +use crate::db::{default_files_path, default_log_level, default_otlp_endpoint, DatabaseConfig}; use serde::{Deserialize, Deserializer, Serialize}; use std::{fmt::Debug, path::PathBuf}; -use super::{file::validate_and_expand_path, Level, LOG_LEVEL}; +use super::{file::validate_and_expand_path, Level}; fn deserialize_and_expand<'de, D>(deserializer: D) -> Result where @@ -29,9 +29,9 @@ pub fn default_stack() -> StackConfig { impl Default for StackConfig { fn default() -> Self { Self { - log_level: LOG_LEVEL, - files_path: get_files_dir_pathbuf(), - otlp_endpoint: None, + log_level: default_log_level(), + files_path: default_files_path(), + otlp_endpoint: default_otlp_endpoint(), db: DatabaseConfig::default(), } } diff --git a/nexus-common/src/db/config.rs b/nexus-common/src/db/config.rs new file mode 100644 index 000000000..119c48a01 --- /dev/null +++ b/nexus-common/src/db/config.rs @@ -0,0 +1,94 @@ +use serde::{Deserialize, Serialize}; +use std::fmt::Debug; +use std::path::PathBuf; +use std::sync::OnceLock; + +use crate::config::file::reader::DEFAULT_CONFIG_TOML; +use crate::config::file::validate_and_expand_path; +use crate::config::Level; + +/// Intermediate structure to extract stack config defaults from the TOML +#[derive(Deserialize)] +struct DefaultConfigParsed { + stack: StackConfigParsed, +} + +/// Parsed stack config from TOML (before path expansion) +#[derive(Deserialize, Clone)] +pub(crate) struct StackConfigParsed { + log_level: Level, + files_path: PathBuf, + otlp_endpoint: Option, + db: DatabaseConfig, +} + +static DEFAULT_STACK_CONFIG: OnceLock = OnceLock::new(); + +/// Returns the default stack config parsed from `default.config.toml` +pub(crate) fn get_default_stack_config() -> &'static StackConfigParsed { + DEFAULT_STACK_CONFIG.get_or_init(|| { + let config: DefaultConfigParsed = toml::from_str(DEFAULT_CONFIG_TOML).expect( + "embedded default.config.toml should be valid TOML and contain [stack] section", + ); + config.stack + }) +} + +/// Returns the default log level from `default.config.toml` +pub(crate) fn default_log_level() -> Level { + get_default_stack_config().log_level +} + +/// Returns the default files path from `default.config.toml` (with ~ expansion) +pub(crate) fn default_files_path() -> PathBuf { + validate_and_expand_path(get_default_stack_config().files_path.clone()) + .expect("default.config.toml files_path should be a valid directory path") +} + +/// Returns the default OTLP endpoint from `default.config.toml` +pub(crate) fn default_otlp_endpoint() -> Option { + get_default_stack_config().otlp_endpoint.clone() +} + +/// Returns the default Redis URI from `default.config.toml`. +fn default_redis_uri() -> String { + get_default_stack_config().db.redis.clone() +} + +/// Returns the default Neo4j config from `default.config.toml` +fn default_neo4j_config() -> Neo4JConfig { + get_default_stack_config().db.neo4j.clone() +} + +fn default_neo4j_user() -> String { + String::from("neo4j") +} + +#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)] +pub struct Neo4JConfig { + pub uri: String, + #[serde(default = "default_neo4j_user")] + pub user: String, + pub password: String, +} + +impl Default for Neo4JConfig { + fn default() -> Self { + default_neo4j_config() + } +} + +#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)] +pub struct DatabaseConfig { + pub redis: String, + pub neo4j: Neo4JConfig, +} + +impl Default for DatabaseConfig { + fn default() -> Self { + Self { + redis: default_redis_uri(), + neo4j: Neo4JConfig::default(), + } + } +} diff --git a/nexus-common/src/db/config/mod.rs b/nexus-common/src/db/config/mod.rs deleted file mode 100644 index 134725091..000000000 --- a/nexus-common/src/db/config/mod.rs +++ /dev/null @@ -1,22 +0,0 @@ -use serde::{Deserialize, Serialize}; -use std::fmt::Debug; - -mod neo4j; -pub use neo4j::Neo4JConfig; - -pub const REDIS_URI: &str = "redis://localhost:6379"; - -#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)] -pub struct DatabaseConfig { - pub redis: String, - pub neo4j: Neo4JConfig, -} - -impl Default for DatabaseConfig { - fn default() -> Self { - Self { - redis: String::from(REDIS_URI), - neo4j: Neo4JConfig::default(), - } - } -} diff --git a/nexus-common/src/db/config/neo4j.rs b/nexus-common/src/db/config/neo4j.rs deleted file mode 100644 index 1e9ec56cb..000000000 --- a/nexus-common/src/db/config/neo4j.rs +++ /dev/null @@ -1,28 +0,0 @@ -use serde::{Deserialize, Serialize}; - -pub const NEO4J_URI: &str = "bolt://localhost:7687"; -pub const NEO4J_USER: &str = "neo4j"; -pub const NEO4J_PASS: &str = "12345678"; - -// Create temporal struct to wrap database config -#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)] -pub struct Neo4JConfig { - pub uri: String, - #[serde(default = "default_neo4j_user")] - pub user: String, - pub password: String, -} - -fn default_neo4j_user() -> String { - String::from("neo4j") -} - -impl Default for Neo4JConfig { - fn default() -> Self { - Self { - uri: String::from(NEO4J_URI), - user: String::from(NEO4J_USER), - password: String::from(NEO4J_PASS), - } - } -} From 67bf325f41d486425b6cba8c8a2e59cdbc74aaaf Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Tue, 10 Mar 2026 12:46:55 +0100 Subject: [PATCH 2/8] chore: simplify deser, remove StackConfigParsed --- examples/watcher/main.rs | 12 +--- nexus-common/src/config/api.rs | 4 +- nexus-common/src/config/mod.rs | 18 +---- nexus-common/src/config/stack.rs | 28 ++++---- nexus-common/src/config/watcher.rs | 4 +- nexus-common/src/db/config.rs | 66 +------------------ .../tests/event_processor/utils/watcher.rs | 4 +- 7 files changed, 30 insertions(+), 106 deletions(-) diff --git a/examples/watcher/main.rs b/examples/watcher/main.rs index 25f535f67..ea9bcdfde 100644 --- a/examples/watcher/main.rs +++ b/examples/watcher/main.rs @@ -1,10 +1,7 @@ use std::path::PathBuf; use clap::Parser; -use nexus_common::{ - db::DatabaseConfig, file::validate_and_expand_path, get_default_log_level, - get_files_dir_pathbuf, types::DynError, StackConfig, WatcherConfig, -}; +use nexus_common::{file::validate_and_expand_path, types::DynError, StackConfig, WatcherConfig}; use nexus_watcher::{service::NexusWatcher, NexusWatcherBuilder}; use pubky_app_specs::PubkyId; @@ -30,12 +27,7 @@ async fn main() -> Result<(), DynError> { PubkyId::try_from("8um71us3fyw6h8wbcxb5ar3rwusy1a6u49956ikzojg3gcwd1dty").unwrap(); let moderation_id = PubkyId::try_from("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa").unwrap(); - let stack = StackConfig { - log_level: get_default_log_level(), - files_path: get_files_dir_pathbuf(), - otlp_endpoint: None, - db: DatabaseConfig::default(), - }; + let stack = StackConfig::default(); let config = WatcherConfig { name: String::from("nexusd.watcher"), testnet: false, diff --git a/nexus-common/src/config/api.rs b/nexus-common/src/config/api.rs index b9ec34f63..78a47cee5 100644 --- a/nexus-common/src/config/api.rs +++ b/nexus-common/src/config/api.rs @@ -2,7 +2,7 @@ use std::net::{IpAddr, Ipv4Addr}; use std::{fmt::Debug, net::SocketAddr}; use super::file::ConfigLoader; -use super::{default_stack, DaemonConfig, StackConfig}; +use super::{DaemonConfig, StackConfig}; use async_trait::async_trait; use serde::{Deserialize, Serialize}; @@ -20,7 +20,7 @@ pub struct ApiConfig { pub public_ip: IpAddr, pub public_addr: SocketAddr, pub pubky_listen_socket: SocketAddr, - #[serde(default = "default_stack")] + #[serde(default)] pub stack: StackConfig, } diff --git a/nexus-common/src/config/mod.rs b/nexus-common/src/config/mod.rs index 0dc1312df..f770a929d 100644 --- a/nexus-common/src/config/mod.rs +++ b/nexus-common/src/config/mod.rs @@ -1,14 +1,6 @@ use serde::{Deserialize, Serialize}; use std::{fmt::Debug, path::PathBuf, sync::OnceLock}; -use crate::db::{default_files_path, default_log_level}; - -/// Returns the default log level from `default.config.toml`. -/// Provided for backward compatibility. Use `StackConfig::default()` when possible. -pub fn get_default_log_level() -> Level { - default_log_level() -} - // All the tests run inside their own crate therefore the default directory does not apply pub const FILES_DIR_TEST: &str = "./static/files"; static FILES_DIR_TEST_PATHBUF: OnceLock = OnceLock::new(); @@ -21,21 +13,15 @@ pub fn get_files_dir_test_pathbuf() -> PathBuf { .clone() } -/// Returns the default files directory path from `default.config.toml`. -/// See [default_files_path] for the implementation. -pub fn get_files_dir_pathbuf() -> PathBuf { - default_files_path() -} - mod api; mod daemon; pub mod file; -mod stack; +pub(crate) mod stack; mod watcher; pub use api::ApiConfig; pub use daemon::DaemonConfig; -pub use stack::{default_stack, StackConfig}; +pub use stack::StackConfig; pub use watcher::WatcherConfig; use crate::file::validate_and_expand_path; diff --git a/nexus-common/src/config/stack.rs b/nexus-common/src/config/stack.rs index 1b5a74850..56d0ab1ba 100644 --- a/nexus-common/src/config/stack.rs +++ b/nexus-common/src/config/stack.rs @@ -1,9 +1,16 @@ -use crate::db::{default_files_path, default_log_level, default_otlp_endpoint, DatabaseConfig}; +use crate::{db::DatabaseConfig, file::reader::DEFAULT_CONFIG_TOML}; use serde::{Deserialize, Deserializer, Serialize}; -use std::{fmt::Debug, path::PathBuf}; +use std::{fmt::Debug, path::PathBuf, sync::OnceLock}; use super::{file::validate_and_expand_path, Level}; +static DEFAULT_STACK_CONFIG: OnceLock = OnceLock::new(); + +#[derive(Deserialize)] +struct DefaultConfig { + stack: StackConfig, +} + fn deserialize_and_expand<'de, D>(deserializer: D) -> Result where D: Deserializer<'de>, @@ -21,18 +28,17 @@ pub struct StackConfig { pub db: DatabaseConfig, } -/// Utility function -pub fn default_stack() -> StackConfig { - StackConfig::default() +/// Returns the default stack config parsed from `default.config.toml` +pub(crate) fn get_default_stack_config() -> &'static StackConfig { + DEFAULT_STACK_CONFIG.get_or_init(|| { + let config: DefaultConfig = toml::from_str(DEFAULT_CONFIG_TOML) + .expect("embedded default.config.toml should be valid TOML"); + config.stack + }) } impl Default for StackConfig { fn default() -> Self { - Self { - log_level: default_log_level(), - files_path: default_files_path(), - otlp_endpoint: default_otlp_endpoint(), - db: DatabaseConfig::default(), - } + get_default_stack_config().clone() } } diff --git a/nexus-common/src/config/watcher.rs b/nexus-common/src/config/watcher.rs index aed0329c0..6e0a1cef0 100644 --- a/nexus-common/src/config/watcher.rs +++ b/nexus-common/src/config/watcher.rs @@ -1,5 +1,5 @@ use super::file::ConfigLoader; -use super::{default_stack, DaemonConfig, StackConfig}; +use super::{DaemonConfig, StackConfig}; use async_trait::async_trait; use pubky_app_specs::PubkyId; use serde::{Deserialize, Serialize}; @@ -43,7 +43,7 @@ pub struct WatcherConfig { pub monitored_homeservers_limit: usize, /// Sleep between every full run (over all monitored homeservers), in milliseconds pub watcher_sleep: u64, - #[serde(default = "default_stack")] + #[serde(default)] pub stack: StackConfig, // Moderation pub moderation_id: PubkyId, diff --git a/nexus-common/src/db/config.rs b/nexus-common/src/db/config.rs index 119c48a01..ee636d855 100644 --- a/nexus-common/src/db/config.rs +++ b/nexus-common/src/db/config.rs @@ -1,64 +1,7 @@ use serde::{Deserialize, Serialize}; use std::fmt::Debug; -use std::path::PathBuf; -use std::sync::OnceLock; -use crate::config::file::reader::DEFAULT_CONFIG_TOML; -use crate::config::file::validate_and_expand_path; -use crate::config::Level; - -/// Intermediate structure to extract stack config defaults from the TOML -#[derive(Deserialize)] -struct DefaultConfigParsed { - stack: StackConfigParsed, -} - -/// Parsed stack config from TOML (before path expansion) -#[derive(Deserialize, Clone)] -pub(crate) struct StackConfigParsed { - log_level: Level, - files_path: PathBuf, - otlp_endpoint: Option, - db: DatabaseConfig, -} - -static DEFAULT_STACK_CONFIG: OnceLock = OnceLock::new(); - -/// Returns the default stack config parsed from `default.config.toml` -pub(crate) fn get_default_stack_config() -> &'static StackConfigParsed { - DEFAULT_STACK_CONFIG.get_or_init(|| { - let config: DefaultConfigParsed = toml::from_str(DEFAULT_CONFIG_TOML).expect( - "embedded default.config.toml should be valid TOML and contain [stack] section", - ); - config.stack - }) -} - -/// Returns the default log level from `default.config.toml` -pub(crate) fn default_log_level() -> Level { - get_default_stack_config().log_level -} - -/// Returns the default files path from `default.config.toml` (with ~ expansion) -pub(crate) fn default_files_path() -> PathBuf { - validate_and_expand_path(get_default_stack_config().files_path.clone()) - .expect("default.config.toml files_path should be a valid directory path") -} - -/// Returns the default OTLP endpoint from `default.config.toml` -pub(crate) fn default_otlp_endpoint() -> Option { - get_default_stack_config().otlp_endpoint.clone() -} - -/// Returns the default Redis URI from `default.config.toml`. -fn default_redis_uri() -> String { - get_default_stack_config().db.redis.clone() -} - -/// Returns the default Neo4j config from `default.config.toml` -fn default_neo4j_config() -> Neo4JConfig { - get_default_stack_config().db.neo4j.clone() -} +use crate::StackConfig; fn default_neo4j_user() -> String { String::from("neo4j") @@ -74,7 +17,7 @@ pub struct Neo4JConfig { impl Default for Neo4JConfig { fn default() -> Self { - default_neo4j_config() + DatabaseConfig::default().neo4j.clone() } } @@ -86,9 +29,6 @@ pub struct DatabaseConfig { impl Default for DatabaseConfig { fn default() -> Self { - Self { - redis: default_redis_uri(), - neo4j: Neo4JConfig::default(), - } + StackConfig::default().db.clone() } } diff --git a/nexus-watcher/tests/event_processor/utils/watcher.rs b/nexus-watcher/tests/event_processor/utils/watcher.rs index c1f5e5cd4..8b4bda3df 100644 --- a/nexus-watcher/tests/event_processor/utils/watcher.rs +++ b/nexus-watcher/tests/event_processor/utils/watcher.rs @@ -2,13 +2,13 @@ use anyhow::{anyhow, Error, Result}; use base32::{encode, Alphabet}; use chrono::Utc; use nexus_common::db::PubkyConnector; -use nexus_common::get_files_dir_pathbuf; use nexus_common::get_files_dir_test_pathbuf; use nexus_common::models::event::Event; use nexus_common::models::event::EventProcessorError; use nexus_common::models::file::FileDetails; use nexus_common::models::homeserver::Homeserver; use nexus_common::models::traits::Collection; +use nexus_common::StackConfig; use nexus_watcher::events::retry::event::RetryEvent; use nexus_watcher::events::{handle, Moderation}; use nexus_watcher::service::EventProcessorRunner; @@ -348,7 +348,7 @@ pub async fn retrieve_and_handle_event_line( event_line: &str, moderation: Arc, ) -> Result<(), EventProcessorError> { - match Event::parse_event(event_line, get_files_dir_pathbuf())? { + match Event::parse_event(event_line, StackConfig::default().files_path)? { Some(event) => handle(&event, moderation).await, None => Ok(()), } From 9ea01d38af80ec54a8d91e495154f0a39b4b7496 Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Tue, 10 Mar 2026 12:53:55 +0100 Subject: [PATCH 3/8] chore: remove unnecessary clone() --- nexus-common/src/db/config.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nexus-common/src/db/config.rs b/nexus-common/src/db/config.rs index ee636d855..f928c4401 100644 --- a/nexus-common/src/db/config.rs +++ b/nexus-common/src/db/config.rs @@ -17,7 +17,7 @@ pub struct Neo4JConfig { impl Default for Neo4JConfig { fn default() -> Self { - DatabaseConfig::default().neo4j.clone() + DatabaseConfig::default().neo4j } } @@ -29,6 +29,6 @@ pub struct DatabaseConfig { impl Default for DatabaseConfig { fn default() -> Self { - StackConfig::default().db.clone() + StackConfig::default().db } } From 3c470ce112aadcf4f6e959bfacac9ee8e5d1c5d0 Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Tue, 10 Mar 2026 12:55:40 +0100 Subject: [PATCH 4/8] chore: keep reader, DEFAULT_CONFIG_TOML as pub(crate) --- nexus-common/src/config/file/mod.rs | 2 +- nexus-common/src/config/file/reader.rs | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/nexus-common/src/config/file/mod.rs b/nexus-common/src/config/file/mod.rs index 7158fb239..e64780f46 100644 --- a/nexus-common/src/config/file/mod.rs +++ b/nexus-common/src/config/file/mod.rs @@ -1,5 +1,5 @@ mod loader; -pub mod reader; +pub(crate) mod reader; pub use loader::ConfigLoader; pub use reader::{default_config_dir_path, validate_and_expand_path, CONFIG_FILE_NAME}; diff --git a/nexus-common/src/config/file/reader.rs b/nexus-common/src/config/file/reader.rs index a494c4565..d68012fce 100644 --- a/nexus-common/src/config/file/reader.rs +++ b/nexus-common/src/config/file/reader.rs @@ -6,8 +6,10 @@ use std::path::{Component, PathBuf}; /// /// See [default_config_dir_path] to use this as [PathBuf] pub const DEFAULT_HOME_DIR: &str = ".pubky-nexus"; + /// The default config TOML content embedded in the binary -pub const DEFAULT_CONFIG_TOML: &str = include_str!("../../../default.config.toml"); +pub(crate) const DEFAULT_CONFIG_TOML: &str = include_str!("../../../default.config.toml"); + /// The sole configuration file name recognized by nexus pub const CONFIG_FILE_NAME: &str = "config.toml"; From 8d3987b1acc8642d5c0ae5321946b7e898354066 Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Tue, 10 Mar 2026 12:56:27 +0100 Subject: [PATCH 5/8] chore: reduce visibility of stack module --- nexus-common/src/config/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nexus-common/src/config/mod.rs b/nexus-common/src/config/mod.rs index f770a929d..b02209d70 100644 --- a/nexus-common/src/config/mod.rs +++ b/nexus-common/src/config/mod.rs @@ -16,7 +16,7 @@ pub fn get_files_dir_test_pathbuf() -> PathBuf { mod api; mod daemon; pub mod file; -pub(crate) mod stack; +mod stack; mod watcher; pub use api::ApiConfig; From 6027b80b0726d3f0b862e0ab635dc777fe4e40e9 Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Tue, 10 Mar 2026 13:01:20 +0100 Subject: [PATCH 6/8] fix: use correct files_path for tests --- nexus-watcher/tests/event_processor/utils/watcher.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/nexus-watcher/tests/event_processor/utils/watcher.rs b/nexus-watcher/tests/event_processor/utils/watcher.rs index 8b4bda3df..8e62b15c1 100644 --- a/nexus-watcher/tests/event_processor/utils/watcher.rs +++ b/nexus-watcher/tests/event_processor/utils/watcher.rs @@ -8,7 +8,6 @@ use nexus_common::models::event::EventProcessorError; use nexus_common::models::file::FileDetails; use nexus_common::models::homeserver::Homeserver; use nexus_common::models::traits::Collection; -use nexus_common::StackConfig; use nexus_watcher::events::retry::event::RetryEvent; use nexus_watcher::events::{handle, Moderation}; use nexus_watcher::service::EventProcessorRunner; @@ -348,7 +347,7 @@ pub async fn retrieve_and_handle_event_line( event_line: &str, moderation: Arc, ) -> Result<(), EventProcessorError> { - match Event::parse_event(event_line, StackConfig::default().files_path)? { + match Event::parse_event(event_line, get_files_dir_test_pathbuf())? { Some(event) => handle(&event, moderation).await, None => Ok(()), } From bfe5e018622ecdd4d06585ab63b6af25da5534a1 Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Tue, 10 Mar 2026 13:10:30 +0100 Subject: [PATCH 7/8] doc: add rustdocs --- nexus-common/src/config/stack.rs | 5 +++++ nexus-common/src/db/config.rs | 2 ++ 2 files changed, 7 insertions(+) diff --git a/nexus-common/src/config/stack.rs b/nexus-common/src/config/stack.rs index 56d0ab1ba..3fdd2bcbd 100644 --- a/nexus-common/src/config/stack.rs +++ b/nexus-common/src/config/stack.rs @@ -6,6 +6,10 @@ use super::{file::validate_and_expand_path, Level}; static DEFAULT_STACK_CONFIG: OnceLock = OnceLock::new(); +/// Intermediary struct used in deserializing [StackConfig] from `default.config.toml` +/// +/// This is done because we don't know the full structure of the config.toml , but we +/// do know it contains a `[stack]` section with [StackConfig]. #[derive(Deserialize)] struct DefaultConfig { stack: StackConfig, @@ -38,6 +42,7 @@ pub(crate) fn get_default_stack_config() -> &'static StackConfig { } impl Default for StackConfig { + /// Extracted from `default.config.toml` fn default() -> Self { get_default_stack_config().clone() } diff --git a/nexus-common/src/db/config.rs b/nexus-common/src/db/config.rs index f928c4401..43ecbb3f8 100644 --- a/nexus-common/src/db/config.rs +++ b/nexus-common/src/db/config.rs @@ -16,6 +16,7 @@ pub struct Neo4JConfig { } impl Default for Neo4JConfig { + /// Extracted from `default.config.toml` via [StackConfig] > [DatabaseConfig] > [Neo4JConfig] fn default() -> Self { DatabaseConfig::default().neo4j } @@ -28,6 +29,7 @@ pub struct DatabaseConfig { } impl Default for DatabaseConfig { + /// Extracted from `default.config.toml` via [StackConfig] > [DatabaseConfig] fn default() -> Self { StackConfig::default().db } From fdcbd75911160323cbf6becd5e176d53aabe1350 Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Wed, 11 Mar 2026 11:02:53 +0100 Subject: [PATCH 8/8] chore: group Neo4jConfig defaults --- nexus-common/src/db/config.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/nexus-common/src/db/config.rs b/nexus-common/src/db/config.rs index c674400fd..85966c1f2 100644 --- a/nexus-common/src/db/config.rs +++ b/nexus-common/src/db/config.rs @@ -3,10 +3,21 @@ use std::fmt::Debug; use crate::StackConfig; +// TODO Does this need to be pub? Isn't this only relevant for default deser where JSOn field isn't set? +pub const DEFAULT_SLOW_QUERY_THRESHOLD_MS: u64 = 100; + fn default_neo4j_user() -> String { String::from("neo4j") } +fn default_slow_query_logging_threshold_ms() -> u64 { + DEFAULT_SLOW_QUERY_THRESHOLD_MS +} + +fn default_slow_query_logging_enabled() -> bool { + true +} + #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)] pub struct Neo4JConfig { pub uri: String, @@ -51,13 +62,3 @@ impl Default for DatabaseConfig { StackConfig::default().db } } - -pub const DEFAULT_SLOW_QUERY_THRESHOLD_MS: u64 = 100; - -fn default_slow_query_logging_threshold_ms() -> u64 { - DEFAULT_SLOW_QUERY_THRESHOLD_MS -} - -fn default_slow_query_logging_enabled() -> bool { - true -}