Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allows control of config_root for global config #3670

Merged
merged 3 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading