Skip to content

Commit

Permalink
feat: Allows control of config_root for global config (#3670)
Browse files Browse the repository at this point in the history
* Makes two config related chages.

- Adds MISE_GLOBAL_CONFIG_ROOT to control config_root for global config file
- Allows MISE_IGNORED_CONFIG_PATHS to specify explicit paths

* Updates docs

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
bnorick and autofix-ci[bot] authored Dec 18, 2024
1 parent a4ab84f commit 123d4e8
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 2 deletions.
6 changes: 6 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,12 @@ Default: `$MISE_CONFIG_DIR/config.toml` (Usually ~/.config/mise/config.toml)

This is the path to the config file.

### `MISE_GLOBAL_CONFIG_ROOT`

Default: `$HOME`

This is the path which is used as `{{config_root}}` for the global config file.

### `MISE_ENV_FILE`

Set to a filename to read from env from a dotenv file. e.g.: `MISE_ENV_FILE=.env`.
Expand Down
4 changes: 4 additions & 0 deletions schema/mise.json
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,10 @@
"description": "Path to the global mise config file. Default is `~/.config/mise/config.toml`. This must be an env var.",
"type": "string"
},
"global_config_root": {
"description": "Path which is used as `{{config_root}}` for the global config file. Default is `$HOME`. This must be an env var.",
"type": "string"
},
"go_default_packages_file": {
"default": "~/.default-go-packages",
"description": "Path to a file containing default go packages to install when installing go",
Expand Down
6 changes: 6 additions & 0 deletions settings.toml
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,12 @@ type = "Path"
optional = true
description = "Path to the global mise config file. Default is `~/.config/mise/config.toml`. This must be an env var."

[global_config_root]
env = "MISE_GLOBAL_CONFIG_ROOT"
type = "Path"
optional = true
description = "Path which is used as `{{config_root}}` for the global config file. Default is `$HOME`. This must be an env var."

[go_default_packages_file]
env = "MISE_GO_DEFAULT_PACKAGES_FILE"
type = "Path"
Expand Down
2 changes: 1 addition & 1 deletion src/config/config_file/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ pub fn parse(path: &Path) -> Result<Box<dyn ConfigFile>> {

pub fn config_root(path: &Path) -> PathBuf {
if is_global_config(path) {
return env::HOME.to_path_buf();
return env::MISE_GLOBAL_CONFIG_ROOT.to_path_buf();
}
let path = path
.absolutize()
Expand Down
5 changes: 4 additions & 1 deletion src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,10 @@ pub fn load_config_paths(config_filenames: &[String], include_ignored: bool) ->
config_files
.into_iter()
.unique_by(|p| file::desymlink_path(p))
.filter(|p| include_ignored || !config_file::is_ignored(&config_trust_root(p)))
.filter(|p| {
include_ignored
|| !(config_file::is_ignored(&config_trust_root(p)) || config_file::is_ignored(p))
})
.collect()
}

Expand Down
2 changes: 2 additions & 0 deletions src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ pub static MISE_GLOBAL_CONFIG_FILE: Lazy<PathBuf> = Lazy::new(|| {
.or_else(|| var_path("MISE_CONFIG_FILE"))
.unwrap_or_else(|| MISE_CONFIG_DIR.join("config.toml"))
});
pub static MISE_GLOBAL_CONFIG_ROOT: Lazy<PathBuf> =
Lazy::new(|| var_path("MISE_GLOBAL_CONFIG_ROOT").unwrap_or_else(|| HOME.to_path_buf()));
pub static MISE_SYSTEM_CONFIG_FILE: Lazy<PathBuf> = Lazy::new(|| {
var_path("MISE_SYSTEM_CONFIG_FILE").unwrap_or_else(|| MISE_SYSTEM_DIR.join("config.toml"))
});
Expand Down

0 comments on commit 123d4e8

Please sign in to comment.