diff --git a/e2e/backend/test_cargo_binstall b/e2e/backend/test_cargo_binstall index ab1ab9de6f..c37ebd1a4b 100644 --- a/e2e/backend/test_cargo_binstall +++ b/e2e/backend/test_cargo_binstall @@ -16,3 +16,9 @@ EOF mise i mise uninstall cargo:cargo-show cargo-binstall + +###### TEST CUSTOM REGISTRY ###### +export CARGO_REGISTRIES_OFFICIAL_GIT_INDEX=https://github.com/rust-lang/crates.io-index +export MISE_CARGO_REGISTRY_NAME=official_git +mise i +mise uninstall cargo:cargo-show cargo-binstall diff --git a/schema/mise.json b/schema/mise.json index 9e7a714b79..9806401a65 100644 --- a/schema/mise.json +++ b/schema/mise.json @@ -309,6 +309,10 @@ "default": true, "description": "Use cargo-binstall instead of cargo install if available", "type": "boolean" + }, + "registry_name": { + "description": "Name of the cargo registry to use.", + "type": "string" } } }, diff --git a/settings.toml b/settings.toml index cfff3e1a69..99526c7e9e 100644 --- a/settings.toml +++ b/settings.toml @@ -174,6 +174,19 @@ mise use -g cargo-binstall ``` """ +[cargo.registry_name] +env = "MISE_CARGO_REGISTRY_NAME" +type = "String" +optional = true +description = "Name of the cargo registry to use." +docs = """ +Packages are installed from the official cargo registry. + +You can set this to a different registry name if you have a custom feed or want to use a different source. + +Please follow the [cargo alternative registries documentation](https://doc.rust-lang.org/cargo/reference/registries.html#using-an-alternate-registry) to configure your registry. +""" + [cargo_binstall] type = "Bool" hide = true diff --git a/src/backend/cargo.rs b/src/backend/cargo.rs index 13ef359b05..dd9cd2162f 100644 --- a/src/backend/cargo.rs +++ b/src/backend/cargo.rs @@ -58,6 +58,7 @@ impl Backend for CargoBackend { fn install_version_(&self, ctx: &InstallContext, tv: ToolVersion) -> eyre::Result { let config = Config::try_get()?; let install_arg = format!("{}@{}", self.tool_name(), tv.version); + let registry_name = &SETTINGS.cargo.registry_name; let cmd = CmdLineRunner::new("cargo").arg("install"); let mut cmd = if let Some(url) = self.git_url() { @@ -109,6 +110,9 @@ impl Backend for CargoBackend { if let Some(c) = opts.get("crate") { cmd = cmd.arg(c); } + if let Some(registry_name) = registry_name { + cmd = cmd.arg(format!("--registry={registry_name}")); + } cmd.arg("--root") .arg(tv.install_path())