about summary refs log tree commit diff
path: root/nixpkgs/pkgs/tools/audio/yabridgectl/chainloader-from-nix-profiles.patch
blob: 066b854cac9e58e086c733efbf4d25fece5669bd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
diff --git a/tools/yabridgectl/src/config.rs b/tools/yabridgectl/src/config.rs
index 53200bd5..ef8a781d 100644
--- a/tools/yabridgectl/src/config.rs
+++ b/tools/yabridgectl/src/config.rs
@@ -22,6 +22,7 @@ use serde_derive::{Deserialize, Serialize};
 use std::collections::{BTreeMap, BTreeSet, HashSet};
 use std::env;
 use std::fs;
+use std::iter;
 use std::path::{Path, PathBuf};
 use which::which;
 use xdg::BaseDirectories;
@@ -225,34 +226,27 @@ impl Config {
                 }
             }
             None => {
-                // Search in the system library locations and in `~/.local/share/yabridge` if no
-                // path was set explicitely. We'll also search through `/usr/local/lib` just in case
-                // but since we advocate against installing yabridge there we won't list this path
-                // in the error message when `libyabridge-chainloader-vst2.so` can't be found.
-                let system_path = Path::new("/usr/lib");
+                // Search through NIX_PROFILES & data home directory if no path was set explicitly.
+                // NIX_PROFILES is iterated in reverse from the most specific (the user profile) to
+                // the least specific (the system profile).
+                let nix_profiles = env::var("NIX_PROFILES");
                 let user_path = xdg_dirs.get_data_home();
-                let lib_directories = [
-                    system_path,
-                    // Used on Debian based distros
-                    Path::new("/usr/lib/x86_64-linux-gnu"),
-                    // Used on Fedora
-                    Path::new("/usr/lib64"),
-                    Path::new("/usr/local/lib"),
-                    Path::new("/usr/local/lib/x86_64-linux-gnu"),
-                    Path::new("/usr/local/lib64"),
-                    &user_path,
-                ];
+                let lib_directories = nix_profiles.iter()
+                    .flat_map(|profiles| profiles.split(' ')
+                              .rev()
+                              .map(|profile| Path::new(profile).join("lib")))
+                    .chain(iter::once(user_path.clone()));
+
                 let mut candidates = lib_directories
-                    .iter()
                     .map(|directory| directory.join(VST2_CHAINLOADER_NAME));
+
                 match candidates.find(|directory| directory.exists()) {
                     Some(candidate) => candidate,
                     _ => {
                         return Err(anyhow!(
-                            "Could not find '{}' in either '{}' or '{}'. You can override the \
+                            "Could not find '{}' through 'NIX_PROFILES' or '{}'. You can override the \
                              default search path using 'yabridgectl set --path=<path>'.",
                             VST2_CHAINLOADER_NAME,
-                            system_path.display(),
                             user_path.display()
                         ));
                     }
diff --git a/tools/yabridgectl/src/main.rs b/tools/yabridgectl/src/main.rs
index 8dcd7dc8..bddca534 100644
--- a/tools/yabridgectl/src/main.rs
+++ b/tools/yabridgectl/src/main.rs
@@ -135,7 +135,7 @@ fn main() -> Result<()> {
                         .long_help(
                             "Path to the directory containing \
                              'libyabridge-chainloader-{clap,vst2,vst3}.so'. If this is not set, \
-                             then yabridgectl will look in both '/usr/lib' and \
+                             then yabridgectl will look through 'NIX_PROFILES' and \
                              '~/.local/share/yabridge' by default.",
                         )
                         .validator(validate_path)