about summary refs log tree commit diff stats
path: root/pkgs/by-name/mp/mpdpopm/src/config.rs
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2026-01-25 20:45:30 +0100
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2026-01-25 20:45:30 +0100
commit91a96ca930f46d7374f91fd00db00d25e3258a91 (patch)
tree39cc8bf51f4c5e4a35864e7ba57a26a91c4a912e /pkgs/by-name/mp/mpdpopm/src/config.rs
parentpkgs/mpdpopm: Switch error handling from snafu to anyhow (diff)
downloadnixos-config-91a96ca930f46d7374f91fd00db00d25e3258a91.zip
pkgs/mpdpopm: Parse MPD_HOST to determine connection
This is way more useful, than hard-coding `localhost:6600`.
Diffstat (limited to '')
-rw-r--r--pkgs/by-name/mp/mpdpopm/src/config.rs35
1 files changed, 31 insertions, 4 deletions
diff --git a/pkgs/by-name/mp/mpdpopm/src/config.rs b/pkgs/by-name/mp/mpdpopm/src/config.rs
index e6c01599..2d9c466b 100644
--- a/pkgs/by-name/mp/mpdpopm/src/config.rs
+++ b/pkgs/by-name/mp/mpdpopm/src/config.rs
@@ -54,6 +54,27 @@ pub enum Connection {
     TCP { host: String, port: u16 },
 }
 
+impl Connection {
+    pub fn new() -> Result<Self> {
+        let env = env::var("MPD_HOST")?;
+
+        if env.starts_with("/") {
+            // We assume that this is a path to a local socket
+            Ok(Self::Local {
+                path: PathBuf::from(env),
+            })
+        } else {
+            todo!("Not yet able to auto-parse, MPD_HOST for remote connection")
+        }
+    }
+}
+
+impl Default for Connection {
+    fn default() -> Self {
+        Self::new().expect("Could not generate default connection")
+    }
+}
+
 #[cfg(test)]
 mod test_connection {
     use super::Connection;
@@ -118,16 +139,22 @@ pub struct Config {
 }
 
 impl Default for Config {
-    fn default() -> Config {
-        Config {
+    fn default() -> Self {
+        Self::new().unwrap()
+    }
+}
+
+impl Config {
+    fn new() -> Result<Self> {
+        Ok(Self {
             _version: String::from("1"),
             log: [LOCALSTATEDIR, "log", "mppopmd.log"].iter().collect(),
-            conn: Connection::default(),
+            conn: Connection::new()?,
             local_music_dir: [PREFIX, "Music"].iter().collect(),
             played_thresh: 0.6,
             poll_interval_ms: 5000,
             commands_chan: String::from("unwoundstack.com:commands"),
-        }
+        })
     }
 }