From b1184d16ee7c9bfafcc9cb44f7206938debae697 Mon Sep 17 00:00:00 2001 From: rzuasti Date: Tue, 27 Jan 2026 13:13:02 -0500 Subject: [PATCH] Added all configuration parameters to nix flake --- nix/modules/oott-service.nix | 43 ++++++++++++++++++++++++++++++-- sample_oott.toml | 3 +++ src/db.rs | 48 ++++++++++++++++++++++-------------- src/settings.rs | 6 +++++ 4 files changed, 80 insertions(+), 20 deletions(-) diff --git a/nix/modules/oott-service.nix b/nix/modules/oott-service.nix index 39f8fb4..7069b7f 100644 --- a/nix/modules/oott-service.nix +++ b/nix/modules/oott-service.nix @@ -16,6 +16,11 @@ in { Whether to run the oott service ''; }; + database.path = mkOption { + type = types.path; + description = "Full path to store the database at"; + default = "/var/lib/oott.db"; + }; networking.interface = mkOption { type = types.str; description = "Network interface to use for scans"; @@ -26,6 +31,41 @@ in { description = "Log level for the oott service"; default = "info"; }; + timings.wait_between_scans = mkOption { + type = types.str; + description = "Wait time between scans. This does not include the scan time."; + default = "15m"; + }; + timings.arp_sender_timeout = mkOption { + type = types.str; + description = "If the ARP sender process takes longer than this it will be stopped (for a class C network - 254 IPs - it should take less than a minute)."; + default = "1m"; + }; + timings.arp_scan_duration = mkOption { + type = types.str; + description = "How long to wait for response packets on each scan (5m to 10m is a good timeframe for a class B or C network)."; + default = "10m"; + }; + notifications.method = mkOption { + type = types.str; + description = "For now just pushover, you can set this to none to avoid sending notifications (it will just log)."; + default = "pushover"; + }; + notifications.notify_when_not_seen_for = mkOption { + type = types.str; + description = "Send a notification if a device comes back online after not being seen for this timeframe."; + default = "1w"; + }; + notifications.pushover.token = mkOption { + type = types.str; + description = "Your pushover token goes here, just copy&paste from their website after creating the app."; + default = ""; + }; + notifications.pushover.user_key = mkOption { + type = types.str; + description = "User key goes here, this is the account wide code for pushover."; + default = ""; + }; }; # Service implementation @@ -36,11 +76,10 @@ in { wantedBy = ["multi-user.target"]; serviceConfig = { - ExecStart = "${pkgs.oott}/bin/oott ${ + ExecStart = "${pkgs.oott}/bin/oott --config ${ builtins.toFile "oott.json" (generators.toJSON {} cfg) }"; - # ExecStart = "${pkgs.oott}/bin/oott"; ProtectHome = "read-only"; Restart = "on-failure"; Type = "exec"; diff --git a/sample_oott.toml b/sample_oott.toml index 366bd34..c6bdf2b 100644 --- a/sample_oott.toml +++ b/sample_oott.toml @@ -1,3 +1,6 @@ +[database] +path = "./oott.db" # Database path. Make sure it's writeable for the user running this process + [networking] interface = "eno1" # Network interface to use for scans diff --git a/src/db.rs b/src/db.rs index a876b73..943fef2 100644 --- a/src/db.rs +++ b/src/db.rs @@ -7,6 +7,8 @@ use rusqlite_migration::Migrations; use std::result::Result; use std::sync::LazyLock; +use crate::settings; + static MIGRATIONS_DIR: Dir = include_dir!("$CARGO_MANIFEST_DIR/database_migrations"); // Define migrations. These are applied atomically. @@ -14,25 +16,35 @@ static MIGRATIONS: LazyLock> = LazyLock::new(|| Migrations::from_directory(&MIGRATIONS_DIR).unwrap()); pub fn init_db() -> Result { - debug!("Opening database."); - let mut conn = match Connection::open("./oott.db") { - Ok(value) => value, - Err(error) => { - error!("Error opening database (oott.db): {error}"); - return Err(format!("Error opening database (oott.db): {error}")); - } - }; + if settings::CONFIG.database.path.is_empty() { + error!("Database path not set. Make sure to define database.path in your config file."); + Err(format!( + "Database path not set. Make sure to define database.path in your config file." + )) + } else { + debug!("Opening database at {}.", settings::CONFIG.database.path); - debug!("Database open, executing migrations if needed."); - // Update the database schema, atomically - match MIGRATIONS.to_latest(&mut conn) { - Ok(_) => { - debug!("Database up to date."); - Ok(conn) - } - Err(error) => { - error!("Error updating database: {error}"); - Err(format!("Error updating database: {error}")) + let database_path = settings::CONFIG.database.path.clone(); + + let mut conn = match Connection::open(database_path) { + Ok(value) => value, + Err(error) => { + error!("Error opening database (oott.db): {error}"); + return Err(format!("Error opening database (oott.db): {error}")); + } + }; + + debug!("Database open, executing migrations if needed."); + // Update the database schema, atomically + match MIGRATIONS.to_latest(&mut conn) { + Ok(_) => { + debug!("Database up to date."); + Ok(conn) + } + Err(error) => { + error!("Error updating database: {error}"); + Err(format!("Error updating database: {error}")) + } } } } diff --git a/src/settings.rs b/src/settings.rs index c3ca382..17983aa 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -8,6 +8,11 @@ use serde::Deserialize; // ----------------------------------------------------------- // Configuration structure +#[derive(Debug, Deserialize, Clone)] +pub struct Database { + pub path: String, +} + #[derive(Debug, Deserialize, Clone)] pub struct Networking { pub interface: String, @@ -40,6 +45,7 @@ pub struct Notifications { #[derive(Debug, Deserialize, Clone)] pub struct Settings { + pub database: Database, pub networking: Networking, pub log: Log, pub timings: Timings,