aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/cli.rs6
-rw-r--r--src/main.rs11
-rw-r--r--wiki/Configuration:-Overview.md5
3 files changed, 21 insertions, 1 deletions
diff --git a/src/cli.rs b/src/cli.rs
index 52489ad0..4004a331 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -13,6 +13,9 @@ use crate::utils::version;
#[command(subcommand_help_heading = "Subcommands")]
pub struct Cli {
/// Path to config file (default: `$XDG_CONFIG_HOME/niri/config.kdl`).
+ ///
+ /// This can also be set with the `NIRI_CONFIG` environment variable. If both are set, the
+ /// command line argument takes precedence.
#[arg(short, long)]
pub config: Option<PathBuf>,
/// Import environment globally to systemd and D-Bus, run D-Bus services.
@@ -43,6 +46,9 @@ pub enum Sub {
/// Validate the config file.
Validate {
/// Path to config file (default: `$XDG_CONFIG_HOME/niri/config.kdl`).
+ ///
+ /// This can also be set with the `NIRI_CONFIG` environment variable. If both are set, the
+ /// command line argument takes precedence.
#[arg(short, long)]
config: Option<PathBuf>,
},
diff --git a/src/main.rs b/src/main.rs
index fb399f3a..ad201b2d 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -91,6 +91,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
tracy_client::Client::start();
let path = config
+ .or_else(env_config_path)
.or_else(default_config_path)
.expect("error getting config path");
Config::load(&path)?;
@@ -113,7 +114,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// Load the config.
let mut config_created = false;
- let path = cli.config.or_else(|| {
+ let path = cli.config.or_else(env_config_path);
+ env::remove_var("NIRI_CONFIG");
+ let path = path.or_else(|| {
let default_path = default_config_path()?;
let default_parent = default_path.parent().unwrap();
@@ -315,6 +318,12 @@ fn import_environment() {
}
}
+fn env_config_path() -> Option<PathBuf> {
+ env::var_os("NIRI_CONFIG")
+ .filter(|x| !x.is_empty())
+ .map(PathBuf::from)
+}
+
fn default_config_path() -> Option<PathBuf> {
let Some(dirs) = ProjectDirs::from("", "", "niri") else {
warn!("error retrieving home directory");
diff --git a/wiki/Configuration:-Overview.md b/wiki/Configuration:-Overview.md
index f11c2a67..ce5ef9bd 100644
--- a/wiki/Configuration:-Overview.md
+++ b/wiki/Configuration:-Overview.md
@@ -25,6 +25,11 @@ You can run `niri validate` to parse the config and see any errors.
To use a different config file path, pass it in the `--config` or `-c` argument to `niri`.
+You can also set `$NIRI_CONFIG` to the path of the config file.
+`--config` always takes precedence.
+If `--config` or `$NIRI_CONFIG` doesn't point to a real file, the config will not be loaded.
+If `$NIRI_CONFIG` is set to an empty string, it is ignored and the default config location is used instead.
+
### Syntax
The config is written in [KDL].